Skip to content

Commit

Permalink
Merge pull request #10 from xendit/9-null-date-bug
Browse files Browse the repository at this point in the history
[Resolves #9] VA null date bug
  • Loading branch information
stanleynguyen authored Nov 26, 2019
2 parents dac8591 + 031181f commit 861a513
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
8 changes: 0 additions & 8 deletions examples/va.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ va.getVABanks()
return r;
})
.then(banks => {
const expDate = new Date();
expDate.setDate(expDate.getDate() + 7);

return va.createFixedVA({
externalID: '123',
bankCode: banks[0].code,
name: 'Stanley Nguyen',
expirationDate: expDate,
});
})
.then(r => {
Expand All @@ -29,14 +25,10 @@ va.getVABanks()
return r;
})
.then(({ id }) => {
const expDate = new Date();
expDate.setMonth(expDate.getMonth() + 1);

return va.updateFixedVA({
id,
suggestedAmt: 20,
expectedAmt: 30,
expirationDate: expDate,
});
})
.then(r => {
Expand Down
2 changes: 1 addition & 1 deletion src/va/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function updateFixedVA(data) {
expected_amount: data.expectedAmt,
expiration_date: data.expirationDate
? data.expirationDate.toISOString()
: null,
: undefined,
is_single_use: data.isSingleUse,
description: data.description,
}),
Expand Down
23 changes: 22 additions & 1 deletion test/va/account.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,30 @@ module.exports = function(x) {
nock(x.opts.xenditURL)
.patch(`/callback_virtual_accounts/${TestConstants.VA_ID}`, {
expected_amount: TestConstants.EXPECTED_AMT,
expiration_date: null,
})
.reply(200, TestConstants.UPDATED_VA_DETAILS);
nock(x.opts.xenditURL)
.post('/callback_virtual_accounts', {
external_id: TestConstants.EXT_ID,
bank_code: TestConstants.BANK_CODE,
name: TestConstants.NAME,
expiration_date: null,
})
.reply(400, {
status: 400,
code: 'API_VALIDATION_ERROR',
message: 'There was an error with the format submitted to the server.',
});
nock(x.opts.xenditURL)
.patch(`/callback_virtual_accounts/${TestConstants.VA_ID}`, {
expected_amount: TestConstants.EXPECTED_AMT,
expiration_date: null,
})
.reply(400, {
status: 400,
code: 'API_VALIDATION_ERROR',
message: 'There was an error with the format submitted to the server.',
});
});

describe('createFixedVA', () => {
Expand Down

0 comments on commit 861a513

Please sign in to comment.