mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
test: remove api call for timezone
This commit is contained in:
parent
0160a9ae52
commit
71563c2c33
@ -3370,57 +3370,53 @@
|
|||||||
"// pretend we're in Berlin, as this is also the time zone configured for the user",
|
"// pretend we're in Berlin, as this is also the time zone configured for the user",
|
||||||
"const userZone = 'Europe/Berlin'",
|
"const userZone = 'Europe/Berlin'",
|
||||||
"",
|
"",
|
||||||
"// postman doesn't have moment-timezone package included",
|
"// https://stackoverflow.com/a/63199512",
|
||||||
"// and we can't just use utcOffset(2), because of summer / winter time",
|
"// return UTC offset of timezone in minutes",
|
||||||
"// inspired by https://stackoverflow.com/a/56853085/3112139",
|
"function getTimezoneOffset(timeZone, date = new Date()) {",
|
||||||
"function getUtcOffset(cb) {",
|
" const tz = date.toLocaleString(\"en\", {timeZone, timeStyle: \"long\"}).split(\" \").slice(-1)[0];",
|
||||||
" let offset = pm.globals.get('utcOffset')",
|
" const dateString = date.toString();",
|
||||||
" if (offset) return cb(offset)",
|
" const offset = Date.parse(`${dateString} UTC`) - Date.parse(`${dateString} ${tz}`);",
|
||||||
" pm.sendRequest(`https://worldtimeapi.org/api/timezone/${userZone}`, (err, res) => {",
|
" return offset / 1000 / 60;",
|
||||||
" offset = res.json().utc_offset",
|
|
||||||
" pm.globals.set('utcOffset', offset)",
|
|
||||||
" return cb(offset)",
|
|
||||||
" })",
|
|
||||||
"}",
|
"}",
|
||||||
"",
|
"",
|
||||||
"getUtcOffset((utcOffset) => {",
|
"const utcOffset = getTimezoneOffset(userZone);",
|
||||||
" const now = moment().utcOffset(utcOffset)",
|
|
||||||
" const startOfDay = now.clone().startOf('day')",
|
|
||||||
" const endOfDay = now.clone().endOf('day')",
|
|
||||||
" const endOfTomorrow = now.clone().add(1, 'd').endOf('day')",
|
|
||||||
"",
|
"",
|
||||||
" // Auth stuff",
|
"const now = moment().utcOffset(utcOffset)",
|
||||||
" const readApiKey = pm.variables.get('READUSER_API_KEY')",
|
"const startOfDay = now.clone().startOf('day')",
|
||||||
" const writeApiKey = pm.variables.get('WRITEUSER_API_KEY')",
|
"const endOfDay = now.clone().endOf('day')",
|
||||||
|
"const endOfTomorrow = now.clone().add(1, 'd').endOf('day')",
|
||||||
"",
|
"",
|
||||||
" console.log(readApiKey)",
|
"// Auth stuff",
|
||||||
|
"const readApiKey = pm.variables.get('READUSER_API_KEY')",
|
||||||
|
"const writeApiKey = pm.variables.get('WRITEUSER_API_KEY')",
|
||||||
"",
|
"",
|
||||||
" if (!readApiKey || !writeApiKey) {",
|
"console.log(readApiKey)",
|
||||||
" throw new Error('no api key given')",
|
|
||||||
" }",
|
|
||||||
"",
|
"",
|
||||||
" pm.variables.set('READUSER_TOKEN', base64encode(readApiKey))",
|
"if (!readApiKey || !writeApiKey) {",
|
||||||
" pm.variables.set('WRITEUSER_TOKEN', base64encode(writeApiKey))",
|
" throw new Error('no api key given')",
|
||||||
|
"}",
|
||||||
"",
|
"",
|
||||||
" function base64encode(str) {",
|
"pm.variables.set('READUSER_TOKEN', base64encode(readApiKey))",
|
||||||
" return Buffer.from(str, 'utf-8').toString('base64')",
|
"pm.variables.set('WRITEUSER_TOKEN', base64encode(writeApiKey))",
|
||||||
" }",
|
|
||||||
"",
|
"",
|
||||||
" // Heartbeat stuff",
|
"function base64encode(str) {",
|
||||||
" pm.variables.set('tsNow', now.clone().format('x') / 1000)",
|
" return Buffer.from(str, 'utf-8').toString('base64')",
|
||||||
" pm.variables.set('tsNowMinus1Min', now.clone().add(-1, 'm').format('x') / 1000)",
|
"}",
|
||||||
" pm.variables.set('tsNowMinus2Min', now.clone().add(-2, 'm').format('x') / 1000)",
|
"",
|
||||||
" pm.variables.set('tsNowMinus3Min', now.clone().add(-3, 'm').format('x') / 1000)",
|
"// Heartbeat stuff",
|
||||||
" pm.variables.set('tsStartOfDay', startOfDay.format('x') / 1000)",
|
"pm.variables.set('tsNow', now.clone().format('x') / 1000)",
|
||||||
" pm.variables.set('tsEndOfDay', endOfDay.format('x') / 1000)",
|
"pm.variables.set('tsNowMinus1Min', now.clone().add(-1, 'm').format('x') / 1000)",
|
||||||
" pm.variables.set('tsEndOfTomorrow', endOfTomorrow.format('x') / 1000)",
|
"pm.variables.set('tsNowMinus2Min', now.clone().add(-2, 'm').format('x') / 1000)",
|
||||||
" pm.variables.set('tsStartOfDayIso', startOfDay.toISOString())",
|
"pm.variables.set('tsNowMinus3Min', now.clone().add(-3, 'm').format('x') / 1000)",
|
||||||
" pm.variables.set('tsEndOfDayIso', endOfDay.toISOString())",
|
"pm.variables.set('tsStartOfDay', startOfDay.format('x') / 1000)",
|
||||||
" pm.variables.set('tsEndOfTomorrowIso', endOfTomorrow.toISOString())",
|
"pm.variables.set('tsEndOfDay', endOfDay.format('x') / 1000)",
|
||||||
" pm.variables.set('ts1', now.clone().startOf('hour').format('x') / 1000)",
|
"pm.variables.set('tsEndOfTomorrow', endOfTomorrow.format('x') / 1000)",
|
||||||
" pm.variables.set('ts2', now.clone().startOf('hour').add(1, 'm').format('x') / 1000)",
|
"pm.variables.set('tsStartOfDayIso', startOfDay.toISOString())",
|
||||||
" pm.variables.set('ts3', now.clone().startOf('hour').add(2, 'm').format('x') / 1000)",
|
"pm.variables.set('tsEndOfDayIso', endOfDay.toISOString())",
|
||||||
"})"
|
"pm.variables.set('tsEndOfTomorrowIso', endOfTomorrow.toISOString())",
|
||||||
|
"pm.variables.set('ts1', now.clone().startOf('hour').format('x') / 1000)",
|
||||||
|
"pm.variables.set('ts2', now.clone().startOf('hour').add(1, 'm').format('x') / 1000)",
|
||||||
|
"pm.variables.set('ts3', now.clone().startOf('hour').add(2, 'm').format('x') / 1000)"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user