Skip to content

Commit 76a0187

Browse files
authored
a few fixes for Namespace to Gateway update (#1161)
* scroll to top, fix redirect for gateway detail * add return null * scroll to top of details on nav from /list * Cypress/ns to gw cli tests (#1158) Cypress tests for new features in `gwa` CLI from NS to GW. * replace Namespace with Gateway in org permission (#1159)
1 parent b902ab0 commit 76a0187

File tree

11 files changed

+289
-41
lines changed

11 files changed

+289
-41
lines changed

e2e/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ COPY e2e/*.yml /e2e
2222
COPY e2e/entrypoint.sh /tmp
2323
ADD e2e/cypress /e2e/cypress
2424

25-
RUN curl -v -L -O https://github.com/bcgov/gwa-cli/releases/download/v3.0.0/gwa_Linux_x86_64.tgz \
25+
RUN curl -v -L -O https://github.com/bcgov/gwa-cli/releases/download/v3.0.4/gwa_Linux_x86_64.tgz \
2626
&& tar -xzf gwa_Linux_x86_64.tgz \
2727
&& mv gwa /usr/local/bin/.
2828

e2e/cypress/pageObjects/products.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { updateYamlDocument } from "@atomist/yaml-updater";
33
import _ = require("cypress/types/lodash");
44
const YAML = require('yamljs');
5+
const { kebabCase } = require('lodash');
56

67
class Products {
78
path: string = '/manager/products'
@@ -57,7 +58,7 @@ class Products {
5758
}
5859

5960
editProduct(productName: string) {
60-
const pname: string = productName.toLowerCase().replaceAll(' ', '-')
61+
const pname: string = kebabCase(productName)
6162
cy.get(`[data-testid=${pname}-more-options-btn]`).first().click()
6263
cy.get(`[data-testid=${pname}-edit-btn]`).first().click()
6364
// cy.get(this.updateBtn).click()
@@ -92,7 +93,7 @@ class Products {
9293
}
9394

9495
editProductEnvironment(productName: string, envName: string) {
95-
const pname: string = productName.toLowerCase().replaceAll(' ', '-')
96+
const pname: string = kebabCase(productName)
9697
let env = this.getTestIdEnvName(envName);
9798
cy.get(`[data-testid=${pname}-${env}-edit-btn]`).click()
9899
cy.wait(2000)
@@ -228,16 +229,15 @@ class Products {
228229
}
229230

230231
deleteProductEnvironment(productName: string, envName: string) {
231-
const pname: string = productName.toLowerCase().replaceAll(' ', '-')
232+
const pname: string = kebabCase(productName)
232233
let env = this.getTestIdEnvName(envName);
233234
cy.get(`[data-testid=${pname}-${env}-more-options-btn]`).click()
234235
cy.get(`[data-testid=${pname}-${env}-delete-btn]`).click()
235236
cy.get(this.deleteConfirmationBtn).click()
236237
}
237238

238239
deleteProduct(productName: string) {
239-
// this.editProduct(productName)
240-
const pname: string = productName.toLowerCase().replaceAll(' ', '-')
240+
const pname: string = kebabCase(productName)
241241
cy.get(`[data-testid=${pname}-edit-btn]`).first().click({ force: true })
242242
cy.get(`[data-testid=${pname}-delete-btn]`).first().click({ force: true })
243243
cy.get(this.deleteProductConfirmationBtn).click()

e2e/cypress/tests/16-gwa-cli/01-cli-commands.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
1-
import LoginPage from '../../pageObjects/login'
2-
import ApplicationPage from '../../pageObjects/applications'
3-
import ApiDirectoryPage from '../../pageObjects/apiDirectory'
4-
import MyAccessPage from '../../pageObjects/myAccess'
5-
const YAML = require('yamljs');
6-
let userSession: any
71
let cli = require("../../fixtures/test_data/gwa-cli.json")
2+
let userSession: any
83
var cleanedUrl = Cypress.env('BASE_URL').replace(/^http?:\/\//i, "");
9-
const jose = require('node-jose')
104

11-
describe('Verify CLI commands', () => {
12-
const login = new LoginPage()
13-
const apiDir = new ApiDirectoryPage()
14-
const app = new ApplicationPage()
15-
const ma = new MyAccessPage()
5+
describe('Verify config / login CLI commands', () => {
166
let namespace: string
177

188
before(() => {
19-
// cy.visit('/')
209
cy.deleteAllCookies()
2110
cy.reload(true)
2211
})
@@ -25,7 +14,6 @@ describe('Verify CLI commands', () => {
2514
cy.preserveCookies()
2615
cy.fixture('apiowner').as('apiowner')
2716
cy.fixture('common-testdata').as('common-testdata')
28-
// cy.visit(login.path)
2917
})
3018

3119
it('authenticates Janis (api owner) to get the user session token', () => {
@@ -90,7 +78,6 @@ describe('Verify CLI commands', () => {
9078
});
9179
})
9280

93-
9481
it('Check gwa gateway list command and verify the created namespace in the list', () => {
9582
cy.executeCliCommand('gwa gateway list --host ' + cleanedUrl + ' --scheme http').then((response) => {
9683
expect(response.stdout).to.contain(namespace);
@@ -103,4 +90,4 @@ describe('Verify CLI commands', () => {
10390
cy.deleteAllCookies()
10491
})
10592

106-
})
93+
})
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import LoginPage from '../../pageObjects/login'
2+
import ApplicationPage from '../../pageObjects/applications'
3+
import ApiDirectoryPage from '../../pageObjects/apiDirectory'
4+
import MyAccessPage from '../../pageObjects/myAccess'
5+
import HomePage from '../../pageObjects/home';
6+
import Products from '../../pageObjects/products';
7+
const YAML = require('yamljs');
8+
let cli = require("../../fixtures/test_data/gwa-cli.json")
9+
const { v4: uuidv4 } = require('uuid')
10+
const jose = require('node-jose')
11+
12+
let userSession: any
13+
const customId = uuidv4().replace(/-/g, '').toLowerCase().substring(0, 3)
14+
const serviceName = 'my-service-' + customId
15+
16+
describe('Verify CLI commands for generate/apply config', () => {
17+
const login = new LoginPage()
18+
const apiDir = new ApiDirectoryPage()
19+
const app = new ApplicationPage()
20+
const ma = new MyAccessPage()
21+
const pd = new Products()
22+
let namespace: string
23+
const home = new HomePage()
24+
25+
before(() => {
26+
// cy.visit('/')
27+
cy.reload(true)
28+
})
29+
30+
beforeEach(() => {
31+
cy.preserveCookies()
32+
cy.fixture('apiowner').as('apiowner')
33+
// cy.visit(login.path)
34+
})
35+
36+
it('authenticates Janis (api owner) to get the user session token', () => {
37+
cy.get('@apiowner').then(({ apiTest }: any) => {
38+
cy.getUserSessionTokenValue(apiTest.namespace, false).then((value) => {
39+
userSession = value
40+
})
41+
})
42+
})
43+
44+
it('Check gwa config command to set token', () => {
45+
cy.executeCliCommand('gwa config set --token ' + userSession).then((response) => {
46+
expect(response.stdout).to.contain("Config settings saved")
47+
});
48+
})
49+
50+
it('Check gwa command to generate config for client credential template', () => {
51+
const command = [
52+
'gwa generate-config --template quick-start',
53+
`--service ${serviceName}`,
54+
'--upstream https://httpbin.org',
55+
'--org ministry-of-health',
56+
'--org-unit planning-and-innovation-division',
57+
'--out gw-config-qs.yaml'
58+
].join(' ');
59+
cy.executeCliCommand(command).then((response) => {
60+
expect(response.stdout).to.contain("File gw-config-qs.yaml created")
61+
});
62+
})
63+
64+
it('Check gwa command to apply generated config', () => {
65+
cy.executeCliCommand('gwa apply -i gw-config-qs.yaml').then((response) => {
66+
expect(response.stdout).to.contain("3/3 Published, 0 Skipped")
67+
let wordOccurrences = (response.stdout.match(/\bcreated\b/g) || []).length;
68+
expect(wordOccurrences).to.equal(2)
69+
});
70+
})
71+
72+
it('Check gwa status --hosts include routes', () => {
73+
cy.executeCliCommand('gwa status --hosts').then((response) => {
74+
expect(response.stdout).to.contain('https://' + serviceName + '.dev.api.gov.bc.ca')
75+
});
76+
})
77+
78+
it('activates namespace in Portal', () => {
79+
cy.executeCliCommand('gwa gateway current').then((response) => {
80+
const namespace = response.stdout.match(/\bgw-\w+/g)[0]
81+
cy.activateGateway(namespace)
82+
})
83+
})
84+
85+
it('Verify that the product created through gwa command is displayed in the portal', () => {
86+
cy.visit(pd.path)
87+
pd.editProductEnvironment(serviceName + ' API', 'dev')
88+
})
89+
90+
it('Verify that the dataset created through GWA comand is assocuated with the product', () => {
91+
cy.visit(pd.path)
92+
pd.verifyDataset(serviceName, serviceName + ' API')
93+
})
94+
95+
it('Verify service name validation error in new namespace', () => {
96+
const command = [
97+
'gwa generate-config --template quick-start',
98+
`--service ${serviceName}`,
99+
'--upstream https://httpbin.org',
100+
'--org ministry-of-health',
101+
'--org-unit planning-and-innovation-division'
102+
].join(' ');
103+
cy.executeCliCommand('gwa gateway create --generate').then((response) => {
104+
const namespace = response.stdout.match(/\bgw-\w+/g)[0]
105+
cy.executeCliCommand(command).then((response) => {
106+
expect(response.stderr).to.contain(`Error: Service ${serviceName} is already in use. Suggestion: ${namespace}-${serviceName}`)
107+
});
108+
});
109+
})
110+
111+
after(() => {
112+
cy.logout()
113+
})
114+
115+
})

e2e/cypress/tests/16-gwa-cli/02-cli-generate-config.ts renamed to e2e/cypress/tests/16-gwa-cli/03-cli-generate-config-client-cred.ts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@ import MyAccessPage from '../../pageObjects/myAccess'
55
import HomePage from '../../pageObjects/home';
66
import Products from '../../pageObjects/products';
77
const YAML = require('yamljs');
8-
let userSession: any
98
let cli = require("../../fixtures/test_data/gwa-cli.json")
10-
9+
const { v4: uuidv4 } = require('uuid')
1110
const jose = require('node-jose')
1211

12+
let userSession: any
13+
let namespace: string
14+
const customId = uuidv4().replace(/-/g, '').toLowerCase().substring(0, 3)
15+
const serviceName = 'my-service-' + customId
16+
1317
describe('Verify CLI commands for generate/apply config', () => {
1418
const login = new LoginPage()
1519
const apiDir = new ApiDirectoryPage()
1620
const app = new ApplicationPage()
1721
const ma = new MyAccessPage()
1822
const pd = new Products()
19-
let namespace: string
2023
const home = new HomePage()
2124

2225
before(() => {
@@ -45,26 +48,38 @@ describe('Verify CLI commands for generate/apply config', () => {
4548
})
4649

4750
it('Check gwa command to generate config for client credential template', () => {
48-
cy.executeCliCommand('gwa generate-config --template client-credentials-shared-idp --service my-service --upstream https://httpbin.org --org ministry-of-health --org-unit planning-and-innovation-division --out gw-config.yaml').then((response) => {
49-
expect(response.stdout).to.contain("File gw-config.yaml created")
51+
const serviceName = 'my-service-' + customId
52+
const command = [
53+
'gwa generate-config --template client-credentials-shared-idp',
54+
`--service ${serviceName}`,
55+
'--upstream https://httpbin.org',
56+
'--org ministry-of-health',
57+
'--org-unit planning-and-innovation-division',
58+
'--out gw-config-cc.yaml'
59+
].join(' ');
60+
cy.executeCliCommand(command).then((response) => {
61+
expect(response.stdout).to.contain("File gw-config-cc.yaml created")
5062
});
5163
})
5264

5365
it('Check gwa command to apply generated config', () => {
54-
cy.executeCliCommand('gwa apply -i gw-config.yaml').then((response) => {
66+
cy.executeCliCommand('gwa apply -i gw-config-cc.yaml').then((response) => {
67+
expect(response.stdout).to.contain("4/4 Published, 0 Skipped")
5568
let wordOccurrences = (response.stdout.match(/\bcreated\b/g) || []).length;
5669
expect(wordOccurrences).to.equal(3)
57-
namespace = response.stdout.match(/\bgw-\w+/g)[0]
5870
});
5971
})
6072

61-
it('activates new namespace', () => {
62-
cy.activateGateway(namespace)
73+
it('activates namespace in Portal', () => {
74+
cy.executeCliCommand('gwa gateway current').then((response) => {
75+
namespace = response.stdout.match(/\bgw-\w+/g)[0]
76+
cy.activateGateway(namespace)
77+
})
6378
})
6479

6580
it('Verify that the product created through gwa command is displayed in the portal', () => {
6681
cy.visit(pd.path)
67-
pd.editProductEnvironment('my-service API', 'dev')
82+
pd.editProductEnvironment(serviceName + ' API', 'dev')
6883
})
6984

7085
it('Verify the Authorization scope and issuer details for the product', () => {
@@ -77,11 +92,7 @@ describe('Verify CLI commands for generate/apply config', () => {
7792

7893
it('Verify that the dataset created through GWA comand is assocuated with the product', () => {
7994
cy.visit(pd.path)
80-
pd.verifyDataset('my-service', 'my-service API')
81-
})
82-
83-
it('Navigate to home path', () => {
84-
cy.visit(login.path)
95+
pd.verifyDataset(serviceName, serviceName + ' API')
8596
})
8697

8798
after(() => {

0 commit comments

Comments
 (0)