(user: ReturnType<typeof workosUser>, listed: readonly FakeMembership[])
| 218 | * is assertable from the outside. |
| 219 | */ |
| 220 | const signIn = (user: ReturnType<typeof workosUser>, listed: readonly FakeMembership[]) => { |
| 221 | const calls: string[] = []; |
| 222 | const refreshedInto: (string | undefined)[] = []; |
| 223 | const handler = callbackHandler( |
| 224 | stubWorkOS({ |
| 225 | authenticateWithCode: () => |
| 226 | Effect.succeed({ |
| 227 | user, |
| 228 | organizationId: undefined, |
| 229 | accessToken: "access", |
| 230 | refreshToken: "refresh", |
| 231 | sealedSession: "sealed", |
| 232 | }), |
| 233 | listUserMemberships: (id) => { |
| 234 | calls.push(`listUserMemberships:${id}`); |
| 235 | return Effect.succeed({ |
| 236 | object: "list" as const, |
| 237 | data: listed as never[], |
| 238 | listMetadata: { before: null, after: null }, |
| 239 | }); |
| 240 | }, |
| 241 | // The landing org's seat recount scans the org from WorkOS the first |
| 242 | // time it is counted (its per-org backfill mark is missing); the |
| 243 | // scan lists the org's members and fetches each user. |
| 244 | listOrgMembers: (organizationId) => { |
| 245 | calls.push(`listOrgMembers:${organizationId}`); |
| 246 | return Effect.succeed({ |
| 247 | object: "list" as const, |
| 248 | data: listed.filter((m) => m.organizationId === organizationId) as never[], |
| 249 | listMetadata: { before: null, after: null }, |
| 250 | }); |
| 251 | }, |
| 252 | getUser: (id) => { |
| 253 | calls.push(`getUser:${id}`); |
| 254 | return Effect.succeed(workosUser(id) as never); |
| 255 | }, |
| 256 | refreshSession: (_sealed, organizationId) => { |
| 257 | refreshedInto.push(organizationId); |
| 258 | return Effect.succeed("sealed-refreshed"); |
| 259 | }, |
| 260 | }), |
| 261 | ); |
| 262 | return { handler, calls, refreshedInto }; |
| 263 | }; |
| 264 | |
| 265 | /** |
| 266 | * `GET /auth/callback` with the CSRF-matched login `state` (the callback |
no test coverage detected