Merge branch 'hotfix/21.56.9' into master
[gitter.git] / test / request-web-tests / export / user-uri-lookups-export-tests.js
blob2a3dc1f0d1191bb8f9a58d9af177ae6add4955cf
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');
13 const uriLookupService = require('gitter-web-uri-resolver/lib/uri-lookup-service');
15 describe('user-uri-lookups-export-api', function() {
16   fixtureLoader.ensureIntegrationEnvironment('#oauthTokens');
18   before(function() {
19     if (this._skipFixtureSetup) return;
20   });
22   var fixture = fixtureLoader.setup({
23     user1: {
24       accessToken: 'web-internal'
25     },
26     userNoExport1: {
27       accessToken: 'web-internal'
28     },
29     troupe1: {},
30     troupe2: {},
31     troupeNoExport1: {}
32   });
34   it('GET /api_web/export/user/:user_id/uri-lookups.ndjson as same user gets data', async () => {
35     await uriLookupService.reserveUriForUsername(fixture.user1.id, fixture.user1.username);
36     await uriLookupService.reserveUriForUsername(
37       fixture.userNoExport1.id,
38       fixture.userNoExport1.username
39     );
41     return request(app)
42       .get(`/api_web/export/user/${fixture.user1.id}/uri-lookups.ndjson`)
43       .set('Accept', 'application/x-ndjson,application/json')
44       .set('Authorization', `Bearer ${fixture.user1.accessToken}`)
45       .expect(200)
46       .then(function(result) {
47         assert.strictEqual(
48           result.text.split('\n').length,
49           2,
50           'includes 1 URI lookup for user (extra newline at the end)'
51         );
52         assert(result.text.includes(fixture.user1.id), 'includes user1');
53         assert(!result.text.includes(fixture.userNoExport1.id), 'does not include userNoExport1');
54       });
55   });
56 });