MCPcopy
hub / github.com/epicweb-dev/epic-stack / getOrInsertUser

Function getOrInsertUser

tests/playwright-utils.ts:36–64  ·  view source on GitHub ↗
({
	id,
	username,
	password,
	email,
}: GetOrInsertUserOptions = {})

Source from the content-addressed store, hash-verified

34}
35
36async function getOrInsertUser({
37 id,
38 username,
39 password,
40 email,
41}: GetOrInsertUserOptions = {}): Promise<User> {
42 const select = { id: true, email: true, username: true, name: true }
43 if (id) {
44 return await prisma.user.findUniqueOrThrow({
45 select,
46 where: { id: id },
47 })
48 } else {
49 const userData = createUser()
50 username ??= userData.username
51 password ??= userData.username
52 email ??= userData.email
53 return await prisma.user.create({
54 select,
55 data: {
56 ...userData,
57 email,
58 username,
59 roles: { connect: { name: 'user' } },
60 password: { create: { hash: await getPasswordHash(password) } },
61 },
62 })
63 }
64}
65
66export const test = base.extend<{
67 insertNewUser(options?: GetOrInsertUserOptions): Promise<User>

Callers 1

Calls 2

createUserFunction · 0.90
getPasswordHashFunction · 0.90

Tested by

no test coverage detected