120 lines
2.7 KiB
TypeScript
120 lines
2.7 KiB
TypeScript
import { db, resetDbInstance } from "./database"
|
|
import migrateToLatest, { resetAll } from "./migrate"
|
|
import {
|
|
createSubscription,
|
|
getSubscription,
|
|
Subscription,
|
|
updateSubscription,
|
|
} from "./subscription"
|
|
|
|
const pushSubscription1 = {
|
|
endpoint: "https://updates.push.services.mozilla.com/wpush/v2/aaaaaaa",
|
|
expirationTime: null,
|
|
keys: {
|
|
auth: "adfsadfasdf",
|
|
p256dh: "aaaaaaaaaaaa",
|
|
},
|
|
}
|
|
|
|
const pushSubscription2 = {
|
|
endpoint: "https://updates.push.services.mozilla.com/wpush/v2/bbbbbbbb",
|
|
expirationTime: null,
|
|
keys: {
|
|
auth: "whoahauth",
|
|
p256dh: "bbbbbbbb",
|
|
},
|
|
}
|
|
|
|
jest.mock("./settings", () => ({
|
|
port: 5432,
|
|
user: "postgres",
|
|
password: process.env.POSTGRES_PASSWORD,
|
|
database: "test",
|
|
host: "localhost",
|
|
}))
|
|
|
|
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)
|
|
}
|
|
})
|
|
|
|
beforeEach(async () => {
|
|
try {
|
|
await migrateToLatest()
|
|
} catch (error) {
|
|
console.log("Something has exploded in migration")
|
|
fail(error)
|
|
}
|
|
})
|
|
|
|
// afterEach(async () => {
|
|
// await resetAll()
|
|
// })
|
|
|
|
// afterAll(async () => {
|
|
// await db.destroy()
|
|
// })
|
|
|
|
// test("createSubscription", async () => {
|
|
// const { id } = await createSubscription(pushSubscription1)
|
|
|
|
// const subscription = (await db
|
|
// .selectFrom("subscription")
|
|
// .selectAll()
|
|
// .where("id", "=", id)
|
|
// .executeTakeFirst()) as Subscription
|
|
|
|
// 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())!
|
|
|
|
// await updateSubscription(pushSubscription2, id)
|
|
|
|
// const updated = (await db
|
|
// .selectFrom("subscription")
|
|
// .selectAll()
|
|
// .where("id", "=", id)
|
|
// .executeTakeFirst()) as Subscription
|
|
|
|
// 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())!
|
|
|
|
// const got = await getSubscription(id)
|
|
|
|
// expect(got).toEqual({
|
|
// subscription: pushSubscription1,
|
|
// id: 5000,
|
|
// })
|
|
// })
|
|
})
|