Skip to content

Commit ec6a8cf

Browse files
committed
fix: do batch call to non-GET methods
Batch call were restricted to do only GET type methods (i.e. search, metadata, get) With this fix you can do more than that, like create, edit, execute
1 parent c916bc4 commit ec6a8cf

4 files changed

Lines changed: 57 additions & 23 deletions

File tree

package-lock.json

Lines changed: 27 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"test:karma": "karma start karma.conf.js",
6161
"test:mocha": "mocha -r ts-node/register/transpile-only test/*.spec.ts",
6262
"e2e": "CI=true mocha --no-timeouts test/e2e.test.js",
63-
"debug": "npm run test -- --auto-watch --browsers Chrome --no-single-run",
63+
"debug": "npm run test:karma -- --auto-watch --browsers Chrome --no-single-run",
6464
"build": "rollup -c && tsc --emitDeclarationOnly -p ./tsconfig.json -d --declarationDir ./typings",
6565
"docs": "rm -rf ./docs/ && typedoc --out ./docs/ ./src/ --excludePrivate --excludeExternals --exclude \"**/*.spec.ts\" && touch ./docs/.nojekyll",
6666
"prepublish": "npm run build",

src/Api.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,11 @@ export class Api {
410410
): Promise<any> {
411411
const clonedParams = {...params}
412412

413-
const options = this.getOptions(path, clonedParams, method)
413+
const options = this.getOptions(
414+
path,
415+
clonedParams,
416+
this._uriGenerationMode ? Api.Methods.GET : method
417+
)
414418

415419
const stringifiedFields = this.getFields(fields)
416420
if (stringifiedFields) {
@@ -428,9 +432,13 @@ export class Api {
428432
}
429433

430434
if (this._uriGenerationMode) {
435+
let appendGetMethod = ''
436+
if (queryString.indexOf('method=') === -1) {
437+
appendGetMethod = (queryString === '' ? '?' : '&') + 'method=' + Api.Methods.GET
438+
}
431439
// @ts-ignore-line
432440
return (
433-
path + queryString + (queryString === '' ? '?' : '&') + 'method=' + Api.Methods.GET
441+
path + queryString + appendGetMethod
434442
)
435443
}
436444
return makeFetchCall(options.url + options.path + queryString, {

test/integration/batch.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,23 @@ describe('Batch', function() {
103103
should(match).has.length(3, 'should have 3 method=GET params')
104104
})
105105
})
106+
describe('Populate proper "uri" for "execute" method without objID', function() {
107+
beforeEach(function () {
108+
this.api.batch(
109+
batchApi => [
110+
batchApi.execute('user', null, 'activateUsers', {userIDs: ['foo', 'bar']})
111+
]
112+
)
113+
})
114+
115+
it('should request POST /batch', function () {
116+
should(fetchMock.lastUrl()).equal(API_URL + '/attask/api-internal/batch')
117+
should(fetchMock.lastOptions()).have.property('method', 'POST')
118+
})
119+
it('has exact body params', function () {
120+
const {body} = fetchMock.lastOptions()
121+
const expectedString = 'atomic=false&uri=user%3Fmethod%3DPUT%26action%3DactivateUsers%26userIDs%3Dfoo%26userIDs%3Dbar'
122+
should(body).equals(expectedString)
123+
})
124+
})
106125
})

0 commit comments

Comments
 (0)