Skip to content

Commit 51a82d8

Browse files
committed
use dynamic time value for time related api params
1 parent fc9a9bd commit 51a82d8

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

test/coreApi.test.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ function generateParamCardSubscription() {
483483
"interval": 1,
484484
"interval_unit": "month",
485485
"max_interval": 12,
486-
"start_time": "2021-11-30 07:25:01 +0700"
486+
"start_time": getFormattedTime(1000 * 60 * 60 * 24 * 2) // current time +2 days
487487
},
488488
"metadata": {
489489
"description": "Recurring payment for A"
@@ -611,12 +611,24 @@ function generateParamMax(){
611611
"finish": "https://demo.midtrans.com"
612612
},
613613
"expiry": {
614-
"start_time": ((new Date).getFullYear()+1)+"-12-20 18:11:08 +0700",
614+
"start_time": getFormattedTime(1000 * 60 * 60 * 24), // current time +24hrs
615615
"unit": "minutes",
616616
"duration": 1
617617
},
618618
"custom_field1": "custom field 1 content",
619619
"custom_field2": "custom field 2 content",
620620
"custom_field3": "custom field 3 content"
621621
}
622-
}
622+
}
623+
624+
function getFormattedTime(offsetInMilisecond = 0) {
625+
let targetDate = new Date(Date.now() + offsetInMilisecond);
626+
// formatted according to API param spec
627+
let formattedDateString = targetDate
628+
.toISOString()
629+
.split('T')
630+
.join(' ')
631+
.split('.')[0]
632+
+' +0000';
633+
return formattedDateString;
634+
}

test/snap.test.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,24 @@ function generateParamMax(){
316316
"finish": "https://demo.midtrans.com"
317317
},
318318
"expiry": {
319-
"start_time": ((new Date).getFullYear()+1)+"-12-20 18:11:08 +0700",
319+
"start_time": getFormattedTime(1000 * 60 * 60 * 24), // current time +24hrs
320320
"unit": "minutes",
321321
"duration": 1
322322
},
323323
"custom_field1": "custom field 1 content",
324324
"custom_field2": "custom field 2 content",
325325
"custom_field3": "custom field 3 content"
326326
}
327-
}
327+
}
328+
329+
function getFormattedTime(offsetInMilisecond = 0) {
330+
let targetDate = new Date(Date.now() + offsetInMilisecond);
331+
// formatted according to API param spec
332+
let formattedDateString = targetDate
333+
.toISOString()
334+
.split('T')
335+
.join(' ')
336+
.split('.')[0]
337+
+' +0000';
338+
return formattedDateString;
339+
}

0 commit comments

Comments
 (0)