Skip to content

Commit

Permalink
fix: unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpy committed May 25, 2020
1 parent 207404b commit 5d41358
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
4 changes: 3 additions & 1 deletion src/server/mautic/mauticAPI.js
Expand Up @@ -100,8 +100,10 @@ export const Mautic = {
},

sendMagicLinkEmail(user: UserRecord, magicLink: string) {
if (!(magicLink && user.fullName && user.mauticId && Config.mauticmagicLinkEmailId))
if (!(magicLink && user.fullName && user.mauticId && Config.mauticmagicLinkEmailId)) {
log.warn('missing input for sending magiclink', { magicLink, user, emailId: Config.mauticmagicLinkEmailId })
throw new Error('missing input for sending magicLink email')
}

return this.baseQuery(`/emails/${Config.mauticmagicLinkEmailId}/contact/${user.mauticId}/send`, this.baseHeaders, {
tokens: { link: magicLink, firstName: user.fullName }
Expand Down
51 changes: 22 additions & 29 deletions src/server/send/__tests__/sendAPI.js
Expand Up @@ -6,10 +6,19 @@ import request from 'supertest'
import makeServer from '../../server-test'
import { getToken } from '../../__util__/'
import UserDBPrivate from '../../db/mongo/user-privat-provider'
import { Mautic } from '../../mautic/mauticAPI'

describe('sendAPÏ', () => {
let server
beforeAll(done => {
beforeAll(async done => {
const res = await Mautic.createContact({ firstname: 'h', lastname: 'r', email: 'hadartest@gooddollar.org' })
const mauticId = res.contact.fields.all.id
//make sure fullname is set for user which is required for sending the recovery email
await UserDBPrivate.updateUser({
identifier: '0x7ac080f6607405705aed79675789701a48c76f55',
fullName: 'full name',
mauticId
})
jest.setTimeout(30000)
server = makeServer(done)
})
Expand Down Expand Up @@ -65,14 +74,6 @@ describe('sendAPÏ', () => {

test('/verify/sendemail with creds', async () => {
const token = await getToken(server)
//make sure fullname is set for user which is required for sending the recovery email
const user = await UserDBPrivate.updateUser({
identifier: '0x7ac080f6607405705aed79675789701a48c76f55',
fullName: 'full name',
mauticId: 5151
})

expect(user).toBeDefined()

await request(server)
.post('/send/recoveryinstructions')
Expand All @@ -83,6 +84,18 @@ describe('sendAPÏ', () => {
.expect(200, { ok: 1 })
})

test('/send/magiclink with creds', async () => {
const token = await getToken(server)

await request(server)
.post('/send/magiclink')
.send({
magiclink: 'unit test magicLink'
})
.set('Authorization', `Bearer ${token}`)
.expect(200, { ok: 1 })
})

test('/verify/sendemail without required fields should fail', async () => {
const token = await getToken(server)
//make sure mauticid is unset which is required
Expand Down Expand Up @@ -110,26 +123,6 @@ describe('sendAPÏ', () => {
.expect(401)
})

test('/send/magiclink with creds', async () => {
const token = await getToken(server)
//make sure fullname is set for user which is required for sending the recovery email
const user = await UserDBPrivate.updateUser({
identifier: '0x7ac080f6607405705aed79675789701a48c76f55',
fullName: 'full name',
mauticId: 5151
})

expect(user).toBeDefined()

await request(server)
.post('/send/magiclink')
.send({
magiclink: 'unit test magicLink'
})
.set('Authorization', `Bearer ${token}`)
.expect(200, { ok: 1 })
})

test('/send/magiclink without required fields should ok', async () => {
const token = await getToken(server)
//make sure fullname is set for user which is required for sending the recovery email
Expand Down

0 comments on commit 5d41358

Please sign in to comment.