mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
create factory folder, move user creation in factory
This commit is contained in:
parent
b30f4dfa5d
commit
004627ddcf
@ -1,13 +1,8 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
|
||||
import {
|
||||
testEnvironment,
|
||||
createConfirmedUser,
|
||||
headerPushMock,
|
||||
cleanDB,
|
||||
resetToken,
|
||||
} from '@test/helpers'
|
||||
import { testEnvironment, headerPushMock, cleanDB, resetToken } from '@test/helpers'
|
||||
import { createConfirmedUser } from '@/seeds/factory/user'
|
||||
import { createUser, setPassword } from '@/seeds/graphql/mutations'
|
||||
import { login, logout } from '@/seeds/graphql/queries'
|
||||
import { GraphQLError } from 'graphql'
|
||||
|
||||
19
backend/src/seeds/factory/user.ts
Normal file
19
backend/src/seeds/factory/user.ts
Normal file
@ -0,0 +1,19 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
|
||||
import { createUser, setPassword } from '@/seeds/graphql/mutations'
|
||||
import { User } from '@entity/User'
|
||||
import { LoginEmailOptIn } from '@entity/LoginEmailOptIn'
|
||||
|
||||
export const createConfirmedUser = async (mutate: any, user: any) => {
|
||||
// resetToken()
|
||||
await mutate({ mutation: createUser, variables: user })
|
||||
const dbUser = await User.findOne({ where: { email: user.email } })
|
||||
if (!dbUser) throw new Error('Ups, no user found')
|
||||
const optin = await LoginEmailOptIn.findOne({ where: { userId: dbUser.id } })
|
||||
if (!optin) throw new Error('Ups, no optin found')
|
||||
await mutate({
|
||||
mutation: setPassword,
|
||||
variables: { password: 'Aa12345_', code: optin.verificationCode },
|
||||
})
|
||||
}
|
||||
@ -4,9 +4,6 @@
|
||||
import { createTestClient } from 'apollo-server-testing'
|
||||
import createServer from '../src/server/createServer'
|
||||
import { initialize } from '@dbTools/helpers'
|
||||
import { createUser, setPassword } from '@/seeds/graphql/mutations'
|
||||
import { LoginEmailOptIn } from '@entity/LoginEmailOptIn'
|
||||
import { User } from '@entity/User'
|
||||
import { entities } from '@entity/index'
|
||||
|
||||
export const headerPushMock = jest.fn((t) => {
|
||||
@ -46,19 +43,6 @@ export const resetEntity = async (entity: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
export const createConfirmedUser = async (mutate: any, user: any) => {
|
||||
// resetToken()
|
||||
await mutate({ mutation: createUser, variables: user })
|
||||
const dbUser = await User.findOne({ where: { email: user.email } })
|
||||
if (!dbUser) throw new Error('Ups, no user found')
|
||||
const optin = await LoginEmailOptIn.findOne({ where: { userId: dbUser.id } })
|
||||
if (!optin) throw new Error('Ups, no optin found')
|
||||
await mutate({
|
||||
mutation: setPassword,
|
||||
variables: { password: 'Aa12345_', code: optin.verificationCode },
|
||||
})
|
||||
}
|
||||
|
||||
export const resetToken = () => {
|
||||
context.token = ''
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user