3 const assert = require('assert');
4 const env = require('gitter-web-env');
5 const config = env.config;
6 const fixtureLoader = require('gitter-web-test-utils/lib/test-fixtures');
7 const roomInviteService = require('../lib/room-invite-service');
9 const ROOM_INVITE_RATE_LIMIT_THRESHOLD = config.get('email:inviteEmailAbuseThresholdPerDay');
11 describe('room-context-service', () => {
12 var fixture = fixtureLoader.setup({
18 it('should invite existing user', async () => {
19 const result = await roomInviteService.createInvite(fixture.troupe1, fixture.userInviting1, {
21 externalId: fixture.user1.username,
22 emailAddress: undefined
25 assert.strictEqual(result.status, 'added');
26 assert.strictEqual(result.user.username, fixture.user1.username);
29 it('should invite someone by email', async () => {
30 const email = 'foo@gitter.im';
31 const result = await roomInviteService.createInvite(fixture.troupe1, fixture.userInviting1, {
37 assert.strictEqual(result.status, 'invited');
38 assert.strictEqual(result.emailAddress, email);
41 it('should be rate-limited when inviting many people by email', async () => {
43 for (var i = 0; i < ROOM_INVITE_RATE_LIMIT_THRESHOLD + 1; i++) {
44 const email = `foo${i}@gitter.im`;
45 await roomInviteService.createInvite(fixture.troupe1, fixture.userInviting1, {
53 assert(err.status, 501);