-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PP-13313: Worldpay details index page (#4365)
* PP-13313: Worldpay details index page This commit deals with a moto-enabled gateway account that hasn't configured the one_off_customer_initiated credentials yet.
- Loading branch information
1 parent
38c45cf
commit d1ab34b
Showing
10 changed files
with
186 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
module.exports.serviceName = require('./service-name/service-name.controller') | ||
module.exports.emailNotifications = require('./email-notifications/email-notifications.controller') | ||
module.exports.organisationDetails = require('./organisation-details/organisation-details.controller') | ||
module.exports.serviceName = require('./service-name/service-name.controller') | ||
module.exports.stripeDetails = require('./stripe-details/stripe-details.controller') | ||
module.exports.teamMembers = require('./team-members/team-members.controller') | ||
module.exports.organisationDetails = require('./organisation-details/organisation-details.controller') | ||
module.exports.cardTypes = require('./card-types/card-types.controller') | ||
module.exports.worldpayDetails = require('./worldpay-details/worldpay-details.controller') |
14 changes: 14 additions & 0 deletions
14
app/controllers/simplified-account/settings/worldpay-details/worldpay-details.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const { response } = require('@utils/response') | ||
const { WorldpayTasks } = require('@models/WorldpayTasks.class') | ||
|
||
function get (req, res) { | ||
const worldpayTasks = new WorldpayTasks(req.account) | ||
|
||
const context = { | ||
tasks: worldpayTasks.tasks, | ||
incompleteTasks: worldpayTasks.incompleteTasks | ||
} | ||
return response(req, res, 'simplified-account/settings/worldpay-details/index', context) | ||
} | ||
|
||
module.exports.get = get |
62 changes: 62 additions & 0 deletions
62
...trollers/simplified-account/settings/worldpay-details/worldpay-details.controller.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const ControllerTestBuilder = require('@test/test-helpers/simplified-account/controllers/ControllerTestBuilder.class') | ||
const sinon = require('sinon') | ||
const { expect } = require('chai') | ||
const Service = require('@models/Service.class') | ||
const GatewayAccount = require('@models/GatewayAccount.class') | ||
|
||
const mockResponse = sinon.spy() | ||
|
||
const ACCOUNT_TYPE = 'live' | ||
const SERVICE_ID = 'service-id-123abc' | ||
|
||
const { req, res, call } = new ControllerTestBuilder('@controllers/simplified-account/settings/worldpay-details/worldpay-details.controller') | ||
.withService(new Service({ | ||
external_id: SERVICE_ID | ||
})) | ||
.withAccountType(ACCOUNT_TYPE) | ||
.withAccount(new GatewayAccount({ | ||
type: ACCOUNT_TYPE, | ||
allow_moto: true, | ||
gateway_account_id: 1, | ||
gateway_account_credentials: [{ | ||
external_id: 'creds-id', | ||
payment_provider: 'worldpay', | ||
state: 'CREATED', | ||
created_date: '2024-11-29T11:58:36.214Z', | ||
gateway_account_id: 1, | ||
credentials: {} | ||
}] | ||
})) | ||
.withStubs({ | ||
'@utils/response': { response: mockResponse } | ||
}) | ||
.build() | ||
|
||
describe('Controller: settings/worldpay-details', () => { | ||
before(() => { | ||
call('get') | ||
}) | ||
|
||
describe('get', () => { | ||
it('should call the response method', () => { | ||
expect(mockResponse.called).to.be.true // eslint-disable-line | ||
}) | ||
|
||
it('should pass req, res and template path to the response method', () => { | ||
expect(mockResponse.args[0][0]).to.deep.equal(req) | ||
expect(mockResponse.args[0][1]).to.deep.equal(res) | ||
expect(mockResponse.args[0][2]).to.equal('simplified-account/settings/worldpay-details/index') | ||
}) | ||
|
||
it('should pass context data to the response method', () => { | ||
const tasks = [{ | ||
href: '#', | ||
id: 'worldpay-credentials', | ||
linkText: 'Link your Worldpay account with GOV.UK Pay', | ||
complete: false | ||
}] | ||
expect(mockResponse.args[0][3]).to.have.property('tasks').to.deep.equal(tasks) | ||
expect(mockResponse.args[0][3]).to.have.property('incompleteTasks').to.equal(true) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict' | ||
|
||
class WorldpayTasks { | ||
/** | ||
* @param {GatewayAccount} gatewayAccount | ||
*/ | ||
constructor (gatewayAccount) { | ||
this.tasks = [] | ||
this.incompleteTasks = true | ||
|
||
const credential = gatewayAccount.activeCredential | ||
|
||
if (gatewayAccount.allowMoto) { | ||
const worldpayCredentials = { | ||
href: '#', | ||
id: 'worldpay-credentials', | ||
linkText: 'Link your Worldpay account with GOV.UK Pay', | ||
complete: true | ||
} | ||
if (credential === null || credential.credentials.one_off_customer_initiated === null) { | ||
worldpayCredentials.complete = false | ||
} | ||
this.tasks.push(worldpayCredentials) | ||
} | ||
|
||
this.incompleteTasks = this.tasks.filter(t => t.complete === false).length > 0 | ||
} | ||
} | ||
|
||
module.exports = { WorldpayTasks } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
app/views/simplified-account/settings/worldpay-details/index.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{% extends "../settings-layout.njk" %} | ||
|
||
{% block settingsPageTitle %} | ||
Worldpay details | ||
{% endblock %} | ||
|
||
{% block settingsContent %} | ||
<h1 class="govuk-heading-l">Worldpay details</h1> | ||
|
||
{% if incompleteTasks %} | ||
<p class="govuk-body govuk-!-margin-bottom-6"> | ||
You need to link your Worldpay account to GOV.UK Pay. | ||
</p> | ||
|
||
{% set taskList = [] %} | ||
{% for task in tasks %} | ||
{% set taskList = (taskList.push({ | ||
title: { | ||
text: task.linkText | ||
}, | ||
href: task.href, | ||
status: { | ||
tag: { | ||
text: "Not yet started", | ||
classes: "govuk-tag--blue" | ||
} | ||
} if task.complete == false else ( | ||
{ | ||
tag: { | ||
text: "Completed", | ||
classes: "govuk-tag--grey" | ||
} | ||
} | ||
) | ||
}), taskList) %} | ||
{% endfor %} | ||
|
||
{{ govukTaskList({ | ||
idPrefix: "worldpay-tasks", | ||
items: taskList, | ||
classes: "task-list" | ||
}) }} | ||
|
||
{% endif %} | ||
|
||
{% endblock %} |