fake sendMail in sign up test
This commit is contained in:
committed by
Jackson Harper
parent
638294e17b
commit
d284a3d302
@ -100,7 +100,7 @@ export const createUser = async (input: {
|
||||
const confirmationLink = `${env.client.url}/confirm-email/${confirmationToken}`
|
||||
// send email
|
||||
const sent = await sendEmail({
|
||||
from: env.sender.general,
|
||||
from: env.sender.message,
|
||||
to: user.email,
|
||||
subject: 'Confirm your email',
|
||||
text: `Please confirm your email by clicking the link below:\n\n${confirmationLink}\n\n`,
|
||||
|
||||
@ -10,6 +10,9 @@ import {
|
||||
import { User } from '../../src/entity/user'
|
||||
import { hashPassword } from '../../src/utils/auth'
|
||||
import 'mocha'
|
||||
import { MailDataRequired } from '@sendgrid/helpers/classes/mail'
|
||||
import sinon from 'sinon'
|
||||
import * as util from '../../src/utils/sendEmail'
|
||||
|
||||
describe('User API', () => {
|
||||
const username = 'fake_user'
|
||||
@ -360,30 +363,29 @@ describe('User API', () => {
|
||||
})
|
||||
|
||||
context('when inputs are valid and user not exists', () => {
|
||||
let fake: (msg: MailDataRequired) => Promise<boolean>
|
||||
|
||||
beforeEach(() => {
|
||||
password = correctPassword
|
||||
username = 'Some_username'
|
||||
email = `${username}@fake.com`
|
||||
fake = sinon.replace(util, 'sendEmail', sinon.fake.resolves(true))
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await deleteTestUser(username)
|
||||
sinon.restore()
|
||||
})
|
||||
|
||||
it('responds with 200', async () => {
|
||||
return graphqlRequest(query).expect(200)
|
||||
})
|
||||
|
||||
it('returns the user', async () => {
|
||||
const res = await graphqlRequest(query).send()
|
||||
expect(res.body.data.signup.me.profile.username).to.eql(username)
|
||||
})
|
||||
|
||||
it('creates user with correct username', async () => {
|
||||
const res = await graphqlRequest(query).send()
|
||||
|
||||
const user = await getUser(res.body.data.signup.me.id)
|
||||
expect(user?.profile?.username).to.eql(username)
|
||||
it('returns the user with the lowercase username', async () => {
|
||||
const res = await graphqlRequest(query).expect(200)
|
||||
expect(res.body.data.signup.me.profile.username).to.eql(
|
||||
username.toLowerCase()
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -72,10 +72,11 @@ describe('create a user with pending confirmation', () => {
|
||||
await deleteTestUser(name)
|
||||
})
|
||||
|
||||
it('creates a user with pending status', async () => {
|
||||
it('creates the user with pending status and correct name', async () => {
|
||||
const user = await createTestUser(name, undefined, undefined, true)
|
||||
|
||||
expect(user.status).to.equal(StatusType.Pending)
|
||||
expect(user.status).to.eql(StatusType.Pending)
|
||||
expect(user.name).to.eql(name)
|
||||
})
|
||||
|
||||
it('sends an email to the user', async () => {
|
||||
|
||||
Reference in New Issue
Block a user