mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
use factory to create user in test, use bibi bloxberg as seeded user (no admin)
This commit is contained in:
parent
004627ddcf
commit
00c70311a1
@ -2,7 +2,8 @@
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
|
||||
import { testEnvironment, headerPushMock, cleanDB, resetToken } from '@test/helpers'
|
||||
import { createConfirmedUser } from '@/seeds/factory/user'
|
||||
import { createUserFactory } from '@/seeds/factory/user'
|
||||
import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg'
|
||||
import { createUser, setPassword } from '@/seeds/graphql/mutations'
|
||||
import { login, logout } from '@/seeds/graphql/queries'
|
||||
import { GraphQLError } from 'graphql'
|
||||
@ -284,7 +285,7 @@ describe('UserResolver', () => {
|
||||
|
||||
describe('login', () => {
|
||||
const variables = {
|
||||
email: 'peter@lustig.de',
|
||||
email: 'bibi@bloxberg.de',
|
||||
password: 'Aa12345_',
|
||||
publisherId: 1234,
|
||||
}
|
||||
@ -311,13 +312,7 @@ describe('UserResolver', () => {
|
||||
|
||||
describe('user is in database and correct login data', () => {
|
||||
beforeAll(async () => {
|
||||
await createConfirmedUser(mutate, {
|
||||
email: 'peter@lustig.de',
|
||||
firstName: 'Peter',
|
||||
lastName: 'Lustig',
|
||||
language: 'de',
|
||||
publisherId: 1234,
|
||||
})
|
||||
await createUserFactory(mutate, bibiBloxberg)
|
||||
result = await query({ query: login, variables })
|
||||
})
|
||||
|
||||
@ -331,15 +326,15 @@ describe('UserResolver', () => {
|
||||
data: {
|
||||
login: {
|
||||
coinanimation: true,
|
||||
email: 'peter@lustig.de',
|
||||
firstName: 'Peter',
|
||||
email: 'bibi@bloxberg.de',
|
||||
firstName: 'Bibi',
|
||||
hasElopage: false,
|
||||
isAdmin: false,
|
||||
klickTipp: {
|
||||
newsletterState: false,
|
||||
},
|
||||
language: 'de',
|
||||
lastName: 'Lustig',
|
||||
lastName: 'Bloxberg',
|
||||
publisherId: 1234,
|
||||
},
|
||||
},
|
||||
@ -354,13 +349,7 @@ describe('UserResolver', () => {
|
||||
|
||||
describe('user is in database and wrong password', () => {
|
||||
beforeAll(async () => {
|
||||
await createConfirmedUser(mutate, {
|
||||
email: 'peter@lustig.de',
|
||||
firstName: 'Peter',
|
||||
lastName: 'Lustig',
|
||||
language: 'de',
|
||||
publisherId: 1234,
|
||||
})
|
||||
await createUserFactory(mutate, bibiBloxberg)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
@ -393,18 +382,12 @@ describe('UserResolver', () => {
|
||||
|
||||
describe('authenticated', () => {
|
||||
const variables = {
|
||||
email: 'peter@lustig.de',
|
||||
email: 'bibi@bloxberg.de',
|
||||
password: 'Aa12345_',
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
await createConfirmedUser(mutate, {
|
||||
email: 'peter@lustig.de',
|
||||
firstName: 'Peter',
|
||||
lastName: 'Lustig',
|
||||
language: 'de',
|
||||
publisherId: 1234,
|
||||
})
|
||||
await createUserFactory(mutate, bibiBloxberg)
|
||||
await query({ query: login, variables })
|
||||
})
|
||||
|
||||
|
||||
@ -4,16 +4,18 @@
|
||||
import { createUser, setPassword } from '@/seeds/graphql/mutations'
|
||||
import { User } from '@entity/User'
|
||||
import { LoginEmailOptIn } from '@entity/LoginEmailOptIn'
|
||||
import { UserInterface } from '@/seeds/users/UserInterface'
|
||||
|
||||
export const createConfirmedUser = async (mutate: any, user: any) => {
|
||||
// resetToken()
|
||||
export const createUserFactory = async (mutate: any, user: UserInterface): Promise<void> => {
|
||||
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 },
|
||||
})
|
||||
if (user.emailChecked) {
|
||||
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 },
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,5 +7,6 @@ export interface UserInterface {
|
||||
emailChecked?: boolean
|
||||
language?: string
|
||||
deletedAt?: Date
|
||||
publisherId?: number
|
||||
isAdmin?: boolean
|
||||
}
|
||||
|
||||
@ -7,4 +7,5 @@ export const bibiBloxberg: UserInterface = {
|
||||
// description: 'Hex Hex',
|
||||
emailChecked: true,
|
||||
language: 'de',
|
||||
publisherId: 1234,
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user