mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: api tests time zone bug (resolve #355)
This commit is contained in:
parent
2173954b84
commit
a0f69a371f
@ -12,6 +12,7 @@ server:
|
|||||||
app:
|
app:
|
||||||
aggregation_time: '02:15'
|
aggregation_time: '02:15'
|
||||||
report_time_weekly: 'fri,18:00'
|
report_time_weekly: 'fri,18:00'
|
||||||
|
heartbeat_max_age: 87600h # 10 years
|
||||||
inactive_days: 7
|
inactive_days: 7
|
||||||
custom_languages:
|
custom_languages:
|
||||||
vue: Vue
|
vue: Vue
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"info": {
|
"info": {
|
||||||
"_postman_id": "43639725-0458-40d7-a4d4-9f55a539a7f7",
|
"_postman_id": "5c0749a5-6ddf-41ea-82f1-140578788bc3",
|
||||||
"name": "Wakapi API Tests",
|
"name": "Wakapi API Tests",
|
||||||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
|
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
|
||||||
},
|
},
|
||||||
@ -973,10 +973,9 @@
|
|||||||
"listen": "test",
|
"listen": "test",
|
||||||
"script": {
|
"script": {
|
||||||
"exec": [
|
"exec": [
|
||||||
"// 1640995199 Friday, 31 December 2021 11:59:59 PM (Jan 1st in +1, +2)",
|
"pm.test(\"Status code is 201\", function () {",
|
||||||
"// 1641074399 Saturday, 1 January 2022 9:59:59 PM (Jan 1st in +1, +2)",
|
" pm.response.to.have.status(201);",
|
||||||
"// 1641081599 Saturday, 1 January 2022 11:59:59 PM (Jan 2nd in +1, +2)",
|
"});"
|
||||||
""
|
|
||||||
],
|
],
|
||||||
"type": "text/javascript"
|
"type": "text/javascript"
|
||||||
}
|
}
|
||||||
@ -1331,8 +1330,8 @@
|
|||||||
"",
|
"",
|
||||||
"pm.test(\"Correct dates\", function () {",
|
"pm.test(\"Correct dates\", function () {",
|
||||||
" const jsonData = pm.response.json();",
|
" const jsonData = pm.response.json();",
|
||||||
" pm.expect(moment(jsonData.from).unix()).to.gte(moment(pm.variables.get('tsStartOfDayDate')).unix())",
|
" pm.expect(moment(jsonData.from).unix()).to.gte(moment(pm.variables.get('tsStartOfDayIso')).unix())",
|
||||||
" pm.expect(moment(jsonData.to).unix()).to.gte(moment(pm.variables.get('tsEndOfDayDate')).unix())",
|
" pm.expect(moment(jsonData.to).unix()).to.lte(moment(pm.variables.get('tsEndOfDayIso')).unix())",
|
||||||
"});",
|
"});",
|
||||||
""
|
""
|
||||||
],
|
],
|
||||||
@ -1358,7 +1357,7 @@
|
|||||||
"method": "GET",
|
"method": "GET",
|
||||||
"header": [],
|
"header": [],
|
||||||
"url": {
|
"url": {
|
||||||
"raw": "{{BASE_URL}}/api/summary?from={{tsStartOfDayDate}}&to={{tsEndOfTomorrowDate}}",
|
"raw": "{{BASE_URL}}/api/summary?from={{tsStartOfDayIso}}&to={{tsEndOfDayIso}}",
|
||||||
"host": [
|
"host": [
|
||||||
"{{BASE_URL}}"
|
"{{BASE_URL}}"
|
||||||
],
|
],
|
||||||
@ -1369,11 +1368,11 @@
|
|||||||
"query": [
|
"query": [
|
||||||
{
|
{
|
||||||
"key": "from",
|
"key": "from",
|
||||||
"value": "{{tsStartOfDayDate}}"
|
"value": "{{tsStartOfDayIso}}"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "to",
|
"key": "to",
|
||||||
"value": "{{tsEndOfTomorrowDate}}"
|
"value": "{{tsEndOfDayIso}}"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -3371,18 +3370,34 @@
|
|||||||
"exec": [
|
"exec": [
|
||||||
"const moment = require('moment')",
|
"const moment = require('moment')",
|
||||||
"",
|
"",
|
||||||
"const now = moment()",
|
"// pretend we're in Berlin, as this is also the time zone configured for the user",
|
||||||
"const startOfDay = moment().startOf('day')",
|
"const userZone = 'Europe/Berlin'",
|
||||||
"const endOfDay = moment().endOf('day')",
|
|
||||||
"const endOfTomorrow = moment().add(1, 'd').endOf('day')",
|
|
||||||
"",
|
"",
|
||||||
"console.log(`Current timestamp is: ${now.format('x') / 1000}`)",
|
"// postman doesn't have moment-timezone package included",
|
||||||
|
"// and we can't just use utcOffset(2), because of summer / winter time",
|
||||||
|
"// inspired by https://stackoverflow.com/a/56853085/3112139",
|
||||||
|
"function getUtcOffset(cb) {",
|
||||||
|
" let offset = pm.globals.get('utcOffset')",
|
||||||
|
" if (offset) return cb(offset)",
|
||||||
|
" pm.sendRequest(`https://worldtimeapi.org/api/timezone/${userZone}`, (err, res) => {",
|
||||||
|
" offset = res.json().utc_offset",
|
||||||
|
" pm.globals.set('utcOffset', offset)",
|
||||||
|
" return cb(offset)",
|
||||||
|
" })",
|
||||||
|
"}",
|
||||||
"",
|
"",
|
||||||
|
"getUtcOffset((utcOffset) => {",
|
||||||
|
" const now = moment().utcOffset(utcOffset)",
|
||||||
|
" const startOfDay = moment().utcOffset(utcOffset).startOf('day')",
|
||||||
|
" const endOfDay = moment().utcOffset(utcOffset).endOf('day')",
|
||||||
|
" const endOfTomorrow = moment().utcOffset(utcOffset).add(1, 'd').endOf('day')",
|
||||||
"",
|
"",
|
||||||
" // Auth stuff",
|
" // Auth stuff",
|
||||||
" const readApiKey = pm.variables.get('READUSER_API_KEY')",
|
" const readApiKey = pm.variables.get('READUSER_API_KEY')",
|
||||||
" const writeApiKey = pm.variables.get('WRITEUSER_API_KEY')",
|
" const writeApiKey = pm.variables.get('WRITEUSER_API_KEY')",
|
||||||
"",
|
"",
|
||||||
|
" console.log(readApiKey)",
|
||||||
|
"",
|
||||||
" if (!readApiKey || !writeApiKey) {",
|
" if (!readApiKey || !writeApiKey) {",
|
||||||
" throw new Error('no api key given')",
|
" throw new Error('no api key given')",
|
||||||
" }",
|
" }",
|
||||||
@ -3405,12 +3420,10 @@
|
|||||||
" pm.variables.set('tsStartOfDayIso', startOfDay.toISOString())",
|
" pm.variables.set('tsStartOfDayIso', startOfDay.toISOString())",
|
||||||
" pm.variables.set('tsEndOfDayIso', endOfDay.toISOString())",
|
" pm.variables.set('tsEndOfDayIso', endOfDay.toISOString())",
|
||||||
" pm.variables.set('tsEndOfTomorrowIso', endOfTomorrow.toISOString())",
|
" pm.variables.set('tsEndOfTomorrowIso', endOfTomorrow.toISOString())",
|
||||||
"pm.variables.set('tsStartOfDayDate', startOfDay.format('YYYY-MM-DD'))",
|
|
||||||
"pm.variables.set('tsEndOfDayDate', endOfDay.format('YYYY-MM-DD'))",
|
|
||||||
"pm.variables.set('tsEndOfTomorrowDate', endOfTomorrow.format('YYYY-MM-DD'))",
|
|
||||||
" pm.variables.set('ts1', now.startOf('hour').format('x') / 1000)",
|
" pm.variables.set('ts1', now.startOf('hour').format('x') / 1000)",
|
||||||
" pm.variables.set('ts2', now.startOf('hour').add(1, 'm').format('x') / 1000)",
|
" pm.variables.set('ts2', now.startOf('hour').add(1, 'm').format('x') / 1000)",
|
||||||
"pm.variables.set('ts3', now.startOf('hour').add(2, 'm').format('x') / 1000)"
|
" pm.variables.set('ts3', now.startOf('hour').add(2, 'm').format('x') / 1000)",
|
||||||
|
"})"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user