Skip to content

Commit

Permalink
Cypress framework optimization (#951)
Browse files Browse the repository at this point in the history
* Add tests for Revoke Environment access and Delete consumer feature

* make name in metrics list unique

* fix publishing api content

* fix publishing api content

* upd service acct title

* fix batch sync not returning non 200 error on failures

* fix public flow access button defect

* upd error messaging for revoke consumer access

* remove the manual mode for cred issuer

* make sure we render routes even if no path is provided

* pending requests should be enforced editing consumer

* ensure email name is provided

* add confirmation dialogs

* fix for error when deleting basic issuer

* provide better error info in activity for issuers

* fix delete namespace race condition

* Optimized test-data files by removing the redundant records

* remove debugger statement

* Set default run browser as edge

---------

Co-authored-by: ikethecoder <ikethecoder@copeconsulting.ca>
  • Loading branch information
nirajCITZ and ikethecoder committed Nov 7, 2023
1 parent 1d11ed5 commit d1a6716
Show file tree
Hide file tree
Showing 81 changed files with 893 additions and 255 deletions.
82 changes: 82 additions & 0 deletions e2e/cypress/fixtures/common-testdata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"namespace": "newplatform",
"deleteResources": {
"namespace": "gw-a9232"
},
"clientCredentials": {
"namespace": "gw-d2c50"
},
"namespacePreview": {
"namespace": "gw-16a3a"
},
"orgAssignment": {
"namespace": "gw-f016e"
},
"orgAssignmentMultipleAdmin": {
"namespace": "orgassignment1"
},
"orgAssignmentOrgUnit": {
"namespace": "orgassign-unit"
},
"checkPermission": {
"namespace": "gw-deedd",
"grantPermission": {
"Mark": {
"userName": "Mark F Mark L",
"email": "mark@gmail.com",
"accessRole": [
"Access.Manage"
]
},
"Mark_NV": {
"userName": "Mark F Mark L",
"email": "mark@gmail.com",
"accessRole": [
"Namespace.View"
]
},
"Wendy": {
"userName": "Wendy F Wendy L",
"email": "wendy@test.com",
"accessRole": [
"Namespace.Manage",
"CredentialIssuer.Admin"
]
},
"Wendy_NM": {
"userName": "Wendy F Wendy L",
"email": "wendy@test.com",
"accessRole": [
"Namespace.Manage"
]
},
"Wendy_CA": {
"userName": "Wendy F Wendy L",
"email": "wendy@test.com",
"accessRole": [
"CredentialIssuer.Admin"
]
},
"Wendy_GC": {
"userName": "Wendy F Wendy L",
"email": "wendy@test.com",
"accessRole": [
"GatewayConfig.Publish",
"Namespace.View"
]
},
"Janis": {
"userName": "Janis Smith",
"email": "janis@testmail.com",
"accessRole": [
"Namespace.Manage",
"CredentialIssuer.Admin"
]
}
}
},
"apiTest": {
"namespace": "gw-c3f31",
"delete_namespace": "testplatform"
}
}
10 changes: 10 additions & 0 deletions e2e/cypress/fixtures/developer.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@
"environment": "dev"
}
},
"deleteResources":{
"application": {
"name": "Delete-Auto Test App",
"description": "Test application for auto test"
},
"product": {
"name": "Delete-Auto Test Product",
"environment": "dev"
}
},
"elevatedAccess":{
"application": {
"name": "Request for Elevated Acess",
Expand Down
34 changes: 34 additions & 0 deletions e2e/cypress/fixtures/service-plugin_A.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
services:
- name: a-service-for-newplatform
host: httpbin.org
tags: [ns.newplatform.test]
port: 443
protocol: https
retries: 0
routes:
- name: a-service-for-newplatform-route
tags: [ns.newplatform.test]
hosts:
- a-service-for-newplatform.api.gov.bc.ca
paths:
- /
methods:
- GET
strip_path: false
https_redirect_status_code: 426
path_handling: v0

plugins:
- name: key-auth
tags: [ ns.newplatform.test ]
protocols: [ http, https ]
config:
key_names: ["X-API-KEY"]
run_on_preflight: true
hide_credentials: true
key_in_body: false
- name: acl
tags: [ ns.newplatform.test ]
config:
hide_groups_header: true
allow: [ "406CB7CF" ]
34 changes: 34 additions & 0 deletions e2e/cypress/fixtures/service-plugin_B.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
services:
- name: a-service-for-newplatform-test
host: httpbin.org
tags: [ns.newplatform.test]
port: 443
protocol: https
retries: 0
routes:
- name: a-service-for-newplatform-test-route
tags: [ns.newplatform.test]
hosts:
- a-service-for-newplatform-test.api.gov.bc.ca
paths:
- /
methods:
- GET
strip_path: false
https_redirect_status_code: 426
path_handling: v0

plugins:
- name: key-auth
tags: [ ns.newplatform.test ]
protocols: [ http, https ]
config:
key_names: ["X-API-KEY"]
run_on_preflight: true
hide_credentials: true
key_in_body: false
- name: acl
tags: [ ns.newplatform.test ]
config:
hide_groups_header: true
allow: [ "9AA97172" ]
2 changes: 1 addition & 1 deletion e2e/cypress/pageObjects/authProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class AuthorizationProfile {
cy.wrap($e1).find('button').eq(1).click()
cy.wait(2000)
cy.wrap($e1).find('button').last().click({force: true})
cy.verifyToastMessage(authProfileName +' deleted')
// cy.verifyToastMessage(authProfileName +' deleted')
return false
}
})
Expand Down
11 changes: 10 additions & 1 deletion e2e/cypress/pageObjects/consumers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default class ConsumersPage {
linkConsumerToNamespaceBtn: string = '[data-testid="link-consumer-namespace"]'
userNameTxt: string = '[data-testid="link-consumer-username"]'
linkBtn: string = '[data-testid="link-consumer-link-btn"]'
productDetails: string = '[data-testid="product-list-table"]'

clickOnRateLimitingOption() {
cy.get(this.rateLimitingOption, { timeout: 2000 }).click()
Expand Down Expand Up @@ -202,7 +203,7 @@ export default class ConsumersPage {
}

editConsumerDialog() {
cy.get('[data-testid="product-list-table"]').then($button => {
cy.get(this.productDetails).then($button => {
if ($button.is(':visible')) {
cy.contains('Edit').first().click()
}
Expand Down Expand Up @@ -374,4 +375,12 @@ export default class ConsumersPage {
getText() {
cy.get('[data-testid="all-consumer-control-tbl"]').find('tr').last().find('td').first().find('a').as('inputValue')
}

revokeProductEnvAccess(prodEnv: any) {
cy.get(this.productDetails).find('tr').each(($row) => {
if ($row.find('td:nth-child(1)').text() == prodEnv) {
cy.wrap($row).find('button').last().click({ force: true })
}
})
}
}
2 changes: 1 addition & 1 deletion e2e/cypress/pageObjects/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class HomePage {
cy.wait(1000)
cy.get(this.namespaceNameInput).next('div').then(($ele) => {
let validationMessage = $ele.text()
assert.equal(validationMessage,"Namespace name must be between 5 and 15 alpha-numeric lowercase characters and begin with an alphabet.")
assert.equal(validationMessage,"Namespace name must be between 5 and 15 alpha-numeric lowercase characters and start and end with an alphabet.")
})
// cy.verifyToastMessage("Namespace create failed")
})
Expand Down
40 changes: 26 additions & 14 deletions e2e/cypress/support/auth-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,20 @@ Cypress.Commands.add('resetCredential', (accessRole: string) => {
cy.visit('/')
cy.reload()
cy.fixture('apiowner').as('apiowner')
cy.fixture('common-testdata').as('common-testdata')
cy.preserveCookies()
cy.visit(login.path)
cy.get('@apiowner').then(({ user, checkPermission }: any) => {
cy.login(user.credentials.username, user.credentials.password)
cy.log('Logged in!')
home.useNamespace(checkPermission.namespace)
cy.visit(na.path)
na.revokeAllPermission(checkPermission.grantPermission[accessRole].userName)
cy.wait(2000)
na.clickGrantUserAccessButton()
na.grantPermission(checkPermission.grantPermission[accessRole])
cy.get('@apiowner').then(({ user }: any) => {
cy.get('@common-testdata').then(({ checkPermission }: any) => {
cy.login(user.credentials.username, user.credentials.password)
cy.log('Logged in!')
home.useNamespace(checkPermission.namespace)
cy.visit(na.path)
na.revokeAllPermission(checkPermission.grantPermission[accessRole].userName)
cy.wait(2000)
na.clickGrantUserAccessButton()
na.grantPermission(checkPermission.grantPermission[accessRole])
})
})
})

Expand Down Expand Up @@ -241,17 +244,26 @@ Cypress.Commands.add('getServiceOrRouteID', (configType: string, host: string) =
}).then((res) => {
expect(res.status).to.eq(200)
if (config === 'routes') {
cy.saveState(config + 'ID', Cypress._.get((Cypress._.filter(res.body.data, ["hosts", [host+".api.gov.bc.ca"]]))[0], 'id'))
cy.saveState(config + 'ID', Cypress._.get((Cypress._.filter(res.body.data, ["hosts", [host + ".api.gov.bc.ca"]]))[0], 'id'))
}
else {
cy.saveState(config + 'ID', Cypress._.get((Cypress._.filter(res.body.data, ["name", host]))[0], 'id'))
}
})
})

Cypress.Commands.add('publishApi', (fileName: string, namespace: string, flag?: boolean) => {
Cypress.Commands.add('publishApi', (fileNames: any, namespace: string, flag?: boolean) => {
let fixtureFile = flag ? "state/regen" : "state/store";
cy.log('< Publish API')
let fileName = ''
if (fileNames instanceof Array) {
for (const filepath of fileNames) {
fileName = fileName + ' ./cypress/fixtures/' + filepath;
}
}
else {
fileName = ' ./cypress/fixtures/' + fileNames
}
const requestName: string = 'publishAPI'
cy.fixture(fixtureFile).then((creds: any) => {
const serviceAcctCreds = JSON.parse(creds.credentials)
Expand All @@ -263,7 +275,7 @@ Cypress.Commands.add('publishApi', (fileName: string, namespace: string, flag?:
cy.executeCliCommand('gwa config set --token ' + res.body.access_token).then((response) => {
{
expect(response.stdout).to.contain("Config settings saved")
cy.executeCliCommand('gwa pg ./cypress/fixtures/' + fileName).then((response) => {
cy.executeCliCommand('gwa pg ' + fileName).then((response) => {
expect(response.stdout).to.contain("Gateway config published")
})
}
Expand Down Expand Up @@ -502,7 +514,7 @@ Cypress.Commands.add('updatePropertiesOfPluginFile', (filename: string, property
if (propertyName === "config.anonymous") {
obj.plugins[0].config.anonymous = propertyValue
}
else if (propertyName === "tags"){
else if (propertyName === "tags") {
obj.plugins[0][propertyName] = propertyValue
}
else {
Expand Down Expand Up @@ -573,7 +585,7 @@ Cypress.Commands.add('forceVisit', (url: string) => {
});
});

Cypress.Commands.add('updateJsonBoby', (json: any, key: string, newValue: string):any => {
Cypress.Commands.add('updateJsonBoby', (json: any, key: string, newValue: string): any => {
json[key] = newValue
return json
});
Expand Down
2 changes: 1 addition & 1 deletion e2e/cypress/support/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ declare namespace Cypress {
client_secret: string
): Chainable<Cypress.Response<any>>

publishApi(fileName: string, namespace: string, flag?: boolean): Chainable<Cypress.Response<any>>
publishApi(fileNames: any, namespace: string, flag?: boolean): Chainable<Cypress.Response<any>>

getServiceOrRouteID(configType: string, host: string
): Chainable<Cypress.Response<any>>
Expand Down
4 changes: 0 additions & 4 deletions e2e/cypress/support/util-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ Cypress.Commands.add('resetState', () => {
})

Cypress.Commands.add('updateJsonValue', (filePath: string, jsonPath: string, newValue: string, index?: any) => {
debugger
cy.readFile('cypress/fixtures/' + filePath).then(currState => {
debugger

const keys = jsonPath.split('.'); // Split the keyPath using dot notation
let currentObj = currState;
Expand Down Expand Up @@ -142,7 +140,6 @@ Cypress.Commands.add('executeCliCommand', (command: string) => {
})

Cypress.Commands.add('replaceWordInJsonObject', (targetWord: string, replacement: string, fileName: string) => {
debugger
cy.readFile('cypress/fixtures/' + fileName).then((content: any) => {
let regex = new RegExp(targetWord, 'g');
let modifiedString = content.replace(regex, replacement);
Expand All @@ -165,7 +162,6 @@ Cypress.Commands.add('gwaPublish', (type: string, fileName: string) => {
Cypress.Commands.add('deleteFileInE2EFolder', (fileName: string) => {
const currentDirectory = Cypress.config('fileServerFolder'); // Get the current working directory
const filePath = path.join(currentDirectory, fileName)
debugger
try {
cy.exec(`rm -f ${filePath}`);
cy.log(`File '${fileName}' has been deleted from the e2e folder.`);
Expand Down
Loading

0 comments on commit d1a6716

Please sign in to comment.