Explain the query is trying to do
[gitter.git] / test / request-web-tests / export / room-users-export-tests.js
blobe30851efbdaadbb58a032c5f1fd716756d6b33d0
1 'use strict';
3 process.env.DISABLE_MATRIX_BRIDGE = '1';
4 process.env.DISABLE_API_LISTEN = '1';
5 process.env.DISABLE_API_WEB_LISTEN = '1';
6 process.env.TEST_EXPORT_RATE_LIMIT = 100;
8 const fixtureLoader = require('gitter-web-test-utils/lib/test-fixtures');
9 const assert = require('assert');
10 const request = require('supertest');
12 const app = require('../../../server/web');
14 describe('room-users-export-api', function() {
15   fixtureLoader.ensureIntegrationEnvironment('#oauthTokens');
17   before(function() {
18     if (this._skipFixtureSetup) return;
19   });
21   var fixture = fixtureLoader.setup({
22     user1: {
23       accessToken: 'web-internal'
24     },
25     user2: {
26       accessToken: 'web-internal'
27     },
28     userNoExport1: {
29       accessToken: 'web-internal'
30     },
31     troupe1: {
32       users: ['user1', 'user2'],
33       securityDescriptor: {
34         admins: 'MANUAL',
35         extraAdmins: ['user1']
36       }
37     },
38     troupeNoExport1: {
39       users: ['userNoExport1']
40     }
41   });
43   it('GET /api_web/export/rooms/:room_id/users.ndjson as admin works', function() {
44     return request(app)
45       .get(`/api_web/export/rooms/${fixture.troupe1.id}/users.ndjson`)
46       .set('Accept', 'application/x-ndjson,application/json')
47       .set('Authorization', `Bearer ${fixture.user1.accessToken}`)
48       .expect(200)
49       .then(function(result) {
50         assert.strictEqual(
51           result.text.split('\n').length,
52           3,
53           'includes 2 users (extra newline at the end)'
54         );
55         assert(result.text.includes(fixture.user1.id), 'includes user1');
56         assert(result.text.includes(fixture.user2.id), 'includes user2');
57         assert(
58           result.text.includes(`"username":"${fixture.user1.username}"`),
59           'make sure it serializes the user itself and not just raw troupe-user'
60         );
61         assert(!result.text.includes(fixture.userNoExport1.id), 'does not include userNoExport1');
62       });
63   });
64 });