Unified · Split
| @@ -11,6 +11,8 @@ · 10 unmodified lines | |||
| 11 | // --------------------------------------------------------------------------- | 11 | // --------------------------------------------------------------------------- |
| 12 | 12 | ||
| 13 | import { afterAll, describe, expect, it } from "@effect/vitest"; | 13 | import { afterAll, describe, expect, it } from "@effect/vitest"; |
| 14 | import { vi } from "vitest"; | ||
| 15 | import { waitUntil } from "cloudflare:workers"; | ||
| 14 | import { Effect, Layer } from "effect"; | 16 | import { Effect, Layer } from "effect"; |
| 15 | import { HttpRouter, HttpServer } from "effect/unstable/http"; | 17 | import { HttpRouter, HttpServer } from "effect/unstable/http"; |
| 16 | import { HttpApiBuilder } from "effect/unstable/httpapi"; | 18 | import { HttpApiBuilder } from "effect/unstable/httpapi"; |
| @@ -21,6 +23,7 @@ import { CloudAuthPublicApi } from "./api"; · 4 unmodified lines | |||
| 21 | import { UserStoreService } from "./context"; | 23 | import { UserStoreService } from "./context"; |
| 22 | import { WorkOSClient, type WorkOSClientService } from "./workos"; | 24 | import { WorkOSClient, type WorkOSClientService } from "./workos"; |
| 23 | import { encodeLoginState } from "./login-state"; | 25 | import { encodeLoginState } from "./login-state"; |
| 26 | import { 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 | ||
| 94 | const app = HttpRouter.toWebHandler(App, { disableLogger: true }); | 101 | 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 | }); | ||
| 96 | 106 | ||
| 97 | const run = (request: Request) => { | 107 | const run = (request: Request) => { |
| 98 | // beta.59: the handler type expects a context argument; this layer stack | 108 | // beta.59: the handler type expects a context argument; this layer stack |