test: Some cleanup for Git Cypress tests (#32836)

1. Change usage of ports bound to 3000, 5000 and 8000 to 4200, which
will be the canonical port for TED in the future.
2. Switch to using TED's native git repo management APIs, instead of the
Gitea compatibility layer.
3. Remove code from GitHub ages.


/ok-to-test tags="@tag.Sanity, @tag.Git"<!-- This is an auto-generated
comment: Cypress test results -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/8785291879>
> Commit: b38f4eb388716f7fcfc2a032d788c2ebb951568b
> Cypress dashboard url: <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=8785291879&attempt=2"
target="_blank">Click here!</a>

<!-- end of auto-generated comment: Cypress test results  -->





<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Refactor**
- Enhanced Git integration by shifting from GitHub to Gitea for
repository operations in test environments.
- Updated URLs and endpoints across various test scripts and data
fixtures to align with new configurations.
- **Tests**
- Modified test scenarios to reflect changes in Git operations and URL
configurations.
- **Chores**
- Updated CI workflows by replacing old secrets with new ones for better
configuration management.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Shrikant Sharat Kandula 2024-04-23 10:01:14 +05:30 committed by GitHub
parent 60d45ea6ff
commit cd22fc1087
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 39 additions and 421 deletions

View File

@ -299,15 +299,12 @@ jobs:
CYPRESS_TESTPASSWORD4: ${{ secrets.CYPRESS_TESTPASSWORD4 }}
CYPRESS_S3_ACCESS_KEY: ${{ secrets.CYPRESS_S3_ACCESS_KEY }}
CYPRESS_S3_SECRET_KEY: ${{ secrets.CYPRESS_S3_SECRET_KEY }}
CYPRESS_GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
CYPRESS_AIRTABLE_BEARER: ${{ secrets.AIRTABLE_BEARER }}
CYPRESS_ORACLE_HOST: ${{ secrets.ORACLE_HOST }}
CYPRESS_ORACLE_SERVICE: ${{ secrets.ORACLE_SERVICE }}
CYPRESS_ORACLE_USERNAME: ${{ secrets.ORACLE_USERNAME }}
CYPRESS_ORACLE_PASSWORD: ${{ secrets.ORACLE_PASSWORD }}
CYPRESS_FIRESTORE_PRIVATE_KEY: ${{ secrets.FIRESTORE_PRIVATE_KEY }}
CYPRESS_GITHUB_PERSONAL_ACCESS_TOKEN: ${{ secrets.CYPRESS_GITHUB_PERSONAL_ACCESS_TOKEN }}
CYPRESS_TEST_GITHUB_USER_NAME: ${{ secrets.CYPRESS_TEST_GITHUB_USER_NAME }}
CYPRESS_APPSMITH_OAUTH2_GOOGLE_CLIENT_ID: ${{ secrets.CYPRESS_APPSMITH_OAUTH2_GOOGLE_CLIENT_ID }}
CYPRESS_APPSMITH_OAUTH2_GOOGLE_CLIENT_SECRET: ${{ secrets.CYPRESS_APPSMITH_OAUTH2_GOOGLE_CLIENT_SECRET }}
CYPRESS_APPSMITH_OAUTH2_GITHUB_CLIENT_ID: ${{ secrets.CYPRESS_APPSMITH_OAUTH2_GITHUB_CLIENT_ID }}

View File

@ -195,15 +195,12 @@ jobs:
CYPRESS_TESTPASSWORD4: ${{ secrets.CYPRESS_TESTPASSWORD4 }}
CYPRESS_S3_ACCESS_KEY: ${{ secrets.CYPRESS_S3_ACCESS_KEY }}
CYPRESS_S3_SECRET_KEY: ${{ secrets.CYPRESS_S3_SECRET_KEY }}
CYPRESS_GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
CYPRESS_AIRTABLE_BEARER: ${{ secrets.AIRTABLE_BEARER }}
CYPRESS_ORACLE_HOST: ${{ secrets.ORACLE_HOST }}
CYPRESS_ORACLE_SERVICE: ${{ secrets.ORACLE_SERVICE }}
CYPRESS_ORACLE_USERNAME: ${{ secrets.ORACLE_USERNAME }}
CYPRESS_ORACLE_PASSWORD: ${{ secrets.ORACLE_PASSWORD }}
CYPRESS_FIRESTORE_PRIVATE_KEY: ${{ secrets.FIRESTORE_PRIVATE_KEY }}
CYPRESS_GITHUB_PERSONAL_ACCESS_TOKEN: ${{ secrets.CYPRESS_GITHUB_PERSONAL_ACCESS_TOKEN }}
CYPRESS_TEST_GITHUB_USER_NAME: ${{ secrets.CYPRESS_TEST_GITHUB_USER_NAME }}
CYPRESS_APPSMITH_OAUTH2_GOOGLE_CLIENT_ID: ${{ secrets.CYPRESS_APPSMITH_OAUTH2_GOOGLE_CLIENT_ID }}
CYPRESS_APPSMITH_OAUTH2_GOOGLE_CLIENT_SECRET: ${{ secrets.CYPRESS_APPSMITH_OAUTH2_GOOGLE_CLIENT_SECRET }}
CYPRESS_APPSMITH_OAUTH2_GITHUB_CLIENT_ID: ${{ secrets.CYPRESS_APPSMITH_OAUTH2_GITHUB_CLIENT_ID }}

View File

@ -303,15 +303,12 @@ jobs:
CYPRESS_TESTPASSWORD4: ${{ secrets.CYPRESS_TESTPASSWORD4 }}
CYPRESS_S3_ACCESS_KEY: ${{ secrets.CYPRESS_S3_ACCESS_KEY }}
CYPRESS_S3_SECRET_KEY: ${{ secrets.CYPRESS_S3_SECRET_KEY }}
CYPRESS_GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
CYPRESS_AIRTABLE_BEARER: ${{ secrets.AIRTABLE_BEARER }}
CYPRESS_ORACLE_HOST: ${{ secrets.ORACLE_HOST }}
CYPRESS_ORACLE_SERVICE: ${{ secrets.ORACLE_SERVICE }}
CYPRESS_ORACLE_USERNAME: ${{ secrets.ORACLE_USERNAME }}
CYPRESS_ORACLE_PASSWORD: ${{ secrets.ORACLE_PASSWORD }}
CYPRESS_FIRESTORE_PRIVATE_KEY: ${{ secrets.FIRESTORE_PRIVATE_KEY }}
CYPRESS_GITHUB_PERSONAL_ACCESS_TOKEN: ${{ secrets.CYPRESS_GITHUB_PERSONAL_ACCESS_TOKEN }}
CYPRESS_TEST_GITHUB_USER_NAME: ${{ secrets.CYPRESS_TEST_GITHUB_USER_NAME }}
CYPRESS_APPSMITH_OAUTH2_GOOGLE_CLIENT_ID: ${{ secrets.CYPRESS_APPSMITH_OAUTH2_GOOGLE_CLIENT_ID }}
CYPRESS_APPSMITH_OAUTH2_GOOGLE_CLIENT_SECRET: ${{ secrets.CYPRESS_APPSMITH_OAUTH2_GOOGLE_CLIENT_SECRET }}
CYPRESS_APPSMITH_OAUTH2_GITHUB_CLIENT_ID: ${{ secrets.CYPRESS_APPSMITH_OAUTH2_GITHUB_CLIENT_ID }}

View File

@ -17,14 +17,12 @@ describe("Git import empty repository", { tags: ["@tag.Git"] }, function () {
cy.generateUUID().then((uid) => {
repoName = uid;
_.gitSync.CreateTestGiteaRepo(repoName);
//cy.createTestGithubRepo(repoName);
});
});
it("1. Bug #12749 Git Import - Empty Repo NullPointerException", () => {
cy.generateUUID().then((uid) => {
repoName = uid;
//cy.createTestGithubRepo(repoName);
_.gitSync.CreateTestGiteaRepo(repoName);
_.gitSync.ImportAppFromGit(undefined, repoName, false);
cy.wait("@importFromGit").then((interception) => {
@ -38,6 +36,5 @@ describe("Git import empty repository", { tags: ["@tag.Git"] }, function () {
});
after(() => {
_.gitSync.DeleteTestGithubRepo(repoName);
//cy.deleteTestGithubRepo(repoName);
});
});

View File

@ -55,6 +55,5 @@ describe("Git sync modal: deploy tab", { tags: ["@tag.Git"] }, function () {
after(() => {
_.gitSync.DeleteTestGithubRepo(repoName);
//cy.deleteTestGithubRepo(repoName);
});
});

View File

@ -111,6 +111,5 @@ describe("Git disconnect modal:", { tags: ["@tag.Git"] }, function () {
after(() => {
_.gitSync.DeleteTestGithubRepo(repoName);
//cy.deleteTestGithubRepo(repoName);
});
});

View File

@ -265,7 +265,7 @@ describe("Git sync Bug #10773", { tags: ["@tag.Git"] }, function () {
agHelper.GetNClick(gitSync.gitConnectNextBtn);
agHelper.TypeText(
gitSync.remoteUrlInput,
`${dataManager.GITEA_API_URL_TED}/${repoName}.git`,
`${dataManager.GIT_CLONE_URL}/${repoName}.git`,
);
agHelper.GetNClick(gitSync.gitConnectNextBtn);

View File

@ -121,28 +121,5 @@ describe(
expect(location.pathname).includes(legacyPathname);
});
});
// // _.gitSync.DeleteTestGithubRepo(repoName);
// // //cy.deleteTestGithubRepo(repoName);
// // // TODO remove when app deletion with conflicts is fixed
// // cy.get(homePage.homeIcon).click({ force: true });
// // cy.get(homePage.createNew)
// // .first()
// // .click({ force: true });
// // cy.wait("@createNewApplication").should(
// // "have.nested.property",
// // "response.body.responseMeta.status",
// // 201,
// // );
// // cy.get("#loading").should("not.exist");
// // cy.wait(2000);
// // cy.AppSetupForRename();
// // cy.get(homePage.applicationName).type(repoName + "{enter}");
// // cy.wait("@updateApplication").should(
// // "have.nested.property",
// // "response.body.responseMeta.status",
// // 200,
// // );
// });
},
);

View File

@ -187,7 +187,8 @@ describe("Git sync:", { tags: ["@tag.Git"] }, function () {
// cy.get("@gitbranchName").then((branName) => {
// tempBranch = branName;
// });
cy.renameBranchViaGithubApi(repoName, tempBranch, tempBranchRenamed);
// rename branch API missing in TED.
// cy.renameBranchViaGithubApi(repoName, tempBranch, tempBranchRenamed);
cy.get(gitSyncLocators.branchButton).click();
cy.get(gitSyncLocators.branchSearchInput).type(`{selectall}${tempBranch}`);
const tempBranchRegex = new RegExp(`^${tempBranch}$`);

View File

@ -22,17 +22,12 @@ describe("Git with Theming:", { tags: ["@tag.Git"] }, function () {
);
});
});
// cy.generateUUID().then((uid) => {
// repoName = uid;
_.gitSync.CreateNConnectToGit();
cy.get("@gitRepoName").then((repName) => {
repoName = repName;
_.gitSync.CreateGitBranch(repoName);
});
// cy.createTestGithubRepo(repoName);
// cy.connectToGitRepo(repoName);
//});
});
it("1. Bug #13860 Theming is not getting applied on view mode when the app is connected to Git", function () {
_.appSettings.OpenAppSettings();

View File

@ -74,7 +74,7 @@ describe(
cy.openPropertyPane("imagewidget");
// Invalid image url
const invalidImageUrl =
"http://host.docker.internal:5000/photo-not-exists.jpeg";
"http://host.docker.internal:4200/photo-not-exists.jpeg";
cy.testCodeMirror(invalidImageUrl);
// Show off error message

File diff suppressed because one or more lines are too long

View File

@ -85,7 +85,7 @@
"readonly": "readonly",
"authenticatedApiUrl": "https://fakeapi.com",
"GraphqlApiUrl_TED": "http://host.docker.internal:5000/graphql",
"GraphqlApiUrl_TED": "http://host.docker.internal:4200/graphql",
"GITEA_API_BASE_TED": "localhost",
"GITEA_API_PORT_TED": "3001",
"GITEA_API_URL_TED": "git@host.docker.internal:Cypress"

View File

@ -62,7 +62,7 @@
]
},
{
"image": "http://host.docker.internal:8000/photo-1492529029602-33e53698f407.jpeg",
"image": "http://host.docker.internal:4200/photo-1492529029602-33e53698f407.jpeg",
"widgetName": "Image1",
"rightColumn": 64,
"widgetId": "ah4cbb9o2e",
@ -502,4 +502,4 @@
}
]
}
}
}

