Skip to content

Commit

Permalink
Cypress/ns to gw cli tests (#1158)
Browse files Browse the repository at this point in the history
Cypress tests for new features in `gwa` CLI from NS to GW.
  • Loading branch information
rustyjux authored Aug 28, 2024
1 parent c8ac094 commit 5390685
Show file tree
Hide file tree
Showing 8 changed files with 284 additions and 40 deletions.
2 changes: 1 addition & 1 deletion e2e/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ COPY e2e/*.yml /e2e
COPY e2e/entrypoint.sh /tmp
ADD e2e/cypress /e2e/cypress

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

Expand Down
10 changes: 5 additions & 5 deletions e2e/cypress/pageObjects/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { updateYamlDocument } from "@atomist/yaml-updater";
import _ = require("cypress/types/lodash");
const YAML = require('yamljs');
const { kebabCase } = require('lodash');

class Products {
path: string = '/manager/products'
Expand Down Expand Up @@ -57,7 +58,7 @@ class Products {
}

editProduct(productName: string) {
const pname: string = productName.toLowerCase().replaceAll(' ', '-')
const pname: string = kebabCase(productName)
cy.get(`[data-testid=${pname}-more-options-btn]`).first().click()
cy.get(`[data-testid=${pname}-edit-btn]`).first().click()
// cy.get(this.updateBtn).click()
Expand Down Expand Up @@ -92,7 +93,7 @@ class Products {
}

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

deleteProductEnvironment(productName: string, envName: string) {
const pname: string = productName.toLowerCase().replaceAll(' ', '-')
const pname: string = kebabCase(productName)
let env = this.getTestIdEnvName(envName);
cy.get(`[data-testid=${pname}-${env}-more-options-btn]`).click()
cy.get(`[data-testid=${pname}-${env}-delete-btn]`).click()
cy.get(this.deleteConfirmationBtn).click()
}

deleteProduct(productName: string) {
// this.editProduct(productName)
const pname: string = productName.toLowerCase().replaceAll(' ', '-')
const pname: string = kebabCase(productName)
cy.get(`[data-testid=${pname}-edit-btn]`).first().click({ force: true })
cy.get(`[data-testid=${pname}-delete-btn]`).first().click({ force: true })
cy.get(this.deleteProductConfirmationBtn).click()
Expand Down
19 changes: 3 additions & 16 deletions e2e/cypress/tests/16-gwa-cli/01-cli-commands.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import LoginPage from '../../pageObjects/login'
import ApplicationPage from '../../pageObjects/applications'
import ApiDirectoryPage from '../../pageObjects/apiDirectory'
import MyAccessPage from '../../pageObjects/myAccess'
const YAML = require('yamljs');
let userSession: any
let cli = require("../../fixtures/test_data/gwa-cli.json")
let userSession: any
var cleanedUrl = Cypress.env('BASE_URL').replace(/^http?:\/\//i, "");
const jose = require('node-jose')

describe('Verify CLI commands', () => {
const login = new LoginPage()
const apiDir = new ApiDirectoryPage()
const app = new ApplicationPage()
const ma = new MyAccessPage()
describe('Verify config / login CLI commands', () => {
let namespace: string

before(() => {
// cy.visit('/')
cy.deleteAllCookies()
cy.reload(true)
})
Expand All @@ -25,7 +14,6 @@ describe('Verify CLI commands', () => {
cy.preserveCookies()
cy.fixture('apiowner').as('apiowner')
cy.fixture('common-testdata').as('common-testdata')
// cy.visit(login.path)
})

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


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

})
})
115 changes: 115 additions & 0 deletions e2e/cypress/tests/16-gwa-cli/02-cli-generate-config-quick-start.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import LoginPage from '../../pageObjects/login'
import ApplicationPage from '../../pageObjects/applications'
import ApiDirectoryPage from '../../pageObjects/apiDirectory'
import MyAccessPage from '../../pageObjects/myAccess'
import HomePage from '../../pageObjects/home';
import Products from '../../pageObjects/products';
const YAML = require('yamljs');
let cli = require("../../fixtures/test_data/gwa-cli.json")
const { v4: uuidv4 } = require('uuid')
const jose = require('node-jose')

let userSession: any
const customId = uuidv4().replace(/-/g, '').toLowerCase().substring(0, 3)
const serviceName = 'my-service-' + customId

describe('Verify CLI commands for generate/apply config', () => {
const login = new LoginPage()
const apiDir = new ApiDirectoryPage()
const app = new ApplicationPage()
const ma = new MyAccessPage()
const pd = new Products()
let namespace: string
const home = new HomePage()

before(() => {
// cy.visit('/')
cy.reload(true)
})

beforeEach(() => {
cy.preserveCookies()
cy.fixture('apiowner').as('apiowner')
// cy.visit(login.path)
})

it('authenticates Janis (api owner) to get the user session token', () => {
cy.get('@apiowner').then(({ apiTest }: any) => {
cy.getUserSessionTokenValue(apiTest.namespace, false).then((value) => {
userSession = value
})
})
})

it('Check gwa config command to set token', () => {
cy.executeCliCommand('gwa config set --token ' + userSession).then((response) => {
expect(response.stdout).to.contain("Config settings saved")
});
})

it('Check gwa command to generate config for client credential template', () => {
const command = [
'gwa generate-config --template quick-start',
`--service ${serviceName}`,
'--upstream https://httpbin.org',
'--org ministry-of-health',
'--org-unit planning-and-innovation-division',
'--out gw-config-qs.yaml'
].join(' ');
cy.executeCliCommand(command).then((response) => {
expect(response.stdout).to.contain("File gw-config-qs.yaml created")
});
})

it('Check gwa command to apply generated config', () => {
cy.executeCliCommand('gwa apply -i gw-config-qs.yaml').then((response) => {
expect(response.stdout).to.contain("3/3 Published, 0 Skipped")
let wordOccurrences = (response.stdout.match(/\bcreated\b/g) || []).length;
expect(wordOccurrences).to.equal(2)
});
})

it('Check gwa status --hosts include routes', () => {
cy.executeCliCommand('gwa status --hosts').then((response) => {
expect(response.stdout).to.contain('https://' + serviceName + '.dev.api.gov.bc.ca')
});
})

it('activates namespace in Portal', () => {
cy.executeCliCommand('gwa gateway current').then((response) => {
const namespace = response.stdout.match(/\bgw-\w+/g)[0]
cy.activateGateway(namespace)
})
})

it('Verify that the product created through gwa command is displayed in the portal', () => {
cy.visit(pd.path)
pd.editProductEnvironment(serviceName + ' API', 'dev')
})

it('Verify that the dataset created through GWA comand is assocuated with the product', () => {
cy.visit(pd.path)
pd.verifyDataset(serviceName, serviceName + ' API')
})

it('Verify service name validation error in new namespace', () => {
const command = [
'gwa generate-config --template quick-start',
`--service ${serviceName}`,
'--upstream https://httpbin.org',
'--org ministry-of-health',
'--org-unit planning-and-innovation-division'
].join(' ');
cy.executeCliCommand('gwa gateway create --generate').then((response) => {
const namespace = response.stdout.match(/\bgw-\w+/g)[0]
cy.executeCliCommand(command).then((response) => {
expect(response.stderr).to.contain(`Error: Service ${serviceName} is already in use. Suggestion: ${namespace}-${serviceName}`)
});
});
})

after(() => {
cy.logout()
})

})
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ import MyAccessPage from '../../pageObjects/myAccess'
import HomePage from '../../pageObjects/home';
import Products from '../../pageObjects/products';
const YAML = require('yamljs');
let userSession: any
let cli = require("../../fixtures/test_data/gwa-cli.json")

const { v4: uuidv4 } = require('uuid')
const jose = require('node-jose')

let userSession: any
let namespace: string
const customId = uuidv4().replace(/-/g, '').toLowerCase().substring(0, 3)
const serviceName = 'my-service-' + customId

describe('Verify CLI commands for generate/apply config', () => {
const login = new LoginPage()
const apiDir = new ApiDirectoryPage()
const app = new ApplicationPage()
const ma = new MyAccessPage()
const pd = new Products()
let namespace: string
const home = new HomePage()

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

it('Check gwa command to generate config for client credential template', () => {
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) => {
expect(response.stdout).to.contain("File gw-config.yaml created")
const serviceName = 'my-service-' + customId
const command = [
'gwa generate-config --template client-credentials-shared-idp',
`--service ${serviceName}`,
'--upstream https://httpbin.org',
'--org ministry-of-health',
'--org-unit planning-and-innovation-division',
'--out gw-config-cc.yaml'
].join(' ');
cy.executeCliCommand(command).then((response) => {
expect(response.stdout).to.contain("File gw-config-cc.yaml created")
});
})

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

it('activates new namespace', () => {
cy.activateGateway(namespace)
it('activates namespace in Portal', () => {
cy.executeCliCommand('gwa gateway current').then((response) => {
namespace = response.stdout.match(/\bgw-\w+/g)[0]
cy.activateGateway(namespace)
})
})

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

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

it('Verify that the dataset created through GWA comand is assocuated with the product', () => {
cy.visit(pd.path)
pd.verifyDataset('my-service', 'my-service API')
})

it('Navigate to home path', () => {
cy.visit(login.path)
pd.verifyDataset(serviceName, serviceName + ' API')
})

after(() => {
Expand Down
Loading

0 comments on commit 5390685

Please sign in to comment.