Openstatus www.openstatus.dev
at main 53 lines 1.4 kB view raw
1import { expect, test } from "bun:test"; 2 3import { app } from "@/index"; 4import { db, eq } from "@openstatus/db"; 5import { pageSubscriber } from "@openstatus/db/src/schema"; 6import { PageSubscriberSchema } from "./schema"; 7 8test("create a page subscription", async () => { 9 const res = await app.request("/v1/page_subscriber/1/update", { 10 method: "POST", 11 headers: { 12 "x-openstatus-key": "1", 13 "content-type": "application/json", 14 }, 15 body: JSON.stringify({ email: "ping@openstatus.dev" }), 16 }); 17 18 const result = PageSubscriberSchema.safeParse(await res.json()); 19 20 expect(res.status).toBe(200); 21 expect(result.success).toBe(true); 22 23 // Cleanup: delete the created page subscriber 24 if (result.success) { 25 await db 26 .delete(pageSubscriber) 27 .where(eq(pageSubscriber.id, result.data.id)); 28 } 29}); 30 31test("create a scubscriber with invalid email should return a 400", async () => { 32 const res = await app.request("/v1/page_subscriber/1/update", { 33 method: "POST", 34 headers: { 35 "x-openstatus-key": "1", 36 "content-type": "application/json", 37 }, 38 body: JSON.stringify({ email: "ping" }), 39 }); 40 41 expect(res.status).toBe(400); 42}); 43 44test("no auth key should return 401", async () => { 45 const res = await app.request("/v1/page_subscriber/1/update", { 46 method: "POST", 47 headers: { 48 "content-type": "application/json", 49 }, 50 }); 51 52 expect(res.status).toBe(401); 53});