mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
test sendActivationEmail
This commit is contained in:
parent
b12865abf8
commit
a88585086c
@ -19,6 +19,7 @@ import {
|
|||||||
setUserRole,
|
setUserRole,
|
||||||
deleteUser,
|
deleteUser,
|
||||||
unDeleteUser,
|
unDeleteUser,
|
||||||
|
sendActivationEmail,
|
||||||
} from '@/seeds/graphql/mutations'
|
} from '@/seeds/graphql/mutations'
|
||||||
import { verifyLogin, queryOptIn, searchAdminUsers, searchUsers } from '@/seeds/graphql/queries'
|
import { verifyLogin, queryOptIn, searchAdminUsers, searchUsers } from '@/seeds/graphql/queries'
|
||||||
import { GraphQLError } from 'graphql'
|
import { GraphQLError } from 'graphql'
|
||||||
@ -176,7 +177,7 @@ describe('UserResolver', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('stores the register event in the database', async () => {
|
it('stores the REGISTER event in the database', async () => {
|
||||||
const userConatct = await UserContact.findOneOrFail(
|
const userConatct = await UserContact.findOneOrFail(
|
||||||
{ email: 'peter@lustig.de' },
|
{ email: 'peter@lustig.de' },
|
||||||
{ relations: ['user'] },
|
{ relations: ['user'] },
|
||||||
@ -209,7 +210,7 @@ describe('UserResolver', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('stores the send confirmation event in the database', () => {
|
it('stores the SEND_CONFIRMATION_EMAIL event in the database', () => {
|
||||||
expect(EventProtocol.find()).resolves.toContainEqual(
|
expect(EventProtocol.find()).resolves.toContainEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
type: EventProtocolType.SEND_CONFIRMATION_EMAIL,
|
type: EventProtocolType.SEND_CONFIRMATION_EMAIL,
|
||||||
@ -250,7 +251,7 @@ describe('UserResolver', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('stores the send account multi registration email event in the database', async () => {
|
it('stores the SEND_ACCOUNT_MULTIREGISTRATION_EMAIL event in the database', async () => {
|
||||||
const userConatct = await UserContact.findOneOrFail(
|
const userConatct = await UserContact.findOneOrFail(
|
||||||
{ email: 'peter@lustig.de' },
|
{ email: 'peter@lustig.de' },
|
||||||
{ relations: ['user'] },
|
{ relations: ['user'] },
|
||||||
@ -354,7 +355,7 @@ describe('UserResolver', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('stores the account activated event in the database', () => {
|
it('stores the ACTIVATE_ACCOUNT event in the database', () => {
|
||||||
expect(EventProtocol.find()).resolves.toContainEqual(
|
expect(EventProtocol.find()).resolves.toContainEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
type: EventProtocolType.ACTIVATE_ACCOUNT,
|
type: EventProtocolType.ACTIVATE_ACCOUNT,
|
||||||
@ -363,7 +364,7 @@ describe('UserResolver', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('stores the redeem register event in the database', () => {
|
it('stores the REDEEM_REGISTER event in the database', () => {
|
||||||
expect(EventProtocol.find()).resolves.toContainEqual(
|
expect(EventProtocol.find()).resolves.toContainEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
type: EventProtocolType.REDEEM_REGISTER,
|
type: EventProtocolType.REDEEM_REGISTER,
|
||||||
@ -447,7 +448,7 @@ describe('UserResolver', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('stores the redeem register event in the database', async () => {
|
it('stores the REDEEM_REGISTER event in the database', async () => {
|
||||||
await expect(EventProtocol.find()).resolves.toContainEqual(
|
await expect(EventProtocol.find()).resolves.toContainEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
type: EventProtocolType.REDEEM_REGISTER,
|
type: EventProtocolType.REDEEM_REGISTER,
|
||||||
@ -674,7 +675,7 @@ describe('UserResolver', () => {
|
|||||||
expect(headerPushMock).toBeCalledWith({ key: 'token', value: expect.any(String) })
|
expect(headerPushMock).toBeCalledWith({ key: 'token', value: expect.any(String) })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('stores the login event in the database', async () => {
|
it('stores the LOGIN event in the database', async () => {
|
||||||
const userConatct = await UserContact.findOneOrFail(
|
const userConatct = await UserContact.findOneOrFail(
|
||||||
{ email: 'bibi@bloxberg.de' },
|
{ email: 'bibi@bloxberg.de' },
|
||||||
{ relations: ['user'] },
|
{ relations: ['user'] },
|
||||||
@ -926,7 +927,7 @@ describe('UserResolver', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('stores the login event in the database', () => {
|
it('stores the LOGIN event in the database', () => {
|
||||||
expect(EventProtocol.find()).resolves.toContainEqual(
|
expect(EventProtocol.find()).resolves.toContainEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
type: EventProtocolType.LOGIN,
|
type: EventProtocolType.LOGIN,
|
||||||
@ -1707,6 +1708,135 @@ describe('UserResolver', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
///
|
||||||
|
|
||||||
|
describe('sendActivationEmail', () => {
|
||||||
|
describe('unauthenticated', () => {
|
||||||
|
it('returns an error', async () => {
|
||||||
|
await expect(
|
||||||
|
mutate({ mutation: sendActivationEmail, variables: { email: 'bibi@bloxberg.de' } }),
|
||||||
|
).resolves.toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
errors: [new GraphQLError('401 Unauthorized')],
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('authenticated', () => {
|
||||||
|
describe('without admin rights', () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
user = await userFactory(testEnv, bibiBloxberg)
|
||||||
|
await mutate({
|
||||||
|
mutation: login,
|
||||||
|
variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' },
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await cleanDB()
|
||||||
|
resetToken()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns an error', async () => {
|
||||||
|
await expect(
|
||||||
|
mutate({ mutation: sendActivationEmail, variables: { email: 'bibi@bloxberg.de' } }),
|
||||||
|
).resolves.toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
errors: [new GraphQLError('401 Unauthorized')],
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('with admin rights', () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
admin = await userFactory(testEnv, peterLustig)
|
||||||
|
await mutate({
|
||||||
|
mutation: login,
|
||||||
|
variables: { email: 'peter@lustig.de', password: 'Aa12345_' },
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await cleanDB()
|
||||||
|
resetToken()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('user does not exist', () => {
|
||||||
|
it('throws an error', async () => {
|
||||||
|
jest.clearAllMocks()
|
||||||
|
await expect(
|
||||||
|
mutate({ mutation: sendActivationEmail, variables: { email: 'INVALID' } }),
|
||||||
|
).resolves.toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
errors: [new GraphQLError('No user with this credentials')],
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('logs the error thrown', () => {
|
||||||
|
expect(logger.error).toBeCalledWith('No user with this credentials', 'invalid')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('user is deleted', () => {
|
||||||
|
it('throws an error', async () => {
|
||||||
|
jest.clearAllMocks()
|
||||||
|
await userFactory(testEnv, stephenHawking)
|
||||||
|
await expect(
|
||||||
|
mutate({ mutation: sendActivationEmail, variables: { email: 'stephen@hawking.uk' } }),
|
||||||
|
).resolves.toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
errors: [new GraphQLError('User with given email contact is deleted')],
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('logs the error thrown', () => {
|
||||||
|
expect(logger.error).toBeCalledWith(
|
||||||
|
'User with given email contact is deleted',
|
||||||
|
'stephen@hawking.uk',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('sendActivationEmail with success', () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
user = await userFactory(testEnv, bibiBloxberg)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns true', async () => {
|
||||||
|
const result = await mutate({
|
||||||
|
mutation: sendActivationEmail,
|
||||||
|
variables: { email: 'bibi@bloxberg.de' },
|
||||||
|
})
|
||||||
|
expect(result).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
data: {
|
||||||
|
sendActivationEmail: true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('stores the ADMIN_SEND_CONFIRMATION_EMAIL event in the database', async () => {
|
||||||
|
const userConatct = await UserContact.findOneOrFail(
|
||||||
|
{ email: 'bibi@bloxberg.de' },
|
||||||
|
{ relations: ['user'] },
|
||||||
|
)
|
||||||
|
expect(EventProtocol.find()).resolves.toContainEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
type: EventProtocolType.ADMIN_SEND_CONFIRMATION_EMAIL,
|
||||||
|
userId: userConatct.user.id,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('unDelete user', () => {
|
describe('unDelete user', () => {
|
||||||
describe('unauthenticated', () => {
|
describe('unauthenticated', () => {
|
||||||
it('returns an error', async () => {
|
it('returns an error', async () => {
|
||||||
|
|||||||
@ -781,19 +781,12 @@ export class UserResolver {
|
|||||||
email = email.trim().toLowerCase()
|
email = email.trim().toLowerCase()
|
||||||
// const user = await dbUser.findOne({ id: emailContact.userId })
|
// const user = await dbUser.findOne({ id: emailContact.userId })
|
||||||
const user = await findUserByEmail(email)
|
const user = await findUserByEmail(email)
|
||||||
if (!user) {
|
if (user.deletedAt || user.emailContact.deletedAt) {
|
||||||
throw new LogError('Could not find user to given email contact', email)
|
|
||||||
}
|
|
||||||
if (user.deletedAt) {
|
|
||||||
throw new LogError('User with given email contact is deleted', email)
|
throw new LogError('User with given email contact is deleted', email)
|
||||||
}
|
}
|
||||||
const emailContact = user.emailContact
|
|
||||||
if (emailContact.deletedAt) {
|
|
||||||
throw new LogError('The given email contact for this user is deleted', email)
|
|
||||||
}
|
|
||||||
|
|
||||||
emailContact.emailResendCount++
|
user.emailContact.emailResendCount++
|
||||||
await emailContact.save()
|
await user.emailContact.save()
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const emailSent = await sendAccountActivationEmail({
|
const emailSent = await sendAccountActivationEmail({
|
||||||
@ -801,7 +794,7 @@ export class UserResolver {
|
|||||||
lastName: user.lastName,
|
lastName: user.lastName,
|
||||||
email,
|
email,
|
||||||
language: user.language,
|
language: user.language,
|
||||||
activationLink: activationLink(emailContact.emailVerificationCode),
|
activationLink: activationLink(user.emailContact.emailVerificationCode),
|
||||||
timeDurationObject: getTimeDurationObject(CONFIG.EMAIL_CODE_VALID_TIME),
|
timeDurationObject: getTimeDurationObject(CONFIG.EMAIL_CODE_VALID_TIME),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -68,6 +68,12 @@ export const createUser = gql`
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
export const sendActivationEmail = gql`
|
||||||
|
mutation ($email: String!) {
|
||||||
|
sendActivationEmail(email: $email)
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
export const sendCoins = gql`
|
export const sendCoins = gql`
|
||||||
mutation ($email: String!, $amount: Decimal!, $memo: String!) {
|
mutation ($email: String!, $amount: Decimal!, $memo: String!) {
|
||||||
sendCoins(email: $email, amount: $amount, memo: $memo)
|
sendCoins(email: $email, amount: $amount, memo: $memo)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user