View File

@ -62,7 +62,7 @@
]
},
{
"image": "http://host.docker.internal:8000/photo-1503469432756-4aae2e18d881.jpeg",
"image": "http://host.docker.internal:4200/photo-1503469432756-4aae2e18d881.jpeg",
"widgetName": "Image1",
"rightColumn": 64,
"widgetId": "ah4cbb9o2e",
@ -545,4 +545,4 @@
}
]
}
}
}

View File

@ -1,9 +1,9 @@
export class DataManager {
environments = ["Production", "Staging"];
defaultEnviorment = this.environments[0];
GITEA_API_BASE_TED = "localhost";
GITEA_API_PORT_TED = "3001";
GITEA_API_URL_TED = "git@host.docker.internal:Cypress";
GIT_API_BASE = "localhost:4200";
GIT_CLONE_URL = "git@host.docker.internal:Cypress";
dsValues: Record<string, any> = {
Production: {
@ -84,9 +84,9 @@ export class DataManager {
"http://host.docker.internal:5001/v1/whatdoestrumpthink/random",
mockHttpCodeUrl: "http://host.docker.internal:5001/v1/mock-http-codes/",
flowerImageUrl1:
"http://host.docker.internal:5000/photo-1503469432756-4aae2e18d881.jpeg",
"http://host.docker.internal:4200/photo-1503469432756-4aae2e18d881.jpeg",
flowerImageUrl2:
"http://host.docker.internal:5000/photo-1492529029602-33e53698f407.jpeg",
"http://host.docker.internal:4200/photo-1492529029602-33e53698f407.jpeg",
AirtableBaseForME: "appubHrVbovcudwN6",
AirtableTableForME: "tblsFCQSskVFf7xNd",
ApiUrlME: "http://host.docker.internal:5001/v1/production",
@ -105,7 +105,7 @@ export class DataManager {
readonly: "readonly",
authenticatedApiUrl: "https://fakeapi.com",
GraphqlApiUrl_TED: "http://host.docker.internal:5000/graphql",
GraphqlApiUrl_TED: "http://host.docker.internal:4200/graphql",
twilio_username: "random-username",
twilio_password: "random-password",
@ -198,7 +198,7 @@ export class DataManager {
readonly: "readonly",
authenticatedApiUrl: "https://fakeapi.com",
GraphqlApiUrl_TED: "http://host.docker.internal:5000/graphql",
GraphqlApiUrl_TED: "http://host.docker.internal:4200/graphql",
twilio_username: "random-username",
twilio_password: "random-password",

View File

@ -96,10 +96,7 @@ export class GitSync {
public CreateTestGiteaRepo(repo: string, privateFlag = false) {
cy.request({
method: "POST",
url: `${this.dataManager.GITEA_API_BASE_TED}:${this.dataManager.GITEA_API_PORT_TED}/api/v1/org/Cypress/repos`,
headers: {
Authorization: `token ${Cypress.env("GITEA_TOKEN")}`,
},
url: `${this.dataManager.GIT_API_BASE}/api/v1/git/repos`,
body: {
name: repo,
private: privateFlag,
@ -152,7 +149,7 @@ export class GitSync {
);
this.agHelper.TypeText(
this.remoteUrlInput,
`${this.dataManager.GITEA_API_URL_TED}/${repoName}.git`,
`${this.dataManager.GIT_CLONE_URL}/${repoName}.git`,
);
this.agHelper.GetNClick(this.gitConnectNextBtn);
@ -164,10 +161,7 @@ export class GitSync {
// fetch the generated key and post to the github repo
cy.request({
method: "POST",
url: `${this.dataManager.GITEA_API_BASE_TED}:${this.dataManager.GITEA_API_PORT_TED}/api/v1/repos/Cypress/${repoName}/keys`,
headers: {
Authorization: `token ${Cypress.env("GITEA_TOKEN")}`,
},
url: `${this.dataManager.GIT_API_BASE}/api/v1/git/keys/${repoName}`,
body: {
title: "key_" + uid,
key: generatedKey,
@ -226,7 +220,7 @@ export class GitSync {
);
this.agHelper.TypeText(
this.remoteUrlInput,
`${this.dataManager.GITEA_API_URL_TED}/${repoName}.git`,
`${this.dataManager.GIT_CLONE_URL}/${repoName}.git`,
);
this.agHelper.GetNClick(this.gitConnectNextBtn);
@ -238,10 +232,7 @@ export class GitSync {
// fetch the generated key and post to the github repo
cy.request({
method: "POST",
url: `${this.dataManager.GITEA_API_BASE_TED}:${this.dataManager.GITEA_API_PORT_TED}/api/v1/repos/Cypress/${repoName}/keys`,
headers: {
Authorization: `token ${Cypress.env("GITEA_TOKEN")}`,
},
url: `${this.dataManager.GIT_API_BASE}/api/v1/git/keys/${repoName}`,
body: {
title: "key_" + uid,
key: generatedKey,
@ -281,30 +272,21 @@ export class GitSync {
DeleteTestGithubRepo(repo: any) {
cy.request({
method: "DELETE",
url: `${this.dataManager.GITEA_API_BASE_TED}:${this.dataManager.GITEA_API_PORT_TED}/api/v1/repos/Cypress/${repo}`,
headers: {
Authorization: `token ${Cypress.env("GITEA_TOKEN")}`,
},
url: `${this.dataManager.GIT_API_BASE}/api/v1/git/repos/${repo}`,
});
}
DeleteDeployKey(repo: any, id: number) {
cy.request({
method: "DELETE",
url: `${this.dataManager.GITEA_API_BASE_TED}:${this.dataManager.GITEA_API_PORT_TED}/api/v1/repos/Cypress/${repo}/keys/${id}`,
headers: {
Authorization: `token ${Cypress.env("GITEA_TOKEN")}`,
},
url: `${this.dataManager.GIT_API_BASE}/api/v1/git/keys/${id}`,
});
}
public CreateRemoteBranch(repo: string, branchName: string) {
cy.request({
method: "POST",
url: `${this.dataManager.GITEA_API_BASE_TED}:${this.dataManager.GITEA_API_PORT_TED}/api/v1/repos/Cypress/${repo}/branches`,
headers: {
Authorization: `token ${Cypress.env("GITEA_TOKEN")}`,
},
url: `${this.dataManager.GIT_API_BASE}/api/v1/git/repos/${repo}/branches`,
body: {
new_branch_name: branchName,
},
@ -469,99 +451,4 @@ export class GitSync {
}
this.CloseGitSyncModal();
}
//#region Unused methods
private AuthorizeLocalGitSSH(remoteUrl: string, assertConnect = true) {
let generatedKey;
this.OpenGitSyncModal();
this.agHelper.AssertAttribute(
this._gitRepoInput,
"placeholder",
"git@example.com:user/repository.git",
);
this.agHelper.TypeText(this._gitRepoInput, remoteUrl);
this.agHelper.ClickButton("Generate key");
cy.wait(`@generateKey`).then((result: any) => {
generatedKey = result.response.body.data.publicKey;
generatedKey = generatedKey.slice(0, generatedKey.length - 1);
let formdata = new FormData();
cy.log("generatedKey is " + generatedKey);
formdata.set("sshkey", generatedKey);
// fetch the generated key and post to the github repo
cy.request({
method: "POST",
url: `http://${this.dataManager.GITEA_API_BASE_TED}:${this.dataManager.GITEA_API_PORT_TED}/v1/gitserver/addgitssh`,
//body: formdata,
body: {
sshkey: generatedKey,
},
form: true,
// headers: {
// "Content-Type": "application/x-www-form-urlencoded"
// },
}).then((response) => {
expect(response.status).to.equal(200);
});
this.agHelper.GetNClick(this._useDefaultConfig); //Uncheck the Use default configuration
this.agHelper.TypeText(
this._gitConfigNameInput,
"testusername",
//`{selectall}${testUsername}`,
);
this.agHelper.TypeText(this._gitConfigEmailInput, "test@test.com");
this.agHelper.ClickButton("CONNECT");
if (assertConnect) {
//this.ReplaceForGit("cypress/fixtures/Bugs/GitConnectResponse.json", remoteUrl);
//cy.get('@connectGitLocalRepo').its('response.statusCode').should('equal', 200);
// cy.intercept("POST", "/api/v1/git/connect/app/*", {
// fixture: "/Bugs/GitConnectResponse.json",
// });
this.assertHelper.AssertNetworkStatus("@connectGitLocalRepo");
}
this.CloseGitSyncModal();
});
}
private ReplaceForGit(fixtureFile: any, remoteUrl: string) {
let currentAppId, currentURL;
cy.readFile(
fixtureFile,
// (err: string) => {
// if (err) {
// return console.error(err);
// }}
).then((data) => {
cy.url().then((url) => {
currentURL = url;
const myRegexp = /page-1(.*)/;
const match = myRegexp.exec(currentURL);
cy.log(currentURL + "currentURL from intercept is");
currentAppId = match ? match[1].split("/")[1] : null;
data.data.id = currentAppId;
data.data.gitApplicationMetadata.defaultApplicationId = currentAppId;
data.data.gitApplicationMetadata.remoteUrl = remoteUrl;
cy.writeFile(fixtureFile, JSON.stringify(data));
});
});
}
private CreateLocalGithubRepo(repo: string) {
let remoteUrl = "";
cy.request({
method: "GET",
url:
`http://${this.dataManager.GITEA_API_BASE_TED}:${this.dataManager.GITEA_API_PORT_TED}/v1/gitserver/addrepo?reponame=` +
repo,
}).then((response) => {
remoteUrl = JSON.stringify(response.body).replace(/['"]+/g, "");
expect(response.status).to.equal(200);
//cy.log("remoteUrl is"+ remoteUrl);
cy.wrap(remoteUrl).as("remoteUrl");
});
}
//#endregion
}

View File

@ -7,16 +7,14 @@ require("cy-verify-downloads").addCustomCommand();
require("cypress-file-upload");
import gitSyncLocators from "../locators/gitSyncLocators";
import homePage from "../locators/HomePage";
import { ObjectsRegistry } from "../support/Objects/Registry";
import { ObjectsRegistry } from "./Objects/Registry";
let gitSync = ObjectsRegistry.GitSync,
agHelper = ObjectsRegistry.AggregateHelper,
dataManager = ObjectsRegistry.DataManager,
assertHelper = ObjectsRegistry.AssertHelper,
homePageTS = ObjectsRegistry.HomePage;
const gitSync = ObjectsRegistry.GitSync;
const agHelper = ObjectsRegistry.AggregateHelper;
const dataManager = ObjectsRegistry.DataManager;
const assertHelper = ObjectsRegistry.AssertHelper;
const commonLocators = require("../locators/commonlocators.json");
const GITHUB_API_BASE = "https://api.github.com";
Cypress.Commands.add("revokeAccessGit", (appName) => {
cy.xpath("//span[text()= `${appName}`]").parent().next().click();
@ -39,98 +37,6 @@ Cypress.Commands.add("revokeAccessGit", (appName) => {
});
});
Cypress.Commands.add(
"connectToGitRepo",
(repo, shouldCommit = true, assertConnectFailure) => {
const testEmail = "test@test.com";
const testUsername = "testusername";
const owner = Cypress.env("TEST_GITHUB_USER_NAME");
let generatedKey;
// open gitSync modal
cy.get(homePage.deployPopupOptionTrigger).click();
cy.get(homePage.connectToGitBtn).click({ force: true });
// cy.intercept(
// {
// url: "api/v1/git/connect/app/*",
// hostname: window.location.host,
// },
// (req) => {
// req.headers["origin"] = "Cypress";
// },
// );
cy.intercept("POST", "/api/v1/applications/ssh-keypair/*").as(
`generateKey-${repo}`,
);
cy.get(gitSyncLocators.gitRepoInput).type(
`git@github.com:${owner}/${repo}.git`,
);
cy.get(gitSyncLocators.generateDeployKeyBtn).click();
cy.wait(`@generateKey-${repo}`).then((result) => {
generatedKey = result.response.body.data.publicKey;
generatedKey = generatedKey.slice(0, generatedKey.length - 1);
// fetch the generated key and post to the github repo
cy.request({
method: "POST",
url: `${GITHUB_API_BASE}/repos/${Cypress.env(
"TEST_GITHUB_USER_NAME",
)}/${repo}/keys`,
headers: {
Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`,
},
body: {
title: "key0",
key: generatedKey,
},
});
cy.get(gitSyncLocators.useGlobalGitConfig).click({ force: true });
cy.get(gitSyncLocators.gitConfigNameInput).type(
`{selectall}${testUsername}`,
);
cy.get(gitSyncLocators.gitConfigEmailInput).type(
`{selectall}${testEmail}`,
);
// click on the connect button and verify
cy.get(gitSyncLocators.connectSubmitBtn).click();
if (!assertConnectFailure) {
// check for connect success
cy.wait("@connectGitLocalRepo").should(
"have.nested.property",
"response.body.responseMeta.status",
200,
);
}
// click commit button
/* if (shouldCommit) {
cy.get(gitSyncLocators.commitCommentInput).type("Initial Commit");
cy.get(gitSyncLocators.commitButton).click();
// check for commit success
cy.wait("@commit").should(
"have.nested.property",
"response.body.responseMeta.status",
201,
);
cy.get(gitSyncLocators.closeGitSyncModal).click();
}
} else {
cy.wait("@connectGitLocalRepo").then((interception) => {
const status = interception.response.body.responseMeta.status;
expect(status).to.be.gte(400);
});
} */
cy.get(gitSyncLocators.closeGitSyncModal).click();
});
},
);
Cypress.Commands.add("latestDeployPreview", () => {
cy.intercept("POST", "/api/v1/applications/publish/*").as("publishApp");
// Wait before publish
@ -187,65 +93,6 @@ Cypress.Commands.add("switchGitBranch", (branch, expectError) => {
AppSidebar.assertVisible(Cypress.config().pageLoadTimeout);
});
Cypress.Commands.add("createTestGithubRepo", (repo, privateFlag = false) => {
cy.request({
method: "POST",
url: `${GITHUB_API_BASE}/user/repos`,
headers: {
Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`,
},
body: {
name: repo,
private: privateFlag,
},
});
});
Cypress.Commands.add("mergeViaGithubApi", ({ base, head, repo }) => {
const owner = Cypress.env("TEST_GITHUB_USER_NAME");
cy.request({
method: "POST",
url: `${GITHUB_API_BASE}/repos/${owner}/${repo}/merges`,
headers: {
Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`,
},
body: {
base,
head,
},
});
});
Cypress.Commands.add("deleteTestGithubRepo", (repo) => {
cy.request({
method: "DELETE",
url: `${GITHUB_API_BASE}/repos/${Cypress.env(
"TEST_GITHUB_USER_NAME",
)}/${repo}`,
headers: {
Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`,
},
});
});
Cypress.Commands.add(
"renameBranchViaGithubApi",
(repo, currentName, newName) => {
cy.request({
method: "POST",
url: `${GITHUB_API_BASE}/repos/${Cypress.env(
"TEST_GITHUB_USER_NAME",
)}/${repo}/branches/${currentName}/rename`,
headers: {
Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`,
},
body: {
new_name: newName,
},
});
},
);
Cypress.Commands.add("commitAndPush", (assertFailure) => {
cy.get(homePage.publishButton).click();
agHelper.AssertElementExist(gitSync._bottomBarPull);
@ -270,29 +117,6 @@ Cypress.Commands.add("commitAndPush", (assertFailure) => {
cy.get(gitSyncLocators.closeGitSyncModal).click();
});
// todo rishabh s: refactor
Cypress.Commands.add(
"createAppAndConnectGit",
(appname, shouldConnect = true, assertConnectFailure) => {
cy.get(homePage.homeIcon).click({ force: true });
cy.get(homePage.createNew).first().click({ force: true });
cy.wait("@createNewApplication").should(
"have.nested.property",
"response.body.responseMeta.status",
201,
);
cy.get("#loading").should("not.exist");
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(2000);
homePageTS.RenameApplication(appname);
cy.createTestGithubRepo(appname, true);
cy.connectToGitRepo(appname, false, assertConnectFailure);
cy.get(gitSyncLocators.closeGitSyncModal).click({ force: true });
},
);
Cypress.Commands.add("merge", (destinationBranch) => {
agHelper.AssertElementExist(gitSync._bottomBarPull);
@ -342,53 +166,22 @@ Cypress.Commands.add(
(repo, assertConnectFailure, failureMessage) => {
const testEmail = "test@test.com";
const testUsername = "testusername";
const owner = Cypress.env("TEST_GITHUB_USER_NAME");
let generatedKey;
// cy.intercept(
// {
// url: "api/v1/git/connect/app/*",
// hostname: window.location.host,
// },
// (req) => {
// req.headers["origin"] = "Cypress";
// },
// );
cy.intercept("GET", "api/v1/git/import/keys?keyType=ECDSA").as(
`generateKey-${repo}`,
);
cy.get(gitSyncLocators.gitRepoInput).type(
//`git@github.com:${owner}/${repo}.git`,
`${dataManager.GITEA_API_URL_TED}/${repo}.git`,
`${dataManager.GIT_CLONE_URL}/${repo}.git`,
);
cy.get(gitSyncLocators.generateDeployKeyBtn).click();
cy.wait(`@generateKey-${repo}`).then((result) => {
generatedKey = result.response.body.data.publicKey;
generatedKey = generatedKey.slice(0, generatedKey.length - 1);
// fetch the generated key and post to the github repo
// cy.request({
// method: "POST",
// url: `${GITHUB_API_BASE}/repos/${Cypress.env(
// "TEST_GITHUB_USER_NAME",
// )}/${repo}/keys`,
// headers: {
// Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`,
// },
// body: {
// title: "key0",
// key: generatedKey,
// },
// });
const key = result.response.body.data.publicKey.trimEnd();
cy.request({
method: "POST",
url: `${dataManager.GITEA_API_BASE_TED}:${dataManager.GITEA_API_PORT_TED}/api/v1/repos/Cypress/${repo}/keys`,
headers: {
Authorization: `token ${Cypress.env("GITEA_TOKEN")}`,
},
url: `${dataManager.GIT_API_BASE}/api/v1/git/keys/${repo}`,
body: {
title: "key1",
key: generatedKey,
key,
read_only: false,
},
});
@ -472,34 +265,13 @@ Cypress.Commands.add(
if (generateKey) {
if (protocol === "ECDSA") {
cy.wait(`@generateKey-${repo}`).then((result) => {
generatedKey = result.response.body.data.publicKey;
generatedKey = generatedKey.slice(0, generatedKey.length - 1);
// fetch the generated key and post to the github repo
// cy.request({
// method: "POST",
// url: `${GITHUB_API_BASE}/repos/${Cypress.env(
// "TEST_GITHUB_USER_NAME",
// )}/${repo}/keys`,
// headers: {
// Authorization: `token ${Cypress.env(
// "GITHUB_PERSONAL_ACCESS_TOKEN",
// )}`,
// },
// body: {
// title: "key0",
// key: generatedKey,
// },
// });
const key = result.response.body.data.publicKey.trimEnd();
cy.request({
method: "POST",
url: `${dataManager.GITEA_API_BASE_TED}:${dataManager.GITEA_API_PORT_TED}/api/v1/repos/Cypress/${repo}/keys`,
headers: {
Authorization: `token ${Cypress.env("GITEA_TOKEN")}`,
},
url: `${dataManager.GIT_API_BASE}/api/v1/repos/Cypress/${repo}/keys`,
body: {
title: "key1",
key: generatedKey,
key,
read_only: false,
},
});