From a719706dff8a633938738a5551dc599d499243a1 Mon Sep 17 00:00:00 2001 From: Jeff Date: Sat, 19 Oct 2024 17:44:38 -0400 Subject: [PATCH] Fix local test port --- api/data/subscription.test.ts | 122 ++++++++++++++-------------------- 1 file changed, 51 insertions(+), 71 deletions(-) diff --git a/api/data/subscription.test.ts b/api/data/subscription.test.ts index a62a230..dc7f80c 100644 --- a/api/data/subscription.test.ts +++ b/api/data/subscription.test.ts @@ -7,8 +7,6 @@ import { updateSubscription, } from "./subscription" -import { exec } from "child_process" - const pushSubscription1 = { endpoint: "https://updates.push.services.mozilla.com/wpush/v2/aaaaaaa", expirationTime: null, @@ -28,96 +26,78 @@ const pushSubscription2 = { } jest.mock("./settings", () => ({ - port: 5432, + port: process.env.POSTGRES_PORT, user: "postgres", password: process.env.POSTGRES_PASSWORD, database: "test", - host: process.env.POSTGRES_HOST ?? "localhost", + host: process.env.POSTGRES_HOST, })) describe("subscriptions", () => { - test("Does it run", () => { - console.log("WHOAH") - expect(true).toBeTruthy() - }) - beforeAll(async () => { - console.log("HEY WTF MAN") - try { - await resetDbInstance() - } catch (error) { - console.log("Something has exploded") - fail(error) - } + await resetDbInstance() }) beforeEach(async () => { - try { - exec("docker ps", (_, out) => console.log(out)) - exec("ls /home", (_, out) => console.log(out)) - await migrateToLatest() - } catch (error) { - console.log("Something has exploded in migration") - fail(error) - } + await migrateToLatest() }) - // afterEach(async () => { - // await resetAll() - // }) + afterEach(async () => { + await resetAll() + }) - // afterAll(async () => { - // await db.destroy() - // }) + afterAll(async () => { + await db.destroy() + }) - // test("createSubscription", async () => { - // const { id } = await createSubscription(pushSubscription1) + test("createSubscription", async () => { + const { id } = await createSubscription(pushSubscription1) - // const subscription = (await db - // .selectFrom("subscription") - // .selectAll() - // .where("id", "=", id) - // .executeTakeFirst()) as Subscription + const subscription = (await db + .selectFrom("subscription") + .selectAll() + .where("id", "=", id) + .executeTakeFirst()) as Subscription - // expect(subscription).toEqual({ - // id, - // subscription: pushSubscription1, - // }) - // }) + expect(subscription).toEqual({ + id, + subscription: pushSubscription1, + }) + }) - // test("updateSubscription", async () => { - // const { id } = (await db - // .insertInto("subscription") - // .values({ subscription: JSON.stringify(pushSubscription1), id: 50 }) - // .returning("id") - // .executeTakeFirst())! + test("updateSubscription", async () => { + const { id } = (await db + .insertInto("subscription") + .values({ subscription: JSON.stringify(pushSubscription1), id: 50 }) + .returning("id") + .executeTakeFirst())! - // await updateSubscription(pushSubscription2, id) + await updateSubscription(pushSubscription2, id) - // const updated = (await db - // .selectFrom("subscription") - // .selectAll() - // .where("id", "=", id) - // .executeTakeFirst()) as Subscription + const updated = (await db + .selectFrom("subscription") + .selectAll() + .where("id", "=", id) + .executeTakeFirst()) as Subscription - // expect(updated).toEqual({ - // id, - // subscription: pushSubscription2, - // }) - // }) + expect(updated).toEqual({ + id, + subscription: pushSubscription2, + }) + }) - // test("getSubscription", async () => { - // const { id } = (await db - // .insertInto("subscription") - // .values({ subscription: JSON.stringify(pushSubscription1), id: 5000 }) - // .returning("id") - // .executeTakeFirst())! + test("getSubscription", async () => { + const { id } = (await db + .insertInto("subscription") + .values({ subscription: JSON.stringify(pushSubscription1), id: 5000 }) + .returning("id") + .executeTakeFirst())! - // const got = await getSubscription(id) + const got = await getSubscription(id) - // expect(got).toEqual({ - // subscription: pushSubscription1, - // id: 5000, - // }) - // }) + expect(got).toEqual({ + subscription: pushSubscription1, + id: 5000, + }) + }) })