Openstatus www.openstatus.dev
at 4c0f4c00a38753a5d0dfd7e7b7b7706dec6f1503 108 lines 2.4 kB view raw
1import { expect, test } from "bun:test"; 2 3import { edgeRouter } from "../edge"; 4import { createInnerTRPCContext } from "../trpc"; 5 6test("Get Test Workspace", async () => { 7 const ctx = createInnerTRPCContext({ 8 req: undefined, 9 session: { 10 user: { 11 id: "1", 12 }, 13 }, 14 //@ts-expect-error 15 workspace: { 16 id: 1, 17 }, 18 }); 19 20 const caller = edgeRouter.createCaller(ctx); 21 const result = await caller.workspace.getWorkspace(); 22 23 expect(result).toMatchObject({ 24 id: 1, 25 slug: "love-openstatus", 26 name: "test", 27 plan: "team", 28 paidUntil: null, 29 stripeId: "stripeId1", 30 subscriptionId: "subscriptionId", 31 updatedAt: expect.any(Date), 32 createdAt: expect.any(Date), 33 endsAt: null, 34 }); 35}); 36 37test("by default we get the first workspace", async () => { 38 const ctx = createInnerTRPCContext({ 39 req: undefined, 40 session: { 41 user: { 42 // @ts-expect-error some issues with types 43 id: 1, 44 }, 45 }, 46 workspace: undefined, 47 }); 48 49 const caller = edgeRouter.createCaller(ctx); 50 const result = await caller.workspace.getWorkspace(); 51 52 expect(result).toMatchObject({ 53 id: 1, 54 slug: "love-openstatus", 55 name: "test", 56 plan: "team", 57 paidUntil: null, 58 stripeId: "stripeId1", 59 subscriptionId: "subscriptionId", 60 updatedAt: expect.any(Date), 61 createdAt: expect.any(Date), 62 endsAt: null, 63 }); 64}); 65 66test("All workspaces", async () => { 67 const ctx = createInnerTRPCContext({ 68 req: undefined, 69 session: { 70 user: { 71 id: "1", 72 }, 73 }, 74 }); 75 76 const caller = edgeRouter.createCaller(ctx); 77 const result = await caller.workspace.getUserWithWorkspace(); 78 expect(result).toMatchObject([ 79 { 80 createdAt: expect.any(Date), 81 email: "ping@openstatus.dev", 82 firstName: "Speed", 83 id: 1, 84 lastName: "Matters", 85 photoUrl: "", 86 tenantId: "1", 87 updatedAt: expect.any(Date), 88 usersToWorkspaces: [ 89 { 90 userId: 1, 91 workspace: { 92 createdAt: expect.any(Date), 93 endsAt: null, 94 id: 1, 95 name: "test", 96 paidUntil: null, 97 plan: "team", 98 slug: "love-openstatus", 99 stripeId: "stripeId1", 100 subscriptionId: "subscriptionId", 101 updatedAt: expect.any(Date), 102 }, 103 workspaceId: 1, 104 }, 105 ], 106 }, 107 ]); 108});