Skip to content

Commit cf077b6

Browse files
committed
Await callback background work in the test fixture
1 parent 13693c6 commit cf077b6

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎apps/cloud/src/auth/workos-callback-state.node.test.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
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";
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(
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(
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

0 commit comments

Comments
 (0)