diff --git a/testing/wakapi_api_tests.postman_collection.json b/testing/wakapi_api_tests.postman_collection.json index b385167..ea76ef8 100644 --- a/testing/wakapi_api_tests.postman_collection.json +++ b/testing/wakapi_api_tests.postman_collection.json @@ -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) {", - " throw new Error('no api key given')", - " }", + "console.log(readApiKey)", "", - " pm.variables.set('READUSER_TOKEN', base64encode(readApiKey))", - " pm.variables.set('WRITEUSER_TOKEN', base64encode(writeApiKey))", + "if (!readApiKey || !writeApiKey) {", + " throw new Error('no api key given')", + "}", "", - " function base64encode(str) {", - " return Buffer.from(str, 'utf-8').toString('base64')", - " }", + "pm.variables.set('READUSER_TOKEN', base64encode(readApiKey))", + "pm.variables.set('WRITEUSER_TOKEN', base64encode(writeApiKey))", "", - " // 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)", - "})" + "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)" ] } },