mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
adapt tests to work with User and UserContact
This commit is contained in:
parent
a0fe5f7951
commit
97dee4d67c
@ -215,10 +215,12 @@ describe('UserResolver', () => {
|
||||
mutation: createUser,
|
||||
variables: { ...variables, email: 'bibi@bloxberg.de', language: 'it' },
|
||||
})
|
||||
await expect(User.find()).resolves.toEqual(
|
||||
await expect(User.find({ relations: ['emailContact'] }, )).resolves.toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
email: 'bibi@bloxberg.de',
|
||||
emailContact: expect.objectContaining({
|
||||
email: 'bibi@bloxberg.de',
|
||||
}),
|
||||
language: 'de',
|
||||
}),
|
||||
]),
|
||||
@ -232,10 +234,12 @@ describe('UserResolver', () => {
|
||||
mutation: createUser,
|
||||
variables: { ...variables, email: 'raeuber@hotzenplotz.de', publisherId: undefined },
|
||||
})
|
||||
await expect(User.find()).resolves.toEqual(
|
||||
await expect(User.find({ relations: ['emailContact'] }, )).resolves.toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
email: 'raeuber@hotzenplotz.de',
|
||||
emailContact: expect.objectContaining({
|
||||
email: 'raeuber@hotzenplotz.de',
|
||||
}),
|
||||
publisherId: null,
|
||||
}),
|
||||
]),
|
||||
@ -276,7 +280,9 @@ describe('UserResolver', () => {
|
||||
UserContact.findOne({ email: 'ein@besucher.de' }, { relations: ['user'] }),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
contributionLinkId: link.id,
|
||||
user: expect.objectContaining({
|
||||
contributionLinkId: link.id,
|
||||
}),
|
||||
}),
|
||||
)
|
||||
})
|
||||
@ -322,20 +328,20 @@ bei Gradidio sei dabei!`,
|
||||
}
|
||||
|
||||
let result: any
|
||||
let emailOptIn: string
|
||||
let emailVerificationCode: string
|
||||
|
||||
describe('valid optin code and valid password', () => {
|
||||
let newUser: any
|
||||
let newUser: User
|
||||
|
||||
beforeAll(async () => {
|
||||
await mutate({ mutation: createUser, variables: createUserVariables })
|
||||
const loginEmailOptIn = await LoginEmailOptIn.find()
|
||||
emailOptIn = loginEmailOptIn[0].verificationCode.toString()
|
||||
const emailContact = await UserContact.findOneOrFail({ email: createUserVariables.email })
|
||||
emailVerificationCode = emailContact.emailVerificationCode.toString()
|
||||
result = await mutate({
|
||||
mutation: setPassword,
|
||||
variables: { code: emailOptIn, password: 'Aa12345_' },
|
||||
variables: { code: emailVerificationCode, password: 'Aa12345_' },
|
||||
})
|
||||
newUser = await User.find()
|
||||
newUser = await User.findOneOrFail({ id: emailContact.userId }, { relations: ['emailContact'] })
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
@ -343,11 +349,11 @@ bei Gradidio sei dabei!`,
|
||||
})
|
||||
|
||||
it('sets email checked to true', () => {
|
||||
expect(newUser[0].emailChecked).toBeTruthy()
|
||||
expect(newUser.emailContact.emailChecked).toBeTruthy()
|
||||
})
|
||||
|
||||
it('updates the password', () => {
|
||||
expect(newUser[0].password).toEqual('3917921995996627700')
|
||||
expect(newUser.password).toEqual('3917921995996627700')
|
||||
})
|
||||
|
||||
/*
|
||||
@ -369,11 +375,11 @@ bei Gradidio sei dabei!`,
|
||||
describe('no valid password', () => {
|
||||
beforeAll(async () => {
|
||||
await mutate({ mutation: createUser, variables: createUserVariables })
|
||||
const loginEmailOptIn = await LoginEmailOptIn.find()
|
||||
emailOptIn = loginEmailOptIn[0].verificationCode.toString()
|
||||
const emailContact = await UserContact.findOneOrFail({ email: createUserVariables.email })
|
||||
emailVerificationCode = emailContact.emailVerificationCode.toString()
|
||||
result = await mutate({
|
||||
mutation: setPassword,
|
||||
variables: { code: emailOptIn, password: 'not-valid' },
|
||||
variables: { code: emailVerificationCode, password: 'not-valid' },
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -324,25 +324,6 @@ export class UserResolver {
|
||||
logger.info(`login with ${email}, ***, ${publisherId} ...`)
|
||||
email = email.trim().toLowerCase()
|
||||
const dbUser = await findUserByEmail(email)
|
||||
/*
|
||||
const dbUserContact = await DbUserContact.findOneOrFail({ email }, { withDeleted: true }).catch(
|
||||
() => {
|
||||
logger.error(`UserContact with email=${email} does not exists`)
|
||||
throw new Error('No user with this credentials')
|
||||
},
|
||||
)
|
||||
const userId = dbUserContact.userId
|
||||
const dbUser = await DbUser.findOneOrFail(userId).catch(() => {
|
||||
logger.error(`User with emeilContact=${email} connected per userId=${userId} does not exist`)
|
||||
throw new Error('No user with this credentials')
|
||||
})
|
||||
*/
|
||||
/*
|
||||
const dbUser = await DbUser.findOneOrFail({ email }, { withDeleted: true }).catch(() => {
|
||||
logger.error(`User with email=${email} does not exists`)
|
||||
throw new Error('No user with this credentials')
|
||||
})
|
||||
*/
|
||||
if (dbUser.deletedAt) {
|
||||
logger.error('The User was permanently deleted in database.')
|
||||
throw new Error('This user was permanently deleted. Contact support for questions.')
|
||||
@ -591,8 +572,9 @@ export class UserResolver {
|
||||
async forgotPassword(@Arg('email') email: string): Promise<boolean> {
|
||||
logger.info(`forgotPassword(${email})...`)
|
||||
email = email.trim().toLowerCase()
|
||||
const user = await findUserByEmail(email)
|
||||
// const user = await DbUser.findOne({ email })
|
||||
const user = await findUserByEmail(email).catch(() => {
|
||||
logger.warn(`fail on find UserContact per ${email}`)
|
||||
})
|
||||
if (!user) {
|
||||
logger.warn(`no user found with ${email}`)
|
||||
return true
|
||||
@ -650,12 +632,13 @@ export class UserResolver {
|
||||
throw new Error('Could not login with emailVerificationCode')
|
||||
})
|
||||
*/
|
||||
const userContact = await DbUserContact.findOneOrFail({ emailVerificationCode: code }).catch(
|
||||
() => {
|
||||
logger.error('Could not login with emailVerificationCode')
|
||||
throw new Error('Could not login with emailVerificationCode')
|
||||
},
|
||||
)
|
||||
const userContact = await DbUserContact.findOneOrFail(
|
||||
{ emailVerificationCode: code },
|
||||
{ relations: ['user'] },
|
||||
).catch(() => {
|
||||
logger.error('Could not login with emailVerificationCode')
|
||||
throw new Error('Could not login with emailVerificationCode')
|
||||
})
|
||||
logger.debug('userContact loaded...')
|
||||
// Code is only valid for `CONFIG.EMAIL_CODE_VALID_TIME` minutes
|
||||
if (!isEmailVerificationCodeValid(userContact.updatedAt)) {
|
||||
@ -669,10 +652,7 @@ export class UserResolver {
|
||||
logger.debug('EmailVerificationCode is valid...')
|
||||
|
||||
// load user
|
||||
const user = await DbUser.findOneOrFail({ id: userContact.userId }).catch(() => {
|
||||
logger.error('Could not find corresponding Login User')
|
||||
throw new Error('Could not find corresponding Login User')
|
||||
})
|
||||
const user = userContact.user
|
||||
logger.debug('user with EmailVerificationCode found...')
|
||||
|
||||
// Generate Passphrase if needed
|
||||
@ -902,13 +882,7 @@ async function findUserByEmail(email: string): Promise<DbUser> {
|
||||
throw new Error('No user with this credentials')
|
||||
})
|
||||
const dbUser = dbUserContact.user
|
||||
/*
|
||||
const dbUser = await DbUser.findOneOrFail({ id: userId }, { withDeleted: true }).catch(() => {
|
||||
logger.error(`User with emailContact=${email} connected per userId=${userId} does not exist`)
|
||||
throw new Error('No user with this credentials')
|
||||
})
|
||||
dbUser.emailContact = dbUserContact
|
||||
*/
|
||||
return dbUser
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ import { createContributionLink } from '@/seeds/graphql/mutations'
|
||||
import { login } from '@/seeds/graphql/queries'
|
||||
import { ContributionLink } from '@model/ContributionLink'
|
||||
import { ContributionLinkInterface } from '@/seeds/contributionLink/ContributionLinkInterface'
|
||||
import { User } from '@/graphql/model/User'
|
||||
|
||||
export const contributionLinkFactory = async (
|
||||
client: ApolloServerTestClient,
|
||||
@ -11,7 +12,10 @@ export const contributionLinkFactory = async (
|
||||
const { mutate, query } = client
|
||||
|
||||
// login as admin
|
||||
await query({ query: login, variables: { email: 'peter@lustig.de', password: 'Aa12345_' } })
|
||||
const user = await query({
|
||||
query: login,
|
||||
variables: { email: 'peter@lustig.de', password: 'Aa12345_' },
|
||||
})
|
||||
|
||||
const variables = {
|
||||
amount: contributionLink.amount,
|
||||
|
||||
@ -17,10 +17,10 @@ export const userFactory = async (
|
||||
} = await mutate({ mutation: createUser, variables: user })
|
||||
// console.log('creatUser:', { id }, { user })
|
||||
// get user from database
|
||||
let dbUser = await User.findOneOrFail({ id })
|
||||
let dbUser = await User.findOneOrFail({ id }, { relations: ['emailContact']})
|
||||
// console.log('dbUser:', dbUser)
|
||||
|
||||
const emailContact = await UserContact.findOneOrFail({ userId: id })
|
||||
const emailContact = dbUser.emailContact
|
||||
// console.log('emailContact:', emailContact)
|
||||
|
||||
if (user.emailChecked) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user