create factory folder, move user creation in factory

This commit is contained in:
Moriz Wahl 2022-03-15 10:23:24 +01:00
parent b30f4dfa5d
commit 004627ddcf
3 changed files with 21 additions and 23 deletions

View File

@ -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'

View 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 },
})
}

View File

@ -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 = ''
}