Skip to content

Commit

Permalink
[squash] remove unneeded label, add cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oswaldquek committed Jan 2, 2025
1 parent 77854fa commit 2209bae
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { response } = require('@utils/response')
const formatSimplifiedAccountPathsFor = require('@utils/simplified-account/format/format-simplified-account-paths-for')
const paths = require('@root/paths')
const { changeApiKeyName } = require('@services/api-keys.service')
const DESCRIPTION_VALIDATION = require('@controllers/simplified-account/settings/api-keys/validations')
const { validationResult } = require('express-validator')
const formatSimplifiedAccountPathsFor = require('@utils/simplified-account/format/format-simplified-account-paths-for')
const formatValidationErrors = require('@utils/simplified-account/format/format-validation-errors')
const { response } = require('@utils/response')
const { changeApiKeyName } = require('@services/api-keys.service')
const DESCRIPTION_VALIDATION = require('@controllers/simplified-account/settings/api-keys/validations')

function get (req, res) {
return response(req, res, 'simplified-account/settings/api-keys/api-key-name', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
maxlength: "50"
},
classes: "govuk-input--width-40",
label: {
text: "Add a description for the key"
},
hint: {
text: "For example, “John Smith’s API key”"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ describe('Settings - API keys', () => {
new Token().withCreatedBy('system generated').withDescription('description')
.withIssuedDate('12 Dec 2024').withTokenLink('token-link-1'),
new Token().withCreatedBy('algae bra').withDescription('mathematical clothes')
.withIssuedDate('10 Dec 2024').withLastUsed('10 Dec 2024').withTokenLink('token-link-1')
.withIssuedDate('10 Dec 2024').withLastUsed('10 Dec 2024').withTokenLink('token-link-2')
]

beforeEach(() => {
setupStubs('admin', apiKeys)
cy.visit(`/simplified/service/${SERVICE_EXTERNAL_ID}/account/${ACCOUNT_TYPE}/settings/api-keys`)
})

it('should show appropriate buttons and text', () => {
cy.get('#api-keys').should('have.text', 'Test API keys')
cy.get('.service-settings-pane')
Expand Down Expand Up @@ -166,6 +167,45 @@ describe('Settings - API keys', () => {
})
})
})

describe('re-name an api key', () => {
const NEW_API_KEY_NAME = 'api key description' // pragma: allowlist secret
const TOKEN_LINK = 'token-link-1'

const apiKeys = [
new Token().withCreatedBy('algae bra').withDescription('mathematical clothes')
.withIssuedDate('10 Dec 2024').withLastUsed('10 Dec 2024').withTokenLink(TOKEN_LINK)
]

beforeEach(() => {
setupStubs('admin', apiKeys)
cy.task('setupStubs', [
apiKeysStubs.changeApiKeyName(TOKEN_LINK, NEW_API_KEY_NAME)
])
cy.visit(`/simplified/service/${SERVICE_EXTERNAL_ID}/account/${ACCOUNT_TYPE}/settings/api-keys`)
})

it('show the API key name page', () => {
cy.get('.govuk-summary-card').within(() => {
cy.contains('h2', 'mathematical clothes').should('exist')
cy.contains('a', 'Change name').click()
})
cy.contains('h1', 'API key name').should('exist')
})

it('should re-name the api key successfully', () => {
cy.get('.govuk-summary-card').within(() => {
cy.contains('h2', 'mathematical clothes').should('exist')
cy.contains('a', 'Change name').click()
})
cy.get('input[id="description"]').type(NEW_API_KEY_NAME)
cy.contains('button', 'Continue').click()
cy.contains('h1', 'Test API keys').should('exist')
cy.get('.govuk-summary-card').within(() => {
cy.contains('h2', 'mathematical clothes').should('exist')
})
})
})
})

describe('for a non-admin user', () => {
Expand Down
11 changes: 11 additions & 0 deletions test/cypress/stubs/api-keys-stubs.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,18 @@ function createApiKey (gatewayAccountId, email, description, expectedToken) {
})
}

function changeApiKeyName (tokenLink, description) {
const path = '/v1/frontend/auth'
return stubBuilder('PUT', path, 200, {
request: {
token_link: tokenLink,
description
}
})
}

module.exports = {
changeApiKeyName,
createApiKey,
getApiKeysForGatewayAccount
}

0 comments on commit 2209bae

Please sign in to comment.