| 41 | }; |
| 42 | |
| 43 | const stubWorkOS = (calls: string[]) => |
| 44 | Layer.succeed( |
| 45 | WorkOSClient, |
| 46 | new Proxy({} as WorkOSClientService, { |
| 47 | get: (_target, prop) => { |
| 48 | if (prop === "listOrgMembers") { |
| 49 | return (organizationId: string) => { |
| 50 | calls.push(`listOrgMembers:${organizationId}`); |
| 51 | return Effect.succeed({ |
| 52 | data: Object.keys(DIRECTORY).map((userId) => ({ userId, organizationId })), |
| 53 | }); |
| 54 | }; |
| 55 | } |
| 56 | if (prop === "getUser") { |
| 57 | return (userId: string) => { |
| 58 | calls.push(`getUser:${userId}`); |
| 59 | const user = DIRECTORY[userId]; |
| 60 | if (!user) return Effect.die(`unexpected user ${userId}`); |
| 61 | return Effect.succeed(user); |
| 62 | }; |
| 63 | } |
| 64 | // A resolver that reaches for any other WorkOS call — notably a |
| 65 | // `listUsers` the emulator cannot serve — is the failure this catches. |
| 66 | return () => Effect.die(`unexpected WorkOSClient.${String(prop)} call`); |
| 67 | }, |
| 68 | }), |
| 69 | ); |
| 70 | |
| 71 | const resolve = (email: string, calls: string[]) => |
| 72 | Effect.gen(function* () { |