Skip to content

Commit ab0ee77

Browse files
committed
feat: add a new boolean argument in report method to force POST request
1 parent ec6a8cf commit ab0ee77

2 files changed

Lines changed: 33 additions & 16 deletions

File tree

src/Api.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,20 @@ export class Api {
387387
* @memberOf Api
388388
* @param {String} objCode One of object codes from {@link https://developers.workfront.com/api-docs/api-explorer/|Workfront API Explorer}
389389
* @param {Object} query An object with search criteria and aggregate functions
390+
* @param {Boolean} [useHttpPost=false] Whenever to use POST to send query params
390391
* @return {Promise} A promise which will resolved with results if everything went ok and rejected otherwise
391392
*/
392-
report(objCode: string, query: object) {
393-
return this.request(objCode + '/report', query, null, Api.Methods.GET)
393+
report(objCode: string, query: object, useHttpPost = false) {
394+
let reportQuery, method
395+
if (useHttpPost) {
396+
reportQuery = {...query, method: Api.Methods.GET}
397+
method = Api.Methods.POST
398+
}
399+
else {
400+
reportQuery = query
401+
method = Api.Methods.GET
402+
}
403+
return this.request(objCode + '/report', reportQuery, null, method)
394404
}
395405

396406
/**

test/integration/report.spec.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import fixture from '../../fixtures/report.json'
2424
const API_URL = 'http://foobar:8080'
2525

2626
describe('Report', function() {
27-
2827
afterEach(fetchMock.reset)
2928
afterEach(fetchMock.restore)
3029

@@ -38,26 +37,34 @@ describe('Report', function() {
3837
})
3938

4039
beforeEach(function() {
41-
fetchMock.mock(
42-
`begin:${API_URL}/attask/api`,
43-
fixture,
44-
{
45-
name: 'report'
46-
}
47-
)
40+
fetchMock.mock(`begin:${API_URL}/attask/api`, fixture, {
41+
name: 'report'
42+
})
4843
})
44+
const objCode = 'TASK',
45+
query = {
46+
['status' + GROUPBY]: true
47+
}
4948
it('makes a request with proper params, url and method', function() {
50-
const objCode = 'TASK',
51-
query = {
52-
['status' + GROUPBY]: true
53-
}
5449
return this.api.report(objCode, query).then(function(data) {
5550
const [url, opts] = fetchMock.lastCall('report')
5651
should(opts.method).equal('GET')
5752
should(opts.body).be.null()
5853
should(url).endWith(`${objCode}/report?status${GROUPBY}=true`)
59-
should(data).have.propertyByPath('CPL', 'dcount_ID').be.Number()
60-
should(data.CPL).have.property('status').be.equal('CPL')
54+
should(data)
55+
.have.propertyByPath('CPL', 'dcount_ID')
56+
.be.Number()
57+
should(data.CPL)
58+
.have.property('status')
59+
.be.equal('CPL')
60+
})
61+
})
62+
it('should do a request with POST method when the useHttpPost=true', function() {
63+
return this.api.report(objCode, query, true).then(function() {
64+
const [url, opts] = fetchMock.lastCall('report')
65+
should(url).endWith(`${objCode}/report`)
66+
should(opts.method).equal('POST')
67+
should(opts.body).equals(`status${GROUPBY}=true&method=GET`)
6168
})
6269
})
6370
})

0 commit comments

Comments
 (0)