Skip to content

Commit

Permalink
test(vnpay): ✅ add tests for vnp_ExpireDate
Browse files Browse the repository at this point in the history
  • Loading branch information
lehuygiang28 committed Aug 15, 2024
1 parent 86abeb9 commit ab8fae6
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions test/build-payment-url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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());

Expand All @@ -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 };
Expand Down

0 comments on commit ab8fae6

Please sign in to comment.