3 var assert = require('assert');
4 var proxyquireNoCallThru = require('proxyquire').noCallThru();
5 var Promise = require('bluebird');
7 describe('assert-user-valid-in-room', function() {
8 var gitlabUser = { providers: ['gitlab'] };
9 var githubUser = { providers: ['github'] };
10 var twitterUser = { providers: ['twitter'] };
12 providers: ['github'],
17 var oneToOneRoom = { oneToOne: true, githubType: 'ONETOONE', security: 'PRIVATE' };
19 var assertUserValidInRoom = proxyquireNoCallThru('../lib/assert-user-valid-in-room', {
20 'gitter-web-identity': {
21 listProvidersForUser: function(user) {
22 return Promise.resolve(user.providers);
27 it('should not allow a user to join a github-only room if the user has a Twitter identity', function() {
28 return assertUserValidInRoom(githubRoom, twitterUser).then(
30 assert.ok(false, 'Expected an exception');
33 assert.strictEqual(err.status, 403);
38 it('should not allow a user to join a github-only room if the user has a GitLab identity', function() {
39 return assertUserValidInRoom(githubRoom, gitlabUser).then(
41 assert.ok(false, 'Expected an exception');
44 assert.strictEqual(err.status, 403);
49 it('should not allow a user who has not yet signed up to join a github-only room', function() {
50 return assertUserValidInRoom(githubRoom, null).then(
52 assert.ok(false, 'Expected an exception');
55 assert.strictEqual(err.status, 403);
60 it('should allow a user to join a github-only room if the user has a github identity', function() {
61 return assertUserValidInRoom(githubRoom, githubUser);
64 it('should pass through one-to-one rooms too', function() {
65 return assertUserValidInRoom(oneToOneRoom, twitterUser);
68 it('should pass through one-to-one rooms too', function() {
69 return assertUserValidInRoom(oneToOneRoom, gitlabUser);