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/no-explicit-any */
|
||||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||||
|
|
||||||
import {
|
import { testEnvironment, headerPushMock, cleanDB, resetToken } from '@test/helpers'
|
||||||
testEnvironment,
|
import { createConfirmedUser } from '@/seeds/factory/user'
|
||||||
createConfirmedUser,
|
|
||||||
headerPushMock,
|
|
||||||
cleanDB,
|
|
||||||
resetToken,
|
|
||||||
} from '@test/helpers'
|
|
||||||
import { createUser, setPassword } from '@/seeds/graphql/mutations'
|
import { createUser, setPassword } from '@/seeds/graphql/mutations'
|
||||||
import { login, logout } from '@/seeds/graphql/queries'
|
import { login, logout } from '@/seeds/graphql/queries'
|
||||||
import { GraphQLError } from 'graphql'
|
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 { createTestClient } from 'apollo-server-testing'
|
||||||
import createServer from '../src/server/createServer'
|
import createServer from '../src/server/createServer'
|
||||||
import { initialize } from '@dbTools/helpers'
|
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'
|
import { entities } from '@entity/index'
|
||||||
|
|
||||||
export const headerPushMock = jest.fn((t) => {
|
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 = () => {
|
export const resetToken = () => {
|
||||||
context.token = ''
|
context.token = ''
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user