| 50 | * actually exercising those routes. |
| 51 | */ |
| 52 | export const seedVerifiedUser = async ( |
| 53 | input: ISeedVerifiedUserInput |
| 54 | ): Promise<ISeedVerifiedUserResult> => { |
| 55 | const password = input.password ?? DEFAULT_PASSWORD; |
| 56 | const passwordHash = await passwordService.hash(password); |
| 57 | const verifiedAt = now(); |
| 58 | const normalizedEmail = normalizeEmail(input.email); |
| 59 | |
| 60 | const [user] = await db |
| 61 | .insert(users) |
| 62 | .values({ |
| 63 | email: normalizedEmail, |
| 64 | firstName: input.firstName ?? "", |
| 65 | lastName: input.lastName ?? "", |
| 66 | emailVerifiedAt: verifiedAt, |
| 67 | isPlatformAdmin: input.isPlatformAdmin ?? false, |
| 68 | }) |
| 69 | .returning(); |
| 70 | |
| 71 | if (!user) { |
| 72 | throw new Error("seedVerifiedUser: failed to insert user row"); |
| 73 | } |
| 74 | |
| 75 | await db.insert(userAuthProviders).values({ |
| 76 | userId: user.id, |
| 77 | provider: EMAIL_PROVIDER_KEY, |
| 78 | providerUserId: normalizedEmail, |
| 79 | passwordHash, |
| 80 | }); |
| 81 | |
| 82 | const provisioned = await accountsService.provisionAfterVerification({ |
| 83 | userId: user.id, |
| 84 | }); |
| 85 | |
| 86 | return { |
| 87 | user, |
| 88 | account: provisioned.account, |
| 89 | membership: provisioned.membership, |
| 90 | password, |
| 91 | }; |
| 92 | }; |
| 93 | |
| 94 | /** |
| 95 | * Fixture for tests that exercise the pending-user state. Inserts the |