diff --git a/app/controllers/api-keys/post-create.controller.js b/app/controllers/api-keys/post-create.controller.js index 003c740f03..966c55af25 100644 --- a/app/controllers/api-keys/post-create.controller.js +++ b/app/controllers/api-keys/post-create.controller.js @@ -4,7 +4,7 @@ const { response } = require('../../utils/response.js') const publicAuthClient = require('../../services/clients/public-auth.client') const { isADirectDebitAccount } = require('../../services/clients/direct-debit-connector.client.js') -module.exports = async function createAPIKey (req, res, next) { +module.exports = async function createApiKey (req, res, next) { const accountId = req.account.gateway_account_id const correlationId = req.correlationId const description = req.body.description diff --git a/app/controllers/api-keys/post-revoke.controller.js b/app/controllers/api-keys/post-revoke.controller.js index a8f05419c5..d0afde5b59 100644 --- a/app/controllers/api-keys/post-revoke.controller.js +++ b/app/controllers/api-keys/post-revoke.controller.js @@ -3,8 +3,11 @@ const paths = require('../../paths') const publicAuthClient = require('../../services/clients/public-auth.client') const logger = require('../../utils/logger')(__filename) +const formatAccountPathsFor = require('../../utils/format-account-paths-for') + +module.exports = async function revokeApiKey (req, res) { + const apiKeysPath = formatAccountPathsFor(paths.account.apiKeys.index, req.account.external_id) -module.exports = async (req, res) => { const accountId = req.account.gateway_account_id const payload = { token_link: req.body.token_link @@ -16,10 +19,10 @@ module.exports = async (req, res) => { }) req.flash('generic', 'The API key was successfully revoked') - return res.redirect(paths.apiKeys.index) + return res.redirect(apiKeysPath) } catch (error) { logger.error('Error revoking API key', { error: error.message }) req.flash('genericError', 'Something went wrong. Please try again or contact support.') - return res.redirect(paths.apiKeys.index) + return res.redirect(apiKeysPath) } } diff --git a/app/controllers/api-keys/post-update.controller.js b/app/controllers/api-keys/post-update.controller.js index cc42567839..52b2832ca0 100644 --- a/app/controllers/api-keys/post-update.controller.js +++ b/app/controllers/api-keys/post-update.controller.js @@ -3,8 +3,11 @@ const paths = require('../../paths') const publicAuthClient = require('../../services/clients/public-auth.client') const logger = require('../../utils/logger')(__filename) +const formatAccountPathsFor = require('../../utils/format-account-paths-for') + +module.exports = async function updateApiKey (req, res) { + const apiKeysPath = formatAccountPathsFor(paths.account.apiKeys.index, req.account.external_id) -module.exports = (req, res) => { // this does not need to be explicitly tied down to account_id // right now because the UUID space is big enough that no-one // will be able to discover other peoples' tokens to change them @@ -13,17 +16,17 @@ module.exports = (req, res) => { description: req.body.description } - publicAuthClient.updateToken({ - payload: payload, - correlationId: req.correlationId - }) - .then(() => { - req.flash('generic', 'The API key description was successfully updated') - res.redirect(paths.apiKeys.index) - }) - .catch(error => { - logger.error('Error updating API key description', { error }) - req.flash('genericError', 'Something went wrong. Please try again or contact support.') - res.redirect(paths.apiKeys.index) + try { + await publicAuthClient.updateToken({ + payload: payload, + correlationId: req.correlationId }) + + req.flash('generic', 'The API key description was successfully updated') + res.redirect(apiKeysPath) + } catch (error) { + logger.error('Error updating API key description', { error }) + req.flash('genericError', 'Something went wrong. Please try again or contact support.') + res.redirect(apiKeysPath) + } } diff --git a/app/paths.js b/app/paths.js index df1aa7b8ab..05a29ed119 100644 --- a/app/paths.js +++ b/app/paths.js @@ -40,6 +40,13 @@ module.exports = { toggleMotoMaskCardNumberAndSecurityCode: { cardNumber: '/moto-hide-card-number', securityCode: '/moto-hide-security-code' + }, + apiKeys: { + index: '/api-keys', + revoked: '/api-keys/revoked', + create: '/api-keys/create', + revoke: '/api-keys/revoke', + update: '/api-keys/update' } }, transactions: { @@ -91,13 +98,6 @@ module.exports = { dashboard: { index: '/' }, - apiKeys: { - index: '/api-keys', - revoked: '/api-keys/revoked', - create: '/api-keys/create', - revoke: '/api-keys/revoke', - update: '/api-keys/update' - }, serviceSwitcher: { index: '/my-services', switch: '/my-services/switch', diff --git a/app/routes.js b/app/routes.js index 6353fdc6c9..3ae8f1ca50 100644 --- a/app/routes.js +++ b/app/routes.js @@ -87,12 +87,13 @@ const stripeSetupDashboardRedirectController = require('./controllers/stripe-set // Assignments const { healthcheck, registerUser, user, dashboard, selfCreateService, transactions, credentials, - apiKeys, serviceSwitcher, teamMembers, staticPaths, inviteValidation, editServiceName, merchantDetails, + serviceSwitcher, teamMembers, staticPaths, inviteValidation, editServiceName, merchantDetails, notificationCredentials, prototyping, paymentLinks, requestToGoLive, policyPages, stripeSetup, stripe, settings, yourPsp, allServiceTransactions, payouts } = paths const { + apiKeys, digitalWallet, emailNotifications, paymentTypes, @@ -236,12 +237,12 @@ module.exports.bind = function (app) { app.post(merchantDetails.edit, permission('merchant-details:update'), merchantDetailsController.postEdit) // API KEYS - app.get(apiKeys.index, permission('tokens-active:read'), getAccount, apiKeysController.getIndex) - app.get(apiKeys.revoked, permission('tokens-revoked:read'), getAccount, apiKeysController.getRevoked) - app.get(apiKeys.create, permission('tokens:create'), getAccount, apiKeysController.getCreate) - app.post(apiKeys.create, permission('tokens:create'), getAccount, apiKeysController.postCreate) - app.post(apiKeys.revoke, permission('tokens:delete'), getAccount, apiKeysController.postRevoke) - app.post(apiKeys.update, permission('tokens:update'), getAccount, apiKeysController.postUpdate) + account.get(apiKeys.index, permission('tokens-active:read'), apiKeysController.getIndex) + account.get(apiKeys.revoked, permission('tokens-revoked:read'), apiKeysController.getRevoked) + account.get(apiKeys.create, permission('tokens:create'), apiKeysController.getCreate) + account.post(apiKeys.create, permission('tokens:create'), apiKeysController.postCreate) + account.post(apiKeys.revoke, permission('tokens:delete'), apiKeysController.postRevoke) + account.post(apiKeys.update, permission('tokens:update'), apiKeysController.postUpdate) account.get(paymentTypes.index, permission('payment-types:read'), paymentTypesController.getIndex) account.post(paymentTypes.index, permission('payment-types:update'), paymentTypesController.postIndex) diff --git a/app/utils/nav-builder.js b/app/utils/nav-builder.js index 1585bdc507..26825278eb 100644 --- a/app/utils/nav-builder.js +++ b/app/utils/nav-builder.js @@ -49,11 +49,11 @@ const serviceNavigationItems = (currentPath, permissions, type) => { navigationItems.push({ id: 'navigation-menu-settings', name: 'Settings', - url: type === 'card' ? paths.settings.index : paths.apiKeys.index, + url: paths.settings.index, current: currentPath !== '/' ? pathLookup(currentPath, [ ...mainSettingsPaths, ...yourPspPaths, - paths.apiKeys, + paths.account.apiKeys, paths.account.paymentTypes ]) : false, permissions: _.some([ @@ -69,6 +69,8 @@ const serviceNavigationItems = (currentPath, permissions, type) => { } const adminNavigationItems = (currentPath, permissions, type, paymentProvider, account = {}) => { + const apiKeysPath = formatAccountPathsFor(paths.account.apiKeys.index, account.external_id) + return [ { id: 'navigation-menu-settings-home', @@ -80,8 +82,8 @@ const adminNavigationItems = (currentPath, permissions, type, paymentProvider, a { id: 'navigation-menu-api-keys', name: 'API keys', - url: paths.apiKeys.index, - current: pathLookup(currentPath, paths.apiKeys.index), + url: apiKeysPath, + current: pathLookup(currentPath, paths.account.apiKeys.index), permissions: permissions.tokens_update }, { diff --git a/app/views/api-keys/_key.njk b/app/views/api-keys/_key.njk index a63f366039..a527ada72e 100644 --- a/app/views/api-keys/_key.njk +++ b/app/views/api-keys/_key.njk @@ -37,7 +37,7 @@ {% endif %} {% if permissions.tokens_delete %} -
+
@@ -64,7 +64,7 @@ govuk-link--no-visited-state target-to-show--cancel" href="#main">Cancel {% endif %} {% if permissions.tokens_update %} -
+ {{ diff --git a/app/views/api-keys/_keys.njk b/app/views/api-keys/_keys.njk index 31cd670b5f..fb6e0d1726 100644 --- a/app/views/api-keys/_keys.njk +++ b/app/views/api-keys/_keys.njk @@ -11,17 +11,17 @@ {% if active %} - {% set apiKeyLinkRoute = routes.apiKeys.revoked %} + {% set apiKeyLinkRoute = routes.account.apiKeys.revoked %} {% set apiKeyLinkText = 'revoked' %} {% set apiKeyLinkId = 'revoked-keys-link' %} {% else %} - {% set apiKeyLinkRoute = routes.apiKeys.index %} + {% set apiKeyLinkRoute = routes.account.apiKeys.index %} {% set apiKeyLinkText = 'active' %} {% set apiKeyLinkId = 'active-keys-link' %} {% endif %} {% if permissions.tokens_create %} @@ -29,7 +29,7 @@ {{ govukButton({ text: "Create a new API key", - href: routes.apiKeys.create, + href: formatAccountPathsFor(routes.account.apiKeys.create, currentGatewayAccount.external_id), classes: "generate-key", attributes: { id: "create-api-key" diff --git a/app/views/api-keys/create.njk b/app/views/api-keys/create.njk index d691796a9c..bb3c108cb9 100644 --- a/app/views/api-keys/create.njk +++ b/app/views/api-keys/create.njk @@ -12,7 +12,7 @@ Create an API key - {{currentService.name}} {{currentGatewayAccount.full_type}}
{% if not token %}

Create an API key

- + {{ @@ -44,7 +44,7 @@ Create an API key - {{currentService.name}} {{currentGatewayAccount.full_type}} }}

- Cancel + Cancel

{% else %}

New API key

@@ -74,7 +74,7 @@ Create an API key - {{currentService.name}} {{currentGatewayAccount.full_type}}

- + Back to API keys

diff --git a/app/views/api-keys/update.njk b/app/views/api-keys/update.njk index b76002f245..a56b7fd31b 100644 --- a/app/views/api-keys/update.njk +++ b/app/views/api-keys/update.njk @@ -22,7 +22,7 @@ Create an API key - {{currentService.name}} {{currentGatewayAccount.full_type}} - + Cancel edits to {{token.description}}
diff --git a/test/ui/navigation.ui.test.js b/test/ui/navigation.ui.test.js index 3ee61b7e83..ea62766c61 100644 --- a/test/ui/navigation.ui.test.js +++ b/test/ui/navigation.ui.test.js @@ -1,5 +1,6 @@ const { render } = require('../test-helpers/html-assertions') const { serviceNavigationItems, adminNavigationItems } = require('../../app/utils/nav-builder') +const formatAccountPathsFor = require('../../app/utils/format-account-paths-for') describe('navigation menu', function () { it('should render only Home link when user does have any of the required permissions to show the navigation links', function () { @@ -15,7 +16,8 @@ describe('navigation menu', function () { hideServiceNav: false, serviceNavigationItems: serviceNavigationItems('/', testPermissions, 'card'), links: [], - linksToDisplay: [] + linksToDisplay: [], + formatAccountPathsFor: formatAccountPathsFor } const body = render('dashboard/index', templateData) @@ -72,7 +74,8 @@ describe('navigation menu', function () { const templateData = { permissions: testPermissions, showSettingsNav: true, - adminNavigationItems: adminNavigationItems('/api-keys', testPermissions, 'card', 'sandbox') + adminNavigationItems: adminNavigationItems('/api-keys', testPermissions, 'card', 'sandbox'), + formatAccountPathsFor: formatAccountPathsFor } const body = render('api-keys/index', templateData) @@ -93,7 +96,8 @@ describe('navigation menu', function () { const templateData = { permissions: testPermissions, showSettingsNav: true, - adminNavigationItems: adminNavigationItems('/api-keys', testPermissions, 'card', 'worldpay') + adminNavigationItems: adminNavigationItems('/api-keys', testPermissions, 'card', 'worldpay'), + formatAccountPathsFor: formatAccountPathsFor } const body = render('api-keys/index', templateData) @@ -114,7 +118,8 @@ describe('navigation menu', function () { const templateData = { permissions: testPermissions, showSettingsNav: true, - adminNavigationItems: adminNavigationItems('/api-keys', testPermissions, 'card', 'stripe') + adminNavigationItems: adminNavigationItems('/api-keys', testPermissions, 'card', 'stripe'), + formatAccountPathsFor: formatAccountPathsFor } const body = render('api-keys/index', templateData) @@ -135,7 +140,8 @@ describe('navigation menu', function () { const templateData = { permissions: testPermissions, showSettingsNav: true, - adminNavigationItems: adminNavigationItems('/api-keys', testPermissions, 'card', 'sandbox') + adminNavigationItems: adminNavigationItems('/api-keys', testPermissions, 'card', 'sandbox'), + formatAccountPathsFor: formatAccountPathsFor } const body = render('api-keys/index', templateData) @@ -155,7 +161,8 @@ describe('navigation menu', function () { const templateData = { permissions: testPermissions, showSettingsNav: true, - adminNavigationItems: adminNavigationItems('/api-keys', testPermissions, 'card', 'sandbox') + adminNavigationItems: adminNavigationItems('/api-keys', testPermissions, 'card', 'sandbox'), + formatAccountPathsFor: formatAccountPathsFor } const body = render('api-keys/index', templateData) @@ -178,7 +185,8 @@ describe('navigation menu', function () { const templateData = { permissions: testPermissions, showSettingsNav: true, - adminNavigationItems: adminNavigationItems('/api-keys', testPermissions, 'direct debit') + adminNavigationItems: adminNavigationItems('/api-keys', testPermissions, 'direct debit'), + formatAccountPathsFor: formatAccountPathsFor } const body = render('api-keys/index', templateData) @@ -206,7 +214,8 @@ describe('navigation menu', function () { const templateData = { permissions: testPermissions, showSettingsNav: true, - adminNavigationItems: adminNavigationItems('/api-keys', testPermissions, 'card', 'worldpay') + adminNavigationItems: adminNavigationItems('/api-keys', testPermissions, 'card', 'worldpay'), + formatAccountPathsFor: formatAccountPathsFor } const body = render('api-keys/index', templateData) diff --git a/test/unit/controller/api-keys/get-index.controller.ft.test.js b/test/unit/controller/api-keys/get-index.controller.ft.test.js index 4a0c7b6555..161d29349e 100644 --- a/test/unit/controller/api-keys/get-index.controller.ft.test.js +++ b/test/unit/controller/api-keys/get-index.controller.ft.test.js @@ -9,10 +9,14 @@ const mockSession = require('../../../test-helpers/mock-session') const userCreator = require('../../../test-helpers/user-creator') const paths = require('../../../../app/paths') const gatewayAccountFixtures = require('../../../fixtures/gateway-account.fixtures') +const formatAccountPathsFor = require('../../../../app/utils/format-account-paths-for') const { PUBLIC_AUTH_URL, CONNECTOR_URL } = process.env const GATEWAY_ACCOUNT_ID = '182364' +const EXTERNAL_GATEWAY_ACCOUNT_ID = 'an-external-id' + +const apiKeysIndexPath = formatAccountPathsFor(paths.account.apiKeys.index, EXTERNAL_GATEWAY_ACCOUNT_ID) const TOKEN_1 = { issued_date: '15 May 2018 - 09:13', @@ -53,7 +57,7 @@ describe('API keys index', () => { mockGetActiveAPIKeys(GATEWAY_ACCOUNT_ID).reply(200, []) supertest(app) - .get(paths.apiKeys.index) + .get(apiKeysIndexPath) .set('Accept', 'application/json') .end((err, res) => { response = res @@ -80,7 +84,7 @@ describe('API keys index', () => { mockGetActiveAPIKeys(GATEWAY_ACCOUNT_ID).reply(200, { tokens: [TOKEN_1] }) supertest(app) - .get(paths.apiKeys.index) + .get(apiKeysIndexPath) .set('Accept', 'application/json') .end((err, res) => { response = res @@ -112,7 +116,7 @@ describe('API keys index', () => { mockGetActiveAPIKeys(GATEWAY_ACCOUNT_ID).reply(200, { tokens: [TOKEN_1, TOKEN_2] }) supertest(app) - .get(paths.apiKeys.index) + .get(apiKeysIndexPath) .set('Accept', 'application/json') .end((err, res) => { response = res @@ -139,8 +143,11 @@ describe('API keys index', () => { }) function mockConnectorGetAccount () { - nock(CONNECTOR_URL).get(`/v1/frontend/accounts/${GATEWAY_ACCOUNT_ID}`) - .reply(200, gatewayAccountFixtures.validGatewayAccountResponse({ - gateway_account_id: GATEWAY_ACCOUNT_ID - })) + nock(CONNECTOR_URL).get(`/v1/api/accounts/external-id/${EXTERNAL_GATEWAY_ACCOUNT_ID}`) + .reply(200, gatewayAccountFixtures.validGatewayAccountResponse( + { + external_id: EXTERNAL_GATEWAY_ACCOUNT_ID, + gateway_account_id: GATEWAY_ACCOUNT_ID + } + )) } diff --git a/test/unit/controller/api-keys/get-revoked.controller.ft.test.js b/test/unit/controller/api-keys/get-revoked.controller.ft.test.js index 01e1b51d0f..fcceb5c2ff 100644 --- a/test/unit/controller/api-keys/get-revoked.controller.ft.test.js +++ b/test/unit/controller/api-keys/get-revoked.controller.ft.test.js @@ -9,10 +9,14 @@ const mockSession = require('../../../test-helpers/mock-session') const userCreator = require('../../../test-helpers/user-creator') const paths = require('../../../../app/paths') const gatewayAccountFixtures = require('../../../fixtures/gateway-account.fixtures') +const formatAccountPathsFor = require('../../../../app/utils/format-account-paths-for') const { PUBLIC_AUTH_URL, CONNECTOR_URL } = process.env const GATEWAY_ACCOUNT_ID = '182364' +const EXTERNAL_GATEWAY_ACCOUNT_ID = 'an-external-id' + +const apiKeysRevokedIndexPath = formatAccountPathsFor(paths.account.apiKeys.revoked, EXTERNAL_GATEWAY_ACCOUNT_ID) const TOKEN_1 = { issued_date: '14 May 2018 - 15:33', @@ -39,10 +43,13 @@ const mockGetRevokedAPIKeys = gatewayAccountId => { } function mockConnectorGetAccount () { - nock(CONNECTOR_URL).get(`/v1/frontend/accounts/${GATEWAY_ACCOUNT_ID}`) - .reply(200, gatewayAccountFixtures.validGatewayAccountResponse({ - gateway_account_id: GATEWAY_ACCOUNT_ID - })) + nock(CONNECTOR_URL).get(`/v1/api/accounts/external-id/${EXTERNAL_GATEWAY_ACCOUNT_ID}`) + .reply(200, gatewayAccountFixtures.validGatewayAccountResponse( + { + external_id: EXTERNAL_GATEWAY_ACCOUNT_ID, + gateway_account_id: GATEWAY_ACCOUNT_ID + } + )) } describe('Revoked API keys index', () => { @@ -62,7 +69,7 @@ describe('Revoked API keys index', () => { mockGetRevokedAPIKeys(GATEWAY_ACCOUNT_ID).reply(200, []) supertest(app) - .get(paths.apiKeys.revoked) + .get(apiKeysRevokedIndexPath) .set('Accept', 'application/json') .end((err, res) => { response = res @@ -89,7 +96,7 @@ describe('Revoked API keys index', () => { mockGetRevokedAPIKeys(GATEWAY_ACCOUNT_ID).reply(200, { tokens: [TOKEN_1] }) supertest(app) - .get(paths.apiKeys.revoked) + .get(apiKeysRevokedIndexPath) .set('Accept', 'application/json') .end((err, res) => { response = res @@ -121,7 +128,7 @@ describe('Revoked API keys index', () => { mockGetRevokedAPIKeys(GATEWAY_ACCOUNT_ID).reply(200, { tokens: [TOKEN_1, TOKEN_2] }) supertest(app) - .get(paths.apiKeys.revoked) + .get(apiKeysRevokedIndexPath) .set('Accept', 'application/json') .end((err, res) => { response = res diff --git a/test/unit/controller/api-keys/post-create.controller.ft.test.js b/test/unit/controller/api-keys/post-create.controller.ft.test.js index 149c491118..c17ac061d4 100644 --- a/test/unit/controller/api-keys/post-create.controller.ft.test.js +++ b/test/unit/controller/api-keys/post-create.controller.ft.test.js @@ -9,7 +9,8 @@ const { getApp } = require('../../../../server') const mockSession = require('../../../test-helpers/mock-session') const userCreator = require('../../../test-helpers/user-creator') const paths = require('../../../../app/paths') -const gatewayAccountFixtures = require('../../../fixtures/gateway-account.fixtures') +const formatAccountPathsFor = require('../../../../app/utils/format-account-paths-for') +const { validGatewayAccountResponse } = require('../../../fixtures/gateway-account.fixtures') const { PUBLIC_AUTH_URL, CONNECTOR_URL } = process.env const GATEWAY_ACCOUNT_ID = '182364' @@ -23,12 +24,18 @@ const VALID_PAYLOAD = { 'description': '' } +const EXTERNAL_GATEWAY_ACCOUNT_ID = 'an-external-id' +const apiKeyCreatePath = formatAccountPathsFor(paths.account.apiKeys.create, EXTERNAL_GATEWAY_ACCOUNT_ID) + function mockConnectorGetAccount (type) { - nock(CONNECTOR_URL).get(`/v1/frontend/accounts/${GATEWAY_ACCOUNT_ID}`) - .reply(200, gatewayAccountFixtures.validGatewayAccountResponse({ - gateway_account_id: GATEWAY_ACCOUNT_ID, - type - })) + nock(CONNECTOR_URL).get(`/v1/api/accounts/external-id/${EXTERNAL_GATEWAY_ACCOUNT_ID}`) + .reply(200, validGatewayAccountResponse( + { + external_id: EXTERNAL_GATEWAY_ACCOUNT_ID, + gateway_account_id: GATEWAY_ACCOUNT_ID, + type + } + )) } describe('POST to create an API key', () => { @@ -56,7 +63,7 @@ describe('POST to create an API key', () => { .reply(200, TOKEN_RESPONSE) supertest(app) - .post(paths.apiKeys.create) + .post(apiKeyCreatePath) .set('Accept', 'application/json') .set('x-request-id', REQUEST_ID) .send(VALID_PAYLOAD) @@ -104,7 +111,7 @@ describe('POST to create an API key', () => { VALID_PAYLOAD.description = DESCRIPTION supertest(app) - .post(paths.apiKeys.create) + .post(apiKeyCreatePath) .set('Accept', 'application/json') .set('x-request-id', REQUEST_ID) .send(VALID_PAYLOAD) diff --git a/test/unit/controller/api-keys/post-revoke.controller.ft.test.js b/test/unit/controller/api-keys/post-revoke.controller.ft.test.js index 030f636e24..c5b1731715 100644 --- a/test/unit/controller/api-keys/post-revoke.controller.ft.test.js +++ b/test/unit/controller/api-keys/post-revoke.controller.ft.test.js @@ -9,7 +9,8 @@ const { getApp } = require('../../../../server') const mockSession = require('../../../test-helpers/mock-session') const userCreator = require('../../../test-helpers/user-creator') const paths = require('../../../../app/paths') -const gatewayAccountFixtures = require('../../../fixtures/gateway-account.fixtures') +const { validGatewayAccountResponse } = require('../../../fixtures/gateway-account.fixtures') +const formatAccountPathsFor = require('../../../../app/utils/format-account-paths-for') const { PUBLIC_AUTH_URL, CONNECTOR_URL } = process.env const GATEWAY_ACCOUNT_ID = '182364' @@ -22,6 +23,9 @@ const VALID_PAYLOAD = { token_link: '398763986398739673' } +const EXTERNAL_GATEWAY_ACCOUNT_ID = 'an-external-id' +const apiKeyRevokePath = formatAccountPathsFor(paths.account.apiKeys.revoke, EXTERNAL_GATEWAY_ACCOUNT_ID) + describe('POST to revoke an API key', () => { let app let response @@ -41,11 +45,11 @@ describe('POST to revoke an API key', () => { ) .reply(200, TOKEN_RESPONSE) - nock(CONNECTOR_URL).get(`/v1/frontend/accounts/${GATEWAY_ACCOUNT_ID}`) - .reply(200, gatewayAccountFixtures.validGatewayAccountResponse({ gateway_account_id: GATEWAY_ACCOUNT_ID })) + nock(CONNECTOR_URL).get(`/v1/api/accounts/external-id/${EXTERNAL_GATEWAY_ACCOUNT_ID}`) + .reply(200, validGatewayAccountResponse({ external_id: EXTERNAL_GATEWAY_ACCOUNT_ID, gateway_account_id: GATEWAY_ACCOUNT_ID })) supertest(app) - .post(paths.apiKeys.revoke) + .post(apiKeyRevokePath) .set('Accept', 'application/json') .set('Content-Type', 'application/x-www-form-urlencoded') .set('x-request-id', REQUEST_ID) @@ -62,7 +66,7 @@ describe('POST to revoke an API key', () => { it('should redirect back to index', () => { expect(response.statusCode).to.equal(302) - expect(response.headers).to.have.property('location').to.equal(paths.apiKeys.index) + expect(response.headers).to.have.property('location').to.equal(formatAccountPathsFor(paths.account.apiKeys.index, EXTERNAL_GATEWAY_ACCOUNT_ID)) }) it('should have success message', () => { diff --git a/test/unit/controller/api-keys/post-update.controller.ft.test.js b/test/unit/controller/api-keys/post-update.controller.ft.test.js index 499ca3b91c..49cd555196 100644 --- a/test/unit/controller/api-keys/post-update.controller.ft.test.js +++ b/test/unit/controller/api-keys/post-update.controller.ft.test.js @@ -9,6 +9,8 @@ const { getApp } = require('../../../../server') const mockSession = require('../../../test-helpers/mock-session') const userCreator = require('../../../test-helpers/user-creator') const paths = require('../../../../app/paths') +const formatAccountPathsFor = require('../../../../app/utils/format-account-paths-for') +const { validGatewayAccountResponse } = require('../../../fixtures/gateway-account.fixtures') const { PUBLIC_AUTH_URL, CONNECTOR_URL } = process.env const GATEWAY_ACCOUNT_ID = '182364' @@ -23,6 +25,9 @@ const VALID_PAYLOAD = { description: DESCRIPTION } +const EXTERNAL_GATEWAY_ACCOUNT_ID = 'an-external-id' +const apiKeyUpdatePath = formatAccountPathsFor(paths.account.apiKeys.update, EXTERNAL_GATEWAY_ACCOUNT_ID) + describe('POST to update an API key description', () => { let app let response @@ -43,13 +48,11 @@ describe('POST to update an API key description', () => { ) .reply(200, TOKEN_RESPONSE) - nock(CONNECTOR_URL).get(`/v1/frontend/accounts/${GATEWAY_ACCOUNT_ID}`) - .reply(200, { - payment_provider: 'sandbox' - }) + nock(CONNECTOR_URL).get(`/v1/api/accounts/external-id/${EXTERNAL_GATEWAY_ACCOUNT_ID}`) + .reply(200, validGatewayAccountResponse({ external_id: EXTERNAL_GATEWAY_ACCOUNT_ID, gateway_account_id: GATEWAY_ACCOUNT_ID })) supertest(app) - .post(paths.apiKeys.update) + .post(apiKeyUpdatePath) .set('Accept', 'application/json') .set('Content-Type', 'application/x-www-form-urlencoded') .set('x-request-id', REQUEST_ID) @@ -66,7 +69,7 @@ describe('POST to update an API key description', () => { it('should redirect back to index', () => { expect(response.statusCode).to.equal(302) - expect(response.headers).to.have.property('location').to.equal(paths.apiKeys.index) + expect(response.headers).to.have.property('location').to.equal(formatAccountPathsFor(paths.account.apiKeys.index, EXTERNAL_GATEWAY_ACCOUNT_ID)) }) it('should have success message', () => {