Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oswaldquek committed Oct 11, 2024
1 parent a9445e2 commit 3757f01
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/controllers/dashboard/dashboard-activity.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,5 @@ async function getTelephonePaymentLinks (gatewayAccountId) {
}
return []
}

// module.exports = dashboardActivity
29 changes: 24 additions & 5 deletions app/controllers/dashboard/dashboard-activity.controller.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
'use strict'

const sinon = require('sinon')
const dashboardController = require('./dashboard-activity.controller')
const User = require('../../models/User.class')
const { validUser } = require('../../../test/fixtures/user.fixtures')
const { validGatewayAccountResponse } = require('../../../test/fixtures/gateway-account.fixtures')
const { ConnectorClient } = require('../../services/clients/connector.client')
const StripeClient = require('../../services/clients/stripe/stripe.client.js')
const { expect } = require('chai')
const proxyquire = require('proxyquire')
const gatewayAccountFixtures = require('../../../test/fixtures/gateway-account.fixtures')

describe('Controller: Dashboard activity', () => {
const externalServiceId = 'service-external-id'
Expand Down Expand Up @@ -55,11 +56,14 @@ describe('Controller: Dashboard activity', () => {
process.env.ENABLE_STRIPE_ONBOARDING_TASK_LIST = undefined
})

it(`should not call call the Connector client or the Stripe client`, async () => {
it(`should not call the Connector client or the Stripe client`, async () => {
accountSpy = sinon.stub(ConnectorClient.prototype, 'getStripeAccount')
stripeSpy = sinon.stub(StripeClient, 'retrieveAccountDetails')

await dashboardController(req, res)
const gatewayAccounts = gatewayAccountFixtures.validGatewayAccountsResponse(
{ accounts: serviceGatewayAccountIds.map(id => ({ gateway_account_id: id })) })
const controller = getControllerWithMocks(gatewayAccounts.accounts)
await controller(req, res)

sinon.assert.notCalled(accountSpy)
sinon.assert.notCalled(stripeSpy)
Expand All @@ -68,18 +72,33 @@ describe('Controller: Dashboard activity', () => {
it('should set enableStripeOnboardingTaskList to true when ENABLE_STRIPE_ONBOARDING_TASK_LIST is true', async () => {
process.env.ENABLE_STRIPE_ONBOARDING_TASK_LIST = 'true'

await dashboardController(req, res)
const gatewayAccounts = gatewayAccountFixtures.validGatewayAccountsResponse(
{ accounts: serviceGatewayAccountIds.map(id => ({ gateway_account_id: id })) })
const controller = getControllerWithMocks(gatewayAccounts.accounts)
await controller(req, res)

const pageData = res.render.args[0][1]
expect(pageData.enableStripeOnboardingTaskList).to.equal(true)
})

it('should set enableStripeOnboardingTaskList to false when ENABLE_STRIPE_ONBOARDING_TASK_LIST is false', async () => {
process.env.ENABLE_STRIPE_ONBOARDING_TASK_LIST = 'false'

await dashboardController(req, res)
const gatewayAccounts = gatewayAccountFixtures.validGatewayAccountsResponse(
{ accounts: serviceGatewayAccountIds.map(id => ({ gateway_account_id: id })) })
const controller = getControllerWithMocks(gatewayAccounts.accounts)
await controller(req, res)

const pageData = res.render.args[0][1]
expect(pageData.enableStripeOnboardingTaskList).to.equal(false)
})
})
})

function getControllerWithMocks (gatewayAccounts) {
return proxyquire('./dashboard-activity.controller', {
'../../services/service.service': {
getGatewayAccounts: sinon.spy(() => Promise.resolve(gatewayAccounts))
}
})
}
2 changes: 2 additions & 0 deletions app/services/clients/connector.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ ConnectorClient.prototype = {
getAccounts: async function (params) {
const url = `${this.connectorUrl}/v1/api/accounts?accountIds=` + encodeURIComponent(params.gatewayAccountIds.join(','))
configureClient(client, url)
console.log('here1')
const response = await client.get(url, 'get an account')
console.log('here2')
return response.data
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ const mockConnectorGetGatewayAccount = (paymentProvider, type) => {
}))
}

const mockConnectorGetGatewayAccounts = (paymentProvider, type) => {
nock(CONNECTOR_URL)
.get(`/v1/api/accounts?accountIds=${GATEWAY_ACCOUNT_EXTERNAL_ID}`)
.reply(200, gatewayAccountFixtures.validGatewayAccountsResponse({
accounts: [{
gateway_account_id: `${GATEWAY_ACCOUNT_ID}`,
type: type || 'test',
payment_provider: paymentProvider || 'sandbox',
external_id: `${GATEWAY_ACCOUNT_EXTERNAL_ID}`
}]
}))
}

const mockConnectorGetStripeSetup = (bankAccount, responsiblePerson, vatNumber, companyNumber, director, governmentEntitydocument) => {
nock(CONNECTOR_URL)
.get(`/v1/api/accounts/${GATEWAY_ACCOUNT_ID}/stripe-setup`)
Expand Down Expand Up @@ -103,6 +116,7 @@ describe('dashboard-activity-controller', () => {
}))

mockConnectorGetGatewayAccount()
mockConnectorGetGatewayAccounts()
mockConnectorGetStripeAccount()
mockStripeRetrieveAccount(true, null)

Expand Down Expand Up @@ -131,7 +145,7 @@ describe('dashboard-activity-controller', () => {
nock.cleanAll()
})

it('it should return a statusCode of 200', () => {
it.only('it should return a statusCode of 200', () => {
expect(result.statusCode).to.equal(200)
})

Expand Down

0 comments on commit 3757f01

Please sign in to comment.