Explain the query is trying to do
[gitter.git] / test / request-web-tests / export / user-oauth-clients-export-tests.js
blob1493ae1a90cd3a1afadd94e7e6fe1cabe0a22602
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('user-oauth-clients-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     userNoExport1: {
26       accessToken: 'web-internal'
27     },
28     oAuthClient1: {
29       ownerUser: 'user1'
30     },
31     oAuthClient2: {
32       ownerUser: 'user1'
33     },
34     oAuthClientNoExport1: {
35       ownerUser: 'userNoExport1'
36     }
37   });
39   it('GET /api_web/export/user/:user_id/oauth-clients.ndjson as same user gets data', async () => {
40     return request(app)
41       .get(`/api_web/export/user/${fixture.user1.id}/oauth-clients.ndjson`)
42       .set('Accept', 'application/x-ndjson,application/json')
43       .set('Authorization', `Bearer ${fixture.user1.accessToken}`)
44       .expect(200)
45       .then(function(result) {
46         assert.strictEqual(
47           result.text.split('\n').length,
48           3,
49           'includes 2 OAuth clients (extra newline at the end)'
50         );
51         assert(result.text.includes(fixture.oAuthClient1.id), 'includes oAuthClient1');
52         assert(result.text.includes(fixture.oAuthClient2.id), 'includes oAuthClient2');
53         assert(
54           !result.text.includes(fixture.oAuthClientNoExport1.id),
55           'does not include oAuthClientNoExport1'
56         );
57       });
58   });
59 });