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
1111 // ---------------------------------------------------------------------------
1212
1313 import { afterAll, describe, expect, it } from "@effect/vitest";
14+import { vi } from "vitest";
15+import { waitUntil } from "cloudflare:workers";
1416 import { Effect, Layer } from "effect";
1517 import { HttpRouter, HttpServer } from "effect/unstable/http";
1618 import { HttpApiBuilder } from "effect/unstable/httpapi";
@@ -21,6 +23,7 @@ import { CloudAuthPublicApi } from "./api"; · 4 unmodified lines
2123 import { UserStoreService } from "./context";
2224 import { WorkOSClient, type WorkOSClientService } from "./workos";
2325 import { encodeLoginState } from "./login-state";
26+import { AutumnService } from "../extensions/billing/service";
2427
2528 // The route under test serves under the `/api` prefix in the composed app;
2629 // toWebHandler mounts the raw group, so paths here are relative to the group.
@@ -46,6 +49,9 @@ const stubWorkOS = Layer.succeed( · 19 unmodified lines
4649 if (prop === "listUserMemberships") {
4750 return () => Effect.succeed({ data: [] });
4851 }
52+ if (prop === "listOrgMembers") {
53+ return () => Effect.succeed({ data: [{ status: "active" }] });
54+ }
4955 return () => Effect.die(`unexpected WorkOSClient.${String(prop)} call`);
5056 },
5157 }),
@@ -88,11 +94,15 @@ const App = HttpApiBuilder.layer(PublicApi).pipe( · 36 unmodified lines
8894 Layer.provide(CloudAuthPublicHandlers),
8995 Layer.provide(stubWorkOS),
9096 Layer.provide(stubUsers),
97+ Layer.provide(AutumnService.Default),
9198 Layer.provide(HttpServer.layerServices),
9299 );
93100
94101 const app = HttpRouter.toWebHandler(App, { disableLogger: true });
95−afterAll(() => app.dispose());
102+afterAll(async () => {
103+ await Promise.all(vi.mocked(waitUntil).mock.calls.map(([work]) => work));
104+ await app.dispose();
105+});
96106
97107 const run = (request: Request) => {
98108 // beta.59: the handler type expects a context argument; this layer stack