generated from DEFRA/ffc-template-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e34d4e
commit 6871df5
Showing
18 changed files
with
312 additions
and
6 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,4 +1,18 @@ | ||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. | ||
version: v1.22.0 | ||
ignore: {} | ||
version: v1.19.0 | ||
# ignores vulnerabilities until expiry date; change duration by modifying expiry date | ||
ignore: | ||
SNYK-JS-AXIOS-1579269: | ||
- '@azure/identity > axios': | ||
reason: no fix | ||
expires: '2021-10-02T17:50:04.275Z' | ||
- '@azure/identity > @azure/msal-node > axios': | ||
reason: no fix | ||
expires: '2021-10-02T17:50:04.276Z' | ||
- ffc-messaging > @azure/identity > axios: | ||
reason: No fix | ||
expires: '2021-10-02T17:50:04.276Z' | ||
- ffc-messaging > @azure/identity > @azure/msal-node > axios: | ||
reason: No fix | ||
expires: '2021-10-02T17:50:04.276Z' | ||
patch: {} |
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,4 +1,4 @@ | ||
ARG PARENT_VERSION=1.2.5-node14.16.1 | ||
ARG PARENT_VERSION=1.2.9-node14.17.6 | ||
ARG PORT_DEBUG=9229 | ||
ARG PORT=3008 | ||
|
||
|
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,9 @@ | ||
const db = require('./data') | ||
|
||
const updateAcknowledgement = async (acknowledgement) => { | ||
if (acknowledgement.success) { | ||
await db.completedPaymentRequest.update({ acknowledged: acknowledgement.acknowledged }, { where: { invoiceNumber: acknowledgement.invoiceNumber } }) | ||
} | ||
} | ||
|
||
module.exports = updateAcknowledgement |
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
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,13 @@ | ||
const updateAcknowledgement = require('../acknowledgement') | ||
|
||
const processAcknowledgementMessage = async (message, receiver) => { | ||
try { | ||
await updateAcknowledgement(message.body) | ||
await receiver.completeMessage(message) | ||
} catch (err) { | ||
console.error('Unable to process acknowledgement request:', err) | ||
await receiver.deadLetterMessage(message) | ||
} | ||
} | ||
|
||
module.exports = processAcknowledgementMessage |
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,13 @@ | ||
const updateSettlementStatus = require('../settlement') | ||
|
||
const processReturnMessage = async (message, receiver) => { | ||
try { | ||
await updateSettlementStatus(message.body) | ||
await receiver.completeMessage(message) | ||
} catch (err) { | ||
console.error('Unable to process return request:', err) | ||
await receiver.deadLetterMessage(message) | ||
} | ||
} | ||
|
||
module.exports = processReturnMessage |
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,9 @@ | ||
const db = require('./data') | ||
|
||
const updateSettlementStatus = async (returnData) => { | ||
if (returnData.settled) { | ||
await db.completedPaymentRequest.update({ settled: returnData.settlementDate }, { where: { invoiceNumber: returnData.invoiceNumber } }) | ||
} | ||
} | ||
|
||
module.exports = updateSettlementStatus |
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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
resources: | ||
topics: | ||
- name: payment | ||
- name: processing | ||
- name: acknowledgement | ||
- name: return |
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,56 @@ | ||
const db = require('../../../app/data') | ||
const updateAcknowledgement = require('../../../app/acknowledgement') | ||
let scheme | ||
let paymentRequest | ||
let acknowledgement | ||
|
||
describe('update settlement status', () => { | ||
beforeEach(async () => { | ||
await db.sequelize.truncate({ cascade: true }) | ||
|
||
scheme = { | ||
schemeId: 1, | ||
name: 'SFI', | ||
active: true | ||
} | ||
|
||
paymentRequest = { | ||
completedPaymentRequestId: 1, | ||
paymentRequestId: 1, | ||
schemeId: 1, | ||
frn: 1234567890, | ||
marketingYear: 2022, | ||
invoiceNumber: 'S12345678A123456V001' | ||
} | ||
|
||
acknowledgement = { | ||
invoiceNumber: 'S12345678A123456V001', | ||
acknowledged: new Date(2021, 8, 2), | ||
success: true | ||
} | ||
}) | ||
|
||
afterAll(async () => { | ||
await db.sequelize.truncate({ cascade: true }) | ||
await db.sequelize.close() | ||
}) | ||
|
||
test('should add acknowledged date if success', async () => { | ||
await db.scheme.create(scheme) | ||
await db.paymentRequest.create(paymentRequest) | ||
await db.completedPaymentRequest.create(paymentRequest) | ||
await updateAcknowledgement(acknowledgement) | ||
const updatedPaymentRequest = await db.completedPaymentRequest.findByPk(paymentRequest.paymentRequestId) | ||
expect(updatedPaymentRequest.acknowledged).toStrictEqual(new Date(2021, 8, 2)) | ||
}) | ||
|
||
test('should not add acknowledged date to failure', async () => { | ||
await db.scheme.create(scheme) | ||
await db.paymentRequest.create(paymentRequest) | ||
await db.completedPaymentRequest.create(paymentRequest) | ||
acknowledgement.success = false | ||
await updateAcknowledgement(acknowledgement) | ||
const updatedPaymentRequest = await db.completedPaymentRequest.findByPk(paymentRequest.paymentRequestId) | ||
expect(updatedPaymentRequest.acknowledged).toBeNull() | ||
}) | ||
}) |
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,56 @@ | ||
const db = require('../../../app/data') | ||
const updateSettlementStatus = require('../../../app/settlement') | ||
let scheme | ||
let paymentRequest | ||
let returnData | ||
|
||
describe('update settlement status', () => { | ||
beforeEach(async () => { | ||
await db.sequelize.truncate({ cascade: true }) | ||
|
||
scheme = { | ||
schemeId: 1, | ||
name: 'SFI', | ||
active: true | ||
} | ||
|
||
paymentRequest = { | ||
completedPaymentRequestId: 1, | ||
paymentRequestId: 1, | ||
schemeId: 1, | ||
frn: 1234567890, | ||
marketingYear: 2022, | ||
invoiceNumber: 'S12345678A123456V001' | ||
} | ||
|
||
returnData = { | ||
invoiceNumber: 'S12345678A123456V001', | ||
settled: true, | ||
settlementDate: new Date(2021, 8, 2) | ||
} | ||
}) | ||
|
||
afterAll(async () => { | ||
await db.sequelize.truncate({ cascade: true }) | ||
await db.sequelize.close() | ||
}) | ||
|
||
test('should add settlement date to settled', async () => { | ||
await db.scheme.create(scheme) | ||
await db.paymentRequest.create(paymentRequest) | ||
await db.completedPaymentRequest.create(paymentRequest) | ||
await updateSettlementStatus(returnData) | ||
const updatedPaymentRequest = await db.completedPaymentRequest.findByPk(paymentRequest.paymentRequestId) | ||
expect(updatedPaymentRequest.settled).toStrictEqual(new Date(2021, 8, 2)) | ||
}) | ||
|
||
test('should not add settlement date to unsettled', async () => { | ||
await db.scheme.create(scheme) | ||
await db.paymentRequest.create(paymentRequest) | ||
await db.completedPaymentRequest.create(paymentRequest) | ||
returnData.settled = false | ||
await updateSettlementStatus(returnData) | ||
const updatedPaymentRequest = await db.completedPaymentRequest.findByPk(paymentRequest.paymentRequestId) | ||
expect(updatedPaymentRequest.settled).toBeNull() | ||
}) | ||
}) |
42 changes: 42 additions & 0 deletions
42
test/unit/messaging/process-acknowledgement-message.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,42 @@ | ||
jest.mock('ffc-messaging') | ||
jest.mock('../../../app/data') | ||
jest.mock('../../../app/acknowledgement') | ||
const mockUpdateAcknowledgement = require('../../../app/acknowledgement') | ||
const processAcknowledgementMessage = require('../../../app/messaging/process-acknowledgement-message') | ||
let receiver | ||
|
||
describe('process acknowledgement message', () => { | ||
beforeEach(() => { | ||
receiver = { | ||
completeMessage: jest.fn(), | ||
deadLetterMessage: jest.fn() | ||
} | ||
}) | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
test('completes valid message', async () => { | ||
const message = { | ||
body: { | ||
frn: 1234567890 | ||
} | ||
} | ||
await processAcknowledgementMessage(message, receiver) | ||
expect(receiver.completeMessage).toHaveBeenCalledWith(message) | ||
}) | ||
|
||
test('dead letters invalid message', async () => { | ||
mockUpdateAcknowledgement.mockImplementation(() => { | ||
throw new Error() | ||
}) | ||
const message = { | ||
body: { | ||
frn: 1234567890 | ||
} | ||
} | ||
await processAcknowledgementMessage(message, receiver) | ||
expect(receiver.deadLetterMessage).toHaveBeenCalledWith(message) | ||
}) | ||
}) |
Oops, something went wrong.