diff --git a/app/controllers/simplified-account/settings/card-types/card-types.controller.js b/app/controllers/simplified-account/settings/card-types/card-types.controller.js index f579e6e1a..2b32d8fbc 100644 --- a/app/controllers/simplified-account/settings/card-types/card-types.controller.js +++ b/app/controllers/simplified-account/settings/card-types/card-types.controller.js @@ -5,9 +5,9 @@ const { formatSimplifiedAccountPathsFor } = require('@utils/simplified-account/f const paths = require('@root/paths') async function get (req, res, next) { - const serviceId = req.service.externalId + const serviceExternalId = req.service.externalId const accountType = req.account.type - const isAdminUser = req.user.isAdminUserForService(serviceId) + const isAdminUser = req.user.isAdminUserForService(serviceExternalId) const messages = res.locals?.flash?.messages ?? [] let noCardTypesSelectedError if (res.locals?.flash?.noCardTypesSelectedError) { @@ -15,7 +15,7 @@ async function get (req, res, next) { } try { const { card_types: allCards } = await getAllCardTypes() - const { card_types: acceptedCards } = await getAcceptedCardTypesForServiceAndAccountType(serviceId, accountType) + const { card_types: acceptedCards } = await getAcceptedCardTypesForServiceAndAccountType(serviceExternalId, accountType) const cardTypesSelected = noCardTypesSelectedError ? [] : acceptedCards const currentAcceptedCardTypeIds = acceptedCards.map(card => card.id) const cardTypes = formatCardTypesForTemplate(allCards, cardTypesSelected, req.account, isAdminUser) @@ -32,8 +32,7 @@ async function get (req, res, next) { } async function post (req, res, next) { - console.log(req.body) - const serviceId = req.service.externalId + const serviceExternalId = req.service.externalId const accountType = req.account.type const selectedDebitCards = (typeof req.body.debit === 'string' ? [req.body.debit] : req.body.debit) || [] const selectedCreditCards = (typeof req.body.credit === 'string' ? [req.body.credit] : req.body.credit) || [] @@ -41,7 +40,7 @@ async function post (req, res, next) { const currentAcceptedCardTypeIds = req.body.currentAcceptedCardTypeIds ? req.body.currentAcceptedCardTypeIds.split(',') : [] if (!selectedDebitCards.length && !selectedCreditCards.length) { req.flash('noCardTypesSelectedError', 'You must choose at least one card') - return res.redirect(formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.cardTypes.index, serviceId, accountType)) + return res.redirect(formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.cardTypes.index, serviceExternalId, accountType)) } const noChangesToAcceptedCardTypes = ( @@ -50,7 +49,7 @@ async function post (req, res, next) { ) if (noChangesToAcceptedCardTypes) { return res.redirect( - formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.cardTypes.index, serviceId, accountType) + formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.cardTypes.index, serviceExternalId, accountType) ) } @@ -58,10 +57,10 @@ async function post (req, res, next) { const payload = { card_types: selectedCardTypeIds } - await postAcceptedCardsForServiceAndAccountType(serviceId, accountType, payload) + await postAcceptedCardsForServiceAndAccountType(serviceExternalId, accountType, payload) req.flash('messages', { state: 'success', icon: '✓', heading: 'Accepted card types have been updated' }) return res.redirect( - formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.cardTypes.index, serviceId, accountType) + formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.cardTypes.index, serviceExternalId, accountType) ) } catch (err) { next(err) diff --git a/app/controllers/simplified-account/settings/card-types/card-types.controller.test.js b/app/controllers/simplified-account/settings/card-types/card-types.controller.test.js index 200bc7227..6939ccb7f 100644 --- a/app/controllers/simplified-account/settings/card-types/card-types.controller.test.js +++ b/app/controllers/simplified-account/settings/card-types/card-types.controller.test.js @@ -6,13 +6,13 @@ const userFixtures = require('@test/fixtures/user.fixtures') const paths = require('@root/paths') const ACCOUNT_TYPE = 'live' -const SERVICE_ID = 'service-id-123abc' +const SERVICE_EXTERNAL_ID = 'service-id-123abc' const adminUser = new User(userFixtures.validUserResponse({ external_id: 'user-id-for-admin-user', service_roles: { service: { - service: { external_id: SERVICE_ID }, + service: { external_id: SERVICE_EXTERNAL_ID }, role: { name: 'admin' } } } @@ -24,7 +24,7 @@ const viewOnlyUser = new User(userFixtures.validUserResponse( service_roles: { service: { - service: { external_id: SERVICE_ID }, + service: { external_id: SERVICE_EXTERNAL_ID }, role: { name: 'view-only' } } } @@ -59,7 +59,7 @@ const mockGetAcceptedCardTypesForServiceAndAccountType = sinon.stub().resolves({ const mockPostAcceptedCardsForServiceAndAccountType = sinon.stub().resolves({}) const { req, res, nextRequest, call } = new ControllerTestBuilder('@controllers/simplified-account/settings/card-types/card-types.controller') - .withServiceExternalId(SERVICE_ID) + .withServiceExternalId(SERVICE_EXTERNAL_ID) .withAccountType(ACCOUNT_TYPE) .withStubs({ '@utils/response': { response: mockResponse }, diff --git a/app/services/clients/connector.client.js b/app/services/clients/connector.client.js index 2eff2c979..8d17d95e7 100644 --- a/app/services/clients/connector.client.js +++ b/app/services/clients/connector.client.js @@ -258,14 +258,14 @@ ConnectorClient.prototype = { }, /** - * Retrieves the accepted card Types for the given external service external id and account type - * @param serviceId (required) - * @param accountType (required) + * Retrieves the accepted card Types for the given service external id and account type + * @param {String} serviceExternalId + * @param {String} accountType * @returns {Promise} */ - getAcceptedCardsForServiceAndAccountType: async function (serviceId, accountType) { - const url = `${this.connectorUrl}/v1/frontend/service/{serviceId}/account/{accountType}/card-types` - .replace('{serviceId}', encodeURIComponent(serviceId)) + getAcceptedCardsForServiceAndAccountType: async function (serviceExternalId, accountType) { + const url = `${this.connectorUrl}/v1/frontend/service/{serviceExternalId}/account/{accountType}/card-types` + .replace('{serviceExternalId}', encodeURIComponent(serviceExternalId)) .replace('{accountType}', encodeURIComponent(accountType)) configureClient(client, url) const response = await client.get(url, 'get accepted card types for account') @@ -287,15 +287,15 @@ ConnectorClient.prototype = { }, /** - * Updates the accepted card Types for to the given service and account type - * @param serviceId (required) - * @param accountType (required) - * @param payload (required) + * Updates the accepted card Types for the given service and account type + * @param {String} serviceExternalId + * @param {String} accountType + * @param {{card_types: string|string[]}} payload * @returns {Promise} */ - postAcceptedCardsForServiceAndAccountType: async function (serviceId, accountType, payload) { - const url = `${this.connectorUrl}/v1/frontend/service/{serviceId}/account/{accountType}/card-types` - .replace('{serviceId}', encodeURIComponent(serviceId)) + postAcceptedCardsForServiceAndAccountType: async function (serviceExternalId, accountType, payload) { + const url = `${this.connectorUrl}/v1/frontend/service/{serviceExternalId}/account/{accountType}/card-types` + .replace('{serviceExternalId}', encodeURIComponent(serviceExternalId)) .replace('{accountType}', encodeURIComponent(accountType)) configureClient(client, url) const response = await client.post(url, payload, 'post accepted card types for account') diff --git a/app/views/simplified-account/settings/card-types/cardTypesCheckboxes.njk b/app/views/simplified-account/settings/card-types/_card-types-checkboxes.njk similarity index 100% rename from app/views/simplified-account/settings/card-types/cardTypesCheckboxes.njk rename to app/views/simplified-account/settings/card-types/_card-types-checkboxes.njk diff --git a/app/views/simplified-account/settings/card-types/cardTypesList.njk b/app/views/simplified-account/settings/card-types/_card-types-list.njk similarity index 100% rename from app/views/simplified-account/settings/card-types/cardTypesList.njk rename to app/views/simplified-account/settings/card-types/_card-types-list.njk diff --git a/app/views/simplified-account/settings/card-types/index.njk b/app/views/simplified-account/settings/card-types/index.njk index 8934820d9..e9b19de41 100644 --- a/app/views/simplified-account/settings/card-types/index.njk +++ b/app/views/simplified-account/settings/card-types/index.njk @@ -23,9 +23,9 @@

Card types

{% if isAdminUser %} - {% include "./cardTypesCheckboxes.njk" %} + {% include "./_card-types-checkboxes.njk" %} {% else %} - {% include "./cardTypesList.njk" %} + {% include "./_card-types-list.njk" %} {% endif %} {% endblock %}