Skip to content

Commit

Permalink
[NEW] Add users.requestDataDownload API endpoint (#14428)
Browse files Browse the repository at this point in the history
* Add users.requestDataDownload API endpoint

* Fix request data download endpoint
  • Loading branch information
ubarsaiyan authored and rodrigok committed Oct 18, 2019
1 parent bdf4811 commit 81a504d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/api/server/v1/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,3 +671,15 @@ API.v1.addRoute('users.presence', { authRequired: true }, {
});
},
});

API.v1.addRoute('users.requestDataDownload', { authRequired: true }, {
get() {
const { fullExport = false } = this.queryParams;
const result = Meteor.runAsUser(this.userId, () => Meteor.call('requestDataDownload', { fullExport: fullExport === 'true' }));

return API.v1.success({
requested: result.requested,
exportOperation: result.exportOperation,
});
},
});
42 changes: 42 additions & 0 deletions tests/end-to-end/api/01-users.js
Original file line number Diff line number Diff line change
Expand Up @@ -1658,4 +1658,46 @@ describe('[Users]', function() {
});
});
});

describe('[/users.requestDataDownload]', () => {
it('should return the request data with fullExport false when no query parameter was send', (done) => {
request.get(api('users.requestDataDownload'))
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('requested');
expect(res.body).to.have.property('exportOperation').and.to.be.an('object');
expect(res.body.exportOperation).to.have.property('fullExport', false);
})
.end(done);
});
it('should return the request data with fullExport false when the fullExport query parameter is false', (done) => {
request.get(api('users.requestDataDownload?fullExport=false'))
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('requested');
expect(res.body).to.have.property('exportOperation').and.to.be.an('object');
expect(res.body.exportOperation).to.have.property('fullExport', false);
})
.end(done);
});
it('should return the request data with fullExport true when the fullExport query parameter is true', (done) => {
request.get(api('users.requestDataDownload?fullExport=true'))
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('requested');
expect(res.body).to.have.property('exportOperation').and.to.be.an('object');
expect(res.body.exportOperation).to.have.property('fullExport', true);
})
.end(done);
});
});
});

0 comments on commit 81a504d

Please sign in to comment.