Skip to content

Commit

Permalink
All cypress tests should pass now
Browse files Browse the repository at this point in the history
  • Loading branch information
oswaldquek committed Oct 10, 2024
1 parent 1f90124 commit a9445e2
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@
"filename": "test/fixtures/gateway-account.fixtures.js",
"hashed_secret": "e472e4dc23e4530d4fddeb6571b1c23447ab4c24",
"is_verified": false,
"line_number": 299
"line_number": 288
}
],
"test/fixtures/invite.fixtures.js": [
Expand Down Expand Up @@ -926,5 +926,5 @@
}
]
},
"generated_at": "2024-09-23T14:36:45Z"
"generated_at": "2024-10-10T11:35:32Z"
}
12 changes: 11 additions & 1 deletion app/controllers/dashboard/dashboard-activity.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const {
DENIED
} = require('../../models/go-live-stage')
const pspTestAccountStage = require('../../models/psp-test-account-stage')
const serviceService = require('../../services/service.service')

const links = {
demoPayment: 0,
Expand Down Expand Up @@ -97,11 +98,19 @@ const displayRequestTestStripeAccountLink = (service, account, user) => {
user.hasPermission(service.externalId, 'psp-test-account-stage:update')
}

async function isWorldpayTestService (gatewayAccountIds) {
const gatewayAccounts = await serviceService.getGatewayAccounts(gatewayAccountIds)
console.log(`returned gateway accounts: ${JSON.stringify(gatewayAccounts)}`)
return gatewayAccounts.length === 1 && gatewayAccounts[0].type === 'test' &&
gatewayAccounts[0].payment_provider.toUpperCase() === 'WORLDPAY'
}

module.exports = async (req, res) => {
const gatewayAccountId = req.account.gateway_account_id
const messages = res.locals.flash.messages
const period = _.get(req, 'query.period', 'today')
const telephonePaymentLink = await getTelephonePaymentLink(req.user, req.service, gatewayAccountId)
const worldpayTestService = await isWorldpayTestService(req.service.gatewayAccountIds)
const linksToDisplay = getLinksToDisplay(req.service, req.account, req.user, telephonePaymentLink)
const model = {
serviceId: req.service.externalId,
Expand All @@ -114,7 +123,8 @@ module.exports = async (req, res) => {
goLiveStarted: goLiveStartedStages.includes(req.service.currentGoLiveStage),
goLiveRequested: goLiveRequestedStages.includes(req.service.currentGoLiveStage),
gatewayAccount: req.account,
enableStripeOnboardingTaskList: process.env.ENABLE_STRIPE_ONBOARDING_TASK_LIST === 'true'
enableStripeOnboardingTaskList: process.env.ENABLE_STRIPE_ONBOARDING_TASK_LIST === 'true',
isWorldpayTestService: worldpayTestService
}

if (req.account.payment_provider === 'stripe' && req.account.type === 'live') {
Expand Down
2 changes: 1 addition & 1 deletion app/views/dashboard/_links.njk
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<h2 class="govuk-heading-s govuk-!-margin-bottom-2">Next steps to go live</h2>
<p class="govuk-body govuk-!-margin-bottom-0">Read our documentation to see how your service can go live with GOV.UK&nbsp;Pay.</p>
</a>
{% elif goLiveNotStarted %}
{% elif goLiveNotStarted and not isWorldpayTestService %}
<a href="{{formatServicePathsFor(routes.service.requestToGoLive.index, currentService.externalId)}}">
<h2 class="govuk-heading-s govuk-!-margin-bottom-2">Request a live account</h2>
<p class="govuk-body govuk-!-margin-bottom-0">To request a live account, tell us your organisation’s name, your payment service provider and agree to our terms and conditions. Once that’s done our team will email you.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ describe('The disabled account banner', () => {
cy.task('setupStubs', [
userStubs.getUserSuccess({ userExternalId, gatewayAccountId, gatewayAccountExternalId }),
gatewayAccountStubs.getGatewayAccountByExternalIdSuccess({ gatewayAccountId, gatewayAccountExternalId, type: 'live', paymentProvider: 'sandbox', gatewayAccountCredentials, disabled: true }),
transactionsSummaryStubs.getDashboardStatistics()
transactionsSummaryStubs.getDashboardStatistics(),
gatewayAccountStubs.getGatewayAccountsSuccess({ gatewayAccountId })
])
})

Expand Down
11 changes: 9 additions & 2 deletions test/cypress/integration/dashboard/dashboard-go-live-link.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ describe('Go live link on dashboard', () => {
})

describe('Go live link not shown', () => {
it('should not show Request a live account link when go-live stage is NOT_STARTED and account is a Worldpay test account', () => {
setupStubs('NOT_STARTED', 'worldpay')
cy.visit(dashboardUrl)

cy.get('#request-to-go-live-link').should('not.contain', 'Request a live account')
})

it('should not show request to go live link when go-live stage is LIVE', () => {
setupStubs('LIVE')
cy.visit(dashboardUrl)
Expand All @@ -99,9 +106,9 @@ describe('Go live link on dashboard', () => {
})
})

function setupStubs (goLiveStage) {
function setupStubs (goLiveStage, paymentProvider) {
cy.task('setupStubs', [
...utils.getUserAndGatewayAccountByExternalIdStubs(utils.buildServiceRoleForGoLiveStage(goLiveStage)),
...utils.getUserAndGatewayAccountByExternalIdStubs(utils.buildServiceRoleForGoLiveStage(goLiveStage), paymentProvider),
transactionStubs.getTransactionsSummarySuccess()
])
}
Expand Down
3 changes: 2 additions & 1 deletion test/cypress/integration/dashboard/dashboard-links.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ function getStubsForDashboard (gatewayAccountId, type, paymentProvider, goLiveSt
type,
paymentProvider
}),
transactionsSummaryStubs.getDashboardStatistics())
transactionsSummaryStubs.getDashboardStatistics(),
gatewayAccountStubs.getGatewayAccountsSuccess({ gatewayAccountId }))

if (paymentProvider === 'stripe') {
stubs.push(stripeAccountSetupStubs.getGatewayAccountStripeSetupSuccess({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('Account dashboard', () => {
cy.task('setupStubs', [
userStubs.getUserSuccess({ userExternalId, gatewayAccountId, serviceName }),
gatewayAccountStubs.getGatewayAccountByExternalIdSuccess({ gatewayAccountId, gatewayAccountExternalId }),
gatewayAccountStubs.getGatewayAccountsSuccess({ gatewayAccountId }),
todayStatisticsStub,
prevSevenDaysStatisticsStub
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ function setupYourPspStubs (opts = {}) {
const user = userStubs.getUserSuccess({ userExternalId, gatewayAccountId, gatewayAccountExternalId })

const stripeAccount = stripeAccountStubs.getStripeAccountSuccess(gatewayAccountId, 'stripe-account-id')
const gatewayAccountByExternalId = gatewayAccountStubs.getGatewayAccountByExternalIdSuccess({ gatewayAccountId, gatewayAccountExternalId, type: 'live', paymentProvider: 'stripe', gatewayAccountCredentials })
const gatewayAccountByExternalId = gatewayAccountStubs.getGatewayAccountByExternalIdSuccess(
{ gatewayAccountId, gatewayAccountExternalId, type: 'live', paymentProvider: 'stripe', gatewayAccountCredentials })
const gatewayAccounts = gatewayAccountStubs.getGatewayAccountsSuccess({ gatewayAccountId })
const transactionsSummary = transactionsSummaryStubs.getDashboardStatistics()
const gatewayAccountSucess = gatewayAccountStubs.getGatewayAccountSuccess({ gatewayAccountId, type: 'live', paymentProvider: 'stripe', gatewayAccountCredentials })
const gatewayAccountSucess = gatewayAccountStubs.getGatewayAccountSuccess(
{ gatewayAccountId, type: 'live', paymentProvider: 'stripe', gatewayAccountCredentials })
const stripeAccountSetup = stripeAccountSetupStubs.getGatewayAccountStripeSetupSuccess({
gatewayAccountId,
bankAccount: opts.bankAccount,
Expand All @@ -37,7 +40,8 @@ function setupYourPspStubs (opts = {}) {
current_deadline: opts.current_deadline
})

const stubs = [user, stripeAccount, gatewayAccountByExternalId, transactionsSummary, gatewayAccountSucess, stripeAccountSetup, stripeRestrictedAccountDetails]
const stubs = [user, stripeAccount, gatewayAccountByExternalId, transactionsSummary, gatewayAccountSucess,
stripeAccountSetup, stripeRestrictedAccountDetails, gatewayAccounts]
cy.task('setupStubs', stubs)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('Worldpay account setup banner', () => {
paymentProvider: 'worldpay',
gatewayAccountCredentials
}),
gatewayAccountStubs.getGatewayAccountsSuccess({ gatewayAccountId }),
transactionsSummaryStubs.getDashboardStatistics()
])
}
Expand Down
10 changes: 8 additions & 2 deletions test/cypress/utils/request-to-go-live-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,19 @@ function getUserAndGatewayAccountsStubs (serviceRole) {
]
}

function getUserAndGatewayAccountByExternalIdStubs (serviceRole) {
function getUserAndGatewayAccountByExternalIdStubs (serviceRole, paymentProvider, accountType) {
return [
userStubs.getUserSuccessWithServiceRole({ userExternalId: variables.userExternalId, serviceRole }),
gatewayAccountStubs.getGatewayAccountByExternalIdSuccess({
gatewayAccountId: variables.gatewayAccountId,
gatewayAccountExternalId: variables.gatewayAccountExternalId
})
}),
gatewayAccountStubs.getGatewayAccountsSuccess(
{
gatewayAccountId: variables.gatewayAccountId,
paymentProvider: paymentProvider || 'sandbox',
type: accountType || 'test'
})
]
}

Expand Down
12 changes: 0 additions & 12 deletions test/fixtures/gateway-account.fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,6 @@ function validGatewayAccountsResponse (opts = {}) {
}
}

function validDirectDebitGatewayAccountResponse (opts = {}) {
return {
gateway_account_id: opts.gateway_account_id || 73,
gateway_account_external_id: opts.gateway_account_external_id || 'DIRECT_DEBIT:' + 'a9c797ab271448bdba21359e15672076',
payment_provider: opts.payment_provider || 'sandbox',
type: opts.type || 'test',
analytics_id: opts.analytics_id || 'd82dae5bcb024828bb686574a932b5a5',
is_connected: opts.is_connected || false
}
}

function validCreateGatewayAccountRequest (opts = {}) {
const data = {
payment_provider: opts.payment_provider || 'sandbox',
Expand Down Expand Up @@ -420,7 +409,6 @@ module.exports = {
validGatewayAccountTokensResponse,
validGatewayAccountResponse,
validGatewayAccountsResponse,
validDirectDebitGatewayAccountResponse,
validCreateGatewayAccountRequest,
validUpdateGatewayAccountCredentialsRequest,
validGatewayAccountCredentialsResponse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ describe('dashboard-activity-controller', () => {
})
})
})

describe('When the dashboard is retrieved for a service that has requested to go live', () => {
let session

Expand Down

0 comments on commit a9445e2

Please sign in to comment.