Skip to content

Commit 752220f

Browse files
committed
Corrected check and tests
1 parent ac6dc4f commit 752220f

2 files changed

Lines changed: 38 additions & 6 deletions

File tree

src/server/plugins/engine/components/PaymentField.test.ts

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ describe('PaymentField', () => {
422422
.mocked(get)
423423
// @ts-expect-error - partial mock
424424
.mockResolvedValueOnce({
425-
payload: { amount: 100, state: { status: 'success' } }
425+
payload: { amount: 10000, state: { status: 'success' } }
426426
})
427427
await paymentField.onSubmit(
428428
mockRequest,
@@ -449,7 +449,7 @@ describe('PaymentField', () => {
449449
.mocked(get)
450450
// @ts-expect-error - partial mock
451451
.mockResolvedValueOnce({
452-
payload: { amount: 100, state: { status: 'bad' } }
452+
payload: { amount: 10000, state: { status: 'bad' } }
453453
})
454454
const error = await paymentField
455455
.onSubmit(
@@ -482,7 +482,7 @@ describe('PaymentField', () => {
482482
.mocked(get)
483483
// @ts-expect-error - partial mock
484484
.mockResolvedValueOnce({
485-
payload: { amount: 100, state: { status: 'capturable' } }
485+
payload: { amount: 10000, state: { status: 'capturable' } }
486486
})
487487
// @ts-expect-error - partial mock
488488
jest.mocked(post).mockResolvedValueOnce({ res: { statusCode: 400 } })
@@ -517,7 +517,7 @@ describe('PaymentField', () => {
517517
.mocked(get)
518518
// @ts-expect-error - partial mock
519519
.mockResolvedValueOnce({
520-
payload: { amount: 50, state: { status: 'capturable' } }
520+
payload: { amount: 5000, state: { status: 'capturable' } }
521521
})
522522
// @ts-expect-error - partial mock
523523
jest.mocked(post).mockResolvedValueOnce({ res: { statusCode: 200 } })
@@ -552,7 +552,7 @@ describe('PaymentField', () => {
552552
.mocked(get)
553553
// @ts-expect-error - partial mock
554554
.mockResolvedValueOnce({
555-
payload: { amount: 100, state: { status: 'capturable' } }
555+
payload: { amount: 10000, state: { status: 'capturable' } }
556556
})
557557
// @ts-expect-error - partial mock
558558
jest.mocked(post).mockResolvedValueOnce({ res: { statusCode: 200 } })
@@ -575,5 +575,37 @@ describe('PaymentField', () => {
575575
expect(post).toHaveBeenCalled()
576576
})
577577
})
578+
579+
describe('getFormValue', () => {
580+
it('should return undefined', () => {
581+
expect(paymentField.getFormValue({})).toBeUndefined()
582+
})
583+
it('should return value', () => {
584+
const payment = {
585+
paymentId: 'payment-id',
586+
amount: 123,
587+
description: 'Payment desc',
588+
isLivePayment: false,
589+
formId: 'formid'
590+
}
591+
expect(paymentField.getFormValue(payment)).toEqual(payment)
592+
})
593+
})
594+
595+
describe('isState', () => {
596+
it('should return false if not valid state', () => {
597+
expect(paymentField.isState({})).toBe(false)
598+
})
599+
it('should return value', () => {
600+
const payment = {
601+
paymentId: 'payment-id',
602+
amount: 123,
603+
description: 'Payment desc',
604+
isLivePayment: false,
605+
formId: 'formid'
606+
}
607+
expect(paymentField.isState(payment)).toBe(true)
608+
})
609+
})
578610
})
579611
})

src/server/plugins/engine/pageControllers/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class PaymentSubmissionError extends Error {
6767
definitionAmount: number | undefined,
6868
component: FormComponent
6969
) {
70-
if (stateAmount !== definitionAmount) {
70+
if (stateAmount / 100 !== definitionAmount) {
7171
throw new PaymentPreAuthError(
7272
component,
7373
'The pre-authorised payment amount is somehow different from that requested. Try adding payment details again.',

0 commit comments

Comments
 (0)