-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PP-12395: Cypress test for API keys landing page #4392
Merged
oswaldquek
merged 2 commits into
master
from
PP-12395-api-keys-landing-page-cypress-test
Dec 19, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
test/cypress/integration/simplified-account/service-settings/api-keys/api-keys.cy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
const userStubs = require('@test/cypress/stubs/user-stubs') | ||
const ROLES = require('@test/fixtures/roles.fixtures') | ||
const gatewayAccountStubs = require('@test/cypress/stubs/gateway-account-stubs') | ||
const apiKeysStubs = require('@test/cypress/stubs/api-keys-stubs') | ||
const { Token } = require('@models/Token.class') | ||
|
||
const USER_EXTERNAL_ID = 'user-123-abc' | ||
const SERVICE_EXTERNAL_ID = 'service-456-def' | ||
const GATEWAY_ACCOUNT_ID = 11 | ||
const ACCOUNT_TYPE = 'test' | ||
|
||
const setupStubs = (role = 'admin', apiKeys = []) => { | ||
cy.task('setupStubs', [ | ||
userStubs.getUserSuccess({ | ||
userExternalId: USER_EXTERNAL_ID, | ||
gatewayAccountId: GATEWAY_ACCOUNT_ID, | ||
serviceName: { en: 'My cool service' }, | ||
serviceExternalId: SERVICE_EXTERNAL_ID, | ||
role: ROLES[role], | ||
features: 'degatewayaccountification' // TODO remove features once simplified accounts are live | ||
}), | ||
gatewayAccountStubs.getAccountByServiceIdAndAccountType(SERVICE_EXTERNAL_ID, ACCOUNT_TYPE, { gateway_account_id: GATEWAY_ACCOUNT_ID }), | ||
apiKeysStubs.getApiKeysForGatewayAccount(GATEWAY_ACCOUNT_ID, apiKeys) | ||
]) | ||
} | ||
|
||
describe('Settings - API keys', () => { | ||
beforeEach(() => { | ||
cy.setEncryptedCookies(USER_EXTERNAL_ID) | ||
}) | ||
|
||
describe('for an admin user', () => { | ||
|
||
describe('when there are no active API keys', () => { | ||
beforeEach(() => { | ||
setupStubs() | ||
}) | ||
it('should show appropriate buttons and text', () => { | ||
cy.visit(`/simplified/service/${SERVICE_EXTERNAL_ID}/account/${ACCOUNT_TYPE}/settings/api-keys`) | ||
|
||
cy.get('#api-keys').should('have.text', 'API keys') | ||
cy.get('.service-settings-pane') | ||
.find('a') | ||
.contains('Create a new API key') | ||
.should('exist') | ||
cy.get('.service-settings-pane') | ||
.find('h2') | ||
.contains('There are no active test API keys') | ||
.should('exist') | ||
cy.get('.service-settings-pane') | ||
.find('a') | ||
.contains('Show revoked API keys') | ||
.should('exist') | ||
}) | ||
}) | ||
|
||
describe('when there are active API keys', () => { | ||
const apiKeys = [ | ||
new Token().withCreatedBy('system generated').withDescription('description').withIssuedDate('12 Dec 2024'), | ||
new Token().withCreatedBy('algae bra').withDescription('mathematical clothes').withIssuedDate('10 Dec 2024') | ||
] | ||
beforeEach(() => { | ||
setupStubs('admin', apiKeys) | ||
}) | ||
it('should show appropriate buttons and text', () => { | ||
cy.visit(`/simplified/service/${SERVICE_EXTERNAL_ID}/account/${ACCOUNT_TYPE}/settings/api-keys`) | ||
|
||
cy.get('#api-keys').should('have.text', 'API keys') | ||
cy.get('.service-settings-pane') | ||
.find('a') | ||
.contains('Create a new API key') | ||
.should('exist') | ||
cy.get('.service-settings-pane') | ||
.find('h2') | ||
.contains('Active test API keys (2)') | ||
.should('exist') | ||
cy.get('.service-settings-pane') | ||
.find('a') | ||
.contains('Show revoked API keys') | ||
.should('exist') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('for a non-admin user', () => { | ||
beforeEach(() => { | ||
setupStubs('view-only') | ||
}) | ||
it('should return forbidden when visiting the url directly', () => { | ||
cy.request({ | ||
url: `/simplified/service/${SERVICE_EXTERNAL_ID}/account/${ACCOUNT_TYPE}/settings/api-keys`, | ||
failOnStatusCode: false | ||
}).then((response) => { | ||
expect(response.status).to.eq(403) | ||
}) | ||
}) | ||
|
||
it('should not show API keys link in the navigation panel', () => { | ||
cy.visit(`/simplified/service/${SERVICE_EXTERNAL_ID}/account/${ACCOUNT_TYPE}/settings`) | ||
cy.get('#api-keys').should('not.exist') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const { stubBuilder } = require('@test/cypress/stubs/stub-builder') | ||
|
||
/** | ||
* @param {number} gatewayAccountId | ||
* @param {[Token]} tokens | ||
*/ | ||
function getApiKeysForGatewayAccount (gatewayAccountId, tokens = []) { | ||
const path = `/v1/frontend/auth/${gatewayAccountId}` | ||
return stubBuilder('GET', path, 200, { | ||
response: { | ||
tokens: tokens.map(t => t.toJson()) | ||
} | ||
}) | ||
} | ||
|
||
module.exports = { | ||
getApiKeysForGatewayAccount | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably test for more than just these bits of text - it should test that the summary cards are shown with the correct content - this could be in a separate test though to aid readability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call - test added