Explain the query is trying to do
[gitter.git] / test / request-web-tests / export / user-settings-export-tests.js
blob10d2694a06eb4af0992b26d4f1b03685ff84ee0e
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 userSettingsService = require('gitter-web-user-settings');
15 describe('user-settings-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   });
31   it('GET /api_web/export/user/:user_id/user-settings.ndjson as same user gets data', async () => {
32     await userSettingsService.setUserSettings(fixture.user1.id, 'test', 'foobar');
33     await userSettingsService.setUserSettings(fixture.userNoExport1.id, 'test', 'noexport');
35     return request(app)
36       .get(`/api_web/export/user/${fixture.user1.id}/user-settings.ndjson`)
37       .set('Accept', 'application/x-ndjson,application/json')
38       .set('Authorization', `Bearer ${fixture.user1.accessToken}`)
39       .expect(200)
40       .then(function(result) {
41         assert.strictEqual(
42           result.text.split('\n').length,
43           2,
44           'includes 1 setting item (extra newline at the end)'
45         );
46         assert(result.text.includes('"test":"foobar"'), 'includes test user settings');
47       });
48   });
49 });