From ab8fae6cbc2df07764a8034b38946268429eda93 Mon Sep 17 00:00:00 2001 From: lehuygiang28 Date: Thu, 15 Aug 2024 16:01:06 +0700 Subject: [PATCH] test(vnpay): :white_check_mark: add tests for `vnp_ExpireDate` --- test/build-payment-url.test.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/test/build-payment-url.test.ts b/test/build-payment-url.test.ts index c5d7d46..2c814fe 100644 --- a/test/build-payment-url.test.ts +++ b/test/build-payment-url.test.ts @@ -131,7 +131,7 @@ describe('buildPaymentUrl', () => { expect(result).toContain('vnp_BankCode=HSBC'); }); - it('should handle current date correctly', () => { + it('should handle current create date correctly', () => { const input: BuildPaymentUrl = { ...baseInput, vnp_CreateDate: 20210101070000, @@ -142,7 +142,7 @@ describe('buildPaymentUrl', () => { expect(result).toContain('vnp_CreateDate=20210101070000'); }); - it('should handle current date correctly when not provided', () => { + it('should handle current create date correctly when not provided', () => { const { vnp_CreateDate, ...input } = baseInput; const currentTime = dateFormat(getDateInGMT7()); @@ -151,6 +151,26 @@ describe('buildPaymentUrl', () => { expect(result).toContain(`vnp_CreateDate=${currentTime}`); }); + it('should handle expired date correctly', () => { + const input: BuildPaymentUrl = { + ...baseInput, + vnp_ExpireDate: 20210101070000, + }; + + const result = vnpay.buildPaymentUrl(input); + + expect(result).toContain('vnp_ExpireDate=20210101070000'); + }); + + it('should throw error when `vnp_ExpireDate` is not a valid date', () => { + const input: BuildPaymentUrl = { + ...baseInput, + vnp_ExpireDate: 1234567, + }; + + expect(() => vnpay.buildPaymentUrl(input)).toThrow(Error); + }); + it('should log the object to the console', () => { // Arrange const input: BuildPaymentUrl = { ...baseInput };