Merge tag '21.36.0' into develop
[gitter.git] / test / request-api-tests / user-api-tests.js
blob069b16882b0cd83c2d3c2c5d2420062c49f82b42
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-api', function() {
10   var app, request;
12   fixtureLoader.ensureIntegrationEnvironment('#oauthTokens');
14   before(function() {
15     if (this._skipFixtureSetup) return;
17     request = require('supertest');
18     app = require('../../server/api');
19   });
21   var fixture = fixtureLoader.setupEach({
22     user1: {
23       accessToken: 'web-internal'
24     },
25     user2: {},
26     group1: {},
27     troupe1: {
28       security: 'PUBLIC',
29       group: 'group1',
30       users: ['user1', 'user2']
31     },
32     troupe2: {
33       security: 'PUBLIC',
34       group: 'group1',
35       users: ['user2']
36     }
37   });
39   it('GET /v1/user/:userId/suggestedRooms', function() {
40     return request(app)
41       .get('/v1/user/me/suggestedRooms')
42       .set('x-access-token', fixture.user1.accessToken)
43       .expect(200)
44       .then(function(result) {
45         // For now, this is a very loose test, to prove
46         // https://github.com/troupe/gitter-webapp/pull/2067
47         // We can extend it later
48         var suggestions = result.body;
49         assert(Array.isArray(suggestions));
50         assert(suggestions.length > 0);
51         suggestions.forEach(function(suggestion) {
52           assert(suggestion.hasOwnProperty('uri'));
53           assert(suggestion.hasOwnProperty('avatarUrl'));
54           assert(suggestion.hasOwnProperty('userCount'));
55           assert(suggestion.hasOwnProperty('tags'));
56           assert(suggestion.hasOwnProperty('description'));
57           assert(suggestion.hasOwnProperty('exists'));
58           assert(
59             (suggestion.exists === true && suggestion.id) ||
60               (suggestion.exists === false && !suggestion.id)
61           );
62         });
63       });
64   });
66   describe('DELETE /v1/user/:userId', () => {
67     it('should be successful', function() {
68       return request(app)
69         .delete('/v1/user/me')
70         .set('x-access-token', fixture.user1.accessToken)
71         .expect(200)
72         .then(function(result) {
73           assert.strictEqual(result.status, 200);
74           assert.deepEqual(result.body, {
75             success: true
76           });
77         });
78     });
80     it('should be successful with ghost option', function() {
81       return request(app)
82         .delete('/v1/user/me')
83         .send({
84           ghost: true
85         })
86         .set('x-access-token', fixture.user1.accessToken)
87         .expect(200)
88         .then(function(result) {
89           assert.strictEqual(result.status, 200);
90           assert.deepEqual(result.body, {
91             success: true
92           });
93         });
94     });
96     it('should clear access tokens', async function() {
97       // Delete the user
98       await request(app)
99         .delete('/v1/user/me')
100         .set('x-access-token', fixture.user1.accessToken)
101         .expect(200);
103       // Access token should no longer work
104       await request(app)
105         .get('/v1/user/me')
106         .set('x-access-token', fixture.user1.accessToken)
107         .expect(401);
108     });
109   });