1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

Merge pull request #461 from muety/tz-test

test: remove api call for timezone
This commit is contained in:
Ferdinand Mütsch 2023-01-22 14:09:25 +01:00 committed by GitHub
commit c42985a279
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3370,57 +3370,53 @@
"// pretend we're in Berlin, as this is also the time zone configured for the user",
"const userZone = 'Europe/Berlin'",
"",
"// 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)",
" })",
"// https://stackoverflow.com/a/63199512",
"// return UTC offset of timezone in minutes",
"function getTimezoneOffset(timeZone, date = new Date()) {",
" const tz = date.toLocaleString(\"en\", {timeZone, timeStyle: \"long\"}).split(\" \").slice(-1)[0];",
" const dateString = date.toString();",
" const offset = Date.parse(`${dateString} UTC`) - Date.parse(`${dateString} ${tz}`);",
" return offset / 1000 / 60;",
"}",
"",
"getUtcOffset((utcOffset) => {",
" 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')",
"const utcOffset = getTimezoneOffset(userZone);",
"",
" // Auth stuff",
" const readApiKey = pm.variables.get('READUSER_API_KEY')",
" const writeApiKey = pm.variables.get('WRITEUSER_API_KEY')",
"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')",
"",
" 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)",
"",
"if (!readApiKey || !writeApiKey) {",
" throw new Error('no api key given')",
" }",
"}",
"",
" pm.variables.set('READUSER_TOKEN', base64encode(readApiKey))",
" pm.variables.set('WRITEUSER_TOKEN', base64encode(writeApiKey))",
"pm.variables.set('READUSER_TOKEN', base64encode(readApiKey))",
"pm.variables.set('WRITEUSER_TOKEN', base64encode(writeApiKey))",
"",
" function base64encode(str) {",
"function base64encode(str) {",
" return Buffer.from(str, 'utf-8').toString('base64')",
" }",
"}",
"",
" // Heartbeat stuff",
" pm.variables.set('tsNow', now.clone().format('x') / 1000)",
" 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)",
" pm.variables.set('tsStartOfDay', startOfDay.format('x') / 1000)",
" pm.variables.set('tsEndOfDay', endOfDay.format('x') / 1000)",
" pm.variables.set('tsEndOfTomorrow', endOfTomorrow.format('x') / 1000)",
" pm.variables.set('tsStartOfDayIso', startOfDay.toISOString())",
" 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)",
"})"
"// Heartbeat stuff",
"pm.variables.set('tsNow', now.clone().format('x') / 1000)",
"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)",
"pm.variables.set('tsStartOfDay', startOfDay.format('x') / 1000)",
"pm.variables.set('tsEndOfDay', endOfDay.format('x') / 1000)",
"pm.variables.set('tsEndOfTomorrow', endOfTomorrow.format('x') / 1000)",
"pm.variables.set('tsStartOfDayIso', startOfDay.toISOString())",
"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)"
]
}
},