History

Await callback background work in the test fixture

Rhys Sullivan committed 1 month ago

Commit cf077b61 parent 13693c61 file · +11 −1Browse files

Unified · Split

apps/cloud/src/auth/workos-callback-state.node.test.ts+11−1
@@ -11,6 +11,8 @@ · 10 unmodified lines
11// ---------------------------------------------------------------------------11// ---------------------------------------------------------------------------
12 12
13import { afterAll, describe, expect, it } from "@effect/vitest";13import { afterAll, describe, expect, it } from "@effect/vitest";
14import { vi } from "vitest";
15import { waitUntil } from "cloudflare:workers";
14import { Effect, Layer } from "effect";16import { Effect, Layer } from "effect";
15import { HttpRouter, HttpServer } from "effect/unstable/http";17import { HttpRouter, HttpServer } from "effect/unstable/http";
16import { HttpApiBuilder } from "effect/unstable/httpapi";18import { HttpApiBuilder } from "effect/unstable/httpapi";
@@ -21,6 +23,7 @@ import { CloudAuthPublicApi } from "./api"; · 4 unmodified lines
21import { UserStoreService } from "./context";23import { UserStoreService } from "./context";
22import { WorkOSClient, type WorkOSClientService } from "./workos";24import { WorkOSClient, type WorkOSClientService } from "./workos";
23import { encodeLoginState } from "./login-state";25import { encodeLoginState } from "./login-state";
26import { AutumnService } from "../extensions/billing/service";
24 27
25// The route under test serves under the `/api` prefix in the composed app;28// The route under test serves under the `/api` prefix in the composed app;
26// toWebHandler mounts the raw group, so paths here are relative to the group.29// toWebHandler mounts the raw group, so paths here are relative to the group.
@@ -46,6 +49,9 @@ const stubWorkOS = Layer.succeed( · 19 unmodified lines
46 if (prop === "listUserMemberships") {49 if (prop === "listUserMemberships") {
47 return () => Effect.succeed({ data: [] });50 return () => Effect.succeed({ data: [] });
48 }51 }
52 if (prop === "listOrgMembers") {
53 return () => Effect.succeed({ data: [{ status: "active" }] });
54 }
49 return () => Effect.die(`unexpected WorkOSClient.${String(prop)} call`);55 return () => Effect.die(`unexpected WorkOSClient.${String(prop)} call`);
50 },56 },
51 }),57 }),
@@ -88,11 +94,15 @@ const App = HttpApiBuilder.layer(PublicApi).pipe( · 36 unmodified lines
88 Layer.provide(CloudAuthPublicHandlers),94 Layer.provide(CloudAuthPublicHandlers),
89 Layer.provide(stubWorkOS),95 Layer.provide(stubWorkOS),
90 Layer.provide(stubUsers),96 Layer.provide(stubUsers),
97 Layer.provide(AutumnService.Default),
91 Layer.provide(HttpServer.layerServices),98 Layer.provide(HttpServer.layerServices),
92);99);
93 100
94const app = HttpRouter.toWebHandler(App, { disableLogger: true });101const app = HttpRouter.toWebHandler(App, { disableLogger: true });
95afterAll(() => app.dispose());102afterAll(async () => {
103 await Promise.all(vi.mocked(waitUntil).mock.calls.map(([work]) => work));
104 await app.dispose();
105});
96 106
97const run = (request: Request) => {107const run = (request: Request) => {
98 // beta.59: the handler type expects a context argument; this layer stack108 // beta.59: the handler type expects a context argument; this layer stack