Created
January 23, 2018 22:11
-
-
Save anomaly44/2535e8f61351182c8603dac3a2e3f3fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('dotenv').config(); | |
const { startWithCleanDb } = require('../../../utils/test.helpers'); | |
const { add } = require('../invitation.service'); | |
const { ADMIN_LEVELS, TABLES } = require('../../../constants'); | |
const { AuthorizationError } = require('../../../errors'); | |
const knex = require('../../../../db/connection'); | |
jest.mock('../../../mailer'); | |
const { sendUserInvitationMail } = require('../../../mailer'); | |
beforeEach(() => startWithCleanDb()); | |
sendUserInvitationMail.mockImplementation(() => console.log('Mocked mail function called')); | |
// sendUserInvitationMail(); | |
describe('invitation.service', () => { | |
describe('add', () => { | |
it('adds an invitation to the db', async () => { | |
expect.assertions(2); | |
const result = await add( | |
{ | |
email: 'tester@test.be', | |
badgeNumber: '344d33843', | |
}, | |
{ currentZoneId: 1 }, | |
ADMIN_LEVELS.ADMINISTRATOR, | |
); | |
const invitation = (await knex.select('*').from(TABLES.INVITATIONS))[0]; | |
expect(invitation.id).toEqual(result.id); | |
expect(invitation.email).toEqual(result.email); | |
}); | |
it('throws an authorization error when user does not have the required adminLevel', async () => { | |
expect.assertions(1); | |
return add( | |
{ | |
email: 'tester@test.be', | |
badgeNumber: '3434343843', | |
}, | |
{ currentZoneId: 1 }, | |
ADMIN_LEVELS.SITE_MANAGER, | |
).catch(e => expect(e).toBeInstanceOf(AuthorizationError)); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment