diff --git a/app/middleware/get-service-and-gateway-account.middleware.js b/app/middleware/get-service-and-gateway-account.middleware.js index 7c11ab8e12..63e641f707 100644 --- a/app/middleware/get-service-and-gateway-account.middleware.js +++ b/app/middleware/get-service-and-gateway-account.middleware.js @@ -90,7 +90,10 @@ module.exports = async function getServiceAndGatewayAccount (req, res, next) { req.account = gatewayAccount // TODO: To be removed once URLs are updated to use the format /service/:serviceExternalId/account/:gatewayAccountExternalId/xxx. // Currently authService.getCurrentGatewayAccountId() sets below if account is available on session or derives one from user services. - req.gateway_account = { currentGatewayAccountId: gatewayAccount.gateway_account_id, currentGatewayAccountExternalId: gatewayAccount.external_id } + req.gateway_account = { + currentGatewayAccountId: gatewayAccount.gateway_account_id && String(gatewayAccount.gateway_account_id), + currentGatewayAccountExternalId: gatewayAccount.external_id + } } } diff --git a/test/unit/middleware/get-service-and-gateway-account.middleware.test.js b/test/unit/middleware/get-service-and-gateway-account.middleware.test.js index 2c8f2d0891..6e174b4e6f 100644 --- a/test/unit/middleware/get-service-and-gateway-account.middleware.test.js +++ b/test/unit/middleware/get-service-and-gateway-account.middleware.test.js @@ -86,7 +86,7 @@ describe('middleware: getGatewayAccountAndService', () => { expect(req.service.externalId).to.equal('some-service-external-id') expect(req.service.hasCardGatewayAccount).to.equal(true) - expect(req.gateway_account.currentGatewayAccountId).to.equal(1) + expect(req.gateway_account.currentGatewayAccountId).to.equal('1') }) it('should error, if both gateway account external ID and service external ID cannot be resolved', async () => { const getGatewayAccountAndService = setupGetGatewayAccountAndService(1, 'some-gateway-external-id', 'worldpay', 'some-service-external-id')