Merge tag '21.36.0' into develop
[gitter.git] / test / request-api-tests / user-rooms-api-tests.js
blobfbacce80006bf0d1a4724e367bc026d8e489cd60
1 'use strict';
3 process.env.DISABLE_MATRIX_BRIDGE = '1';
4 process.env.DISABLE_API_LISTEN = '1';
6 var fixtureLoader = require('gitter-web-test-utils/lib/test-fixtures');
7 var assert = require('assert');
9 describe('user-rooms-api', function() {
10   var app, request;
12   before(function() {
13     request = require('supertest');
14     app = require('../../server/api');
15   });
17   var fixture = fixtureLoader.setup({
18     user1: { accessToken: 'web-internal' },
19     user2: { accessToken: 'web-internal' },
20     troupe1: {
21       security: 'PUBLIC',
22       users: ['user1']
23     },
24     troupe2: {
25       security: 'PRIVATE',
26       users: ['user1']
27     }
28   });
30   it('GET /v1/user/:userId/rooms', function() {
31     return request(app)
32       .get(`/v1/user/${fixture.user1.id}/rooms`)
33       .set('x-access-token', fixture.user1.accessToken)
34       .expect(200)
35       .then(function(result) {
36         var rooms = result.body;
38         assert(
39           rooms.some(function(r) {
40             return r.id === fixture.troupe1.id;
41           })
42         );
44         assert(
45           rooms.some(function(r) {
46             return r.id === fixture.troupe2.id;
47           })
48         );
50         assert.strictEqual(rooms.length, 2);
51       });
52   });
54   it('GET /v1/user/:userId/rooms/:roomId/unreadItems', function() {
55     return request(app)
56       .get(`/v1/user/${fixture.user1.id}/rooms/${fixture.troupe1.id}/unreadItems`)
57       .set('x-access-token', fixture.user1.accessToken)
58       .expect(200)
59       .then(function(result) {
60         var { chat, mention } = result.body;
62         assert.strictEqual(chat.length, 0);
63         assert.strictEqual(mention.length, 0);
64       });
65   });
67   it('PATCH /v1/user/:userId/rooms/:roomId', () => {
68     return request(app)
69       .put(`/v1/user/${fixture.user1.id}/rooms/${fixture.troupe2.id}`)
70       .set('x-access-token', fixture.user1.accessToken)
71       .send({ favourite: 1 })
72       .expect(200);
73   });
75   it('PATCH /v1/user/:userId/rooms/:roomId is forbidden for unauthorized user', () => {
76     return request(app)
77       .patch(`/v1/user/${fixture.user2.id}/rooms/${fixture.troupe2.id}`)
78       .set('x-access-token', fixture.user2.accessToken)
79       .expect(403);
80   });
81 });