Skip to content

Commit

Permalink
[test] skip tests that depend on node and db timezone offsets matching (
Browse files Browse the repository at this point in the history
  • Loading branch information
lolopinto authored Dec 6, 2023
1 parent 9710938 commit 253e195
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions ts/src/schema/postgres_schema_live.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { v1, v4 as uuidv4 } from "uuid";
import { DateTime } from "luxon";
import pg from "pg";
import DB from "../core/db";
import * as fs from "fs";
import * as path from "path";
import each from "jest-each";
Expand Down Expand Up @@ -170,7 +172,30 @@ describe("timestamp", () => {
expect(updatedAt.getTime()).toBe(date.getTime());
});

let dbOffset: number | undefined;

async function shouldSkipTimezoneQuery(): Promise<boolean> {
if (dbOffset === undefined) {
const result = await DB.getInstance()
.getPool()
.query(
"SELECT EXTRACT(TIMEZONE FROM CURRENT_TIMESTAMP) / 60 AS timezone_offset_hours",
);
dbOffset = parseFloat(result.rows[0]["timezone_offset_hours"]);
}

const nodeOffset = DateTime.now().offset;
// if (dbOffset.toString() !== nodeOffset.toString()) {
return dbOffset !== nodeOffset;
}

test("no setTypeParser", async () => {
const shouldSkip = await shouldSkipTimezoneQuery();
if (shouldSkip) {
console.warn("skipping because db offset and node offset are different");
return;
}

const date = new Date();
const action = getInsertAction(
UserSchema,
Expand Down Expand Up @@ -212,6 +237,12 @@ describe("timestamp", () => {
}

test("no toISO formattting", async () => {
const shouldSkip = await shouldSkipTimezoneQuery();
if (shouldSkip) {
console.warn("skipping because db offset and node offset are different");
return;
}

const date = new Date();
const action = getInsertAction(
new UserWithTimestampNoFormatSchema(),
Expand Down

0 comments on commit 253e195

Please sign in to comment.