Skip to content

Commit f14eeea

Browse files
committed
fix: Api.execute method for namedAction should make request with POST instead of PUT
1 parent 27000c7 commit f14eeea

3 files changed

Lines changed: 24 additions & 17 deletions

File tree

src/Api.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,16 @@ export class Api {
194194
endPoint += '/' + objID + '/' + action
195195
}
196196
else {
197-
actionArgs = actionArgs || {}
198-
actionArgs['action'] = action
197+
endPoint += '?method='+ Api.Methods.PUT +'&action=' + action
199198
}
200-
return this.request(endPoint, actionArgs, null, Api.Methods.PUT)
199+
const JSONstringifiedArgs = JSON.stringify(actionArgs)
200+
let params = null
201+
if (JSONstringifiedArgs) {
202+
params = {
203+
updates: JSONstringifiedArgs
204+
}
205+
}
206+
return this.request(endPoint, params, null, Api.Methods.POST)
201207
}
202208

203209
/**
@@ -364,7 +370,7 @@ export class Api {
364370
a.push(k + '=' + encodeURIComponent(params[k]))
365371
return a
366372
}, []).join('&')
367-
if (method === Api.Methods.GET || method === Api.Methods.PUT) {
373+
if (method === Api.Methods.GET) {
368374
if (bodyParams) {
369375
queryString = '?' + bodyParams
370376
}

test/integration/edit.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ describe('Edit', function() {
5555
return this.api.edit(objCode, objID, params).then(function(data) {
5656
const [url, opts] = fetchMock.lastCall('edit')
5757
should(opts.method).equal('PUT')
58-
should(url).endWith(objCode + '/' + objID + '?name=' + encodeURIComponent('api test 2'))
59-
should(opts.body).be.null()
58+
should(url).endWith(objCode + '/' + objID)
59+
should(opts.body).containEql('name=' + encodeURIComponent('api test 2'))
6060

6161
should(data).have.properties(['ID', 'name', 'objCode'])
6262
should(data.objCode).equal(objCode)

test/integration/execute.spec.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,35 +49,36 @@ describe('Execute', function() {
4949
return this.api.execute('foo', 'bar', 'baz').then(function(data) {
5050
const [url, opts] = fetchMock.lastCall('execute')
5151
should(url).endWith('foo/bar/baz')
52-
should(opts.method).equal('PUT')
52+
should(opts.method).equal('POST')
5353
})
5454
})
5555

5656
it('should call request() with proper params (with args)', function() {
5757
return this.api.execute('foo', 'bar', 'baz', {foo: 'barbaz'}).then(function(data) {
5858
const [url, opts] = fetchMock.lastCall('execute')
59-
should(url).containEql('foo/bar/baz')
60-
should(url).containEql('foo=barbaz')
61-
should(opts.body).be.null()
62-
should(opts.method).equal('PUT')
59+
should(url).endWith('foo/bar/baz')
60+
should(opts.body).containEql(`updates=${encodeURIComponent(JSON.stringify({foo: 'barbaz'}))}`)
61+
should(opts.method).equal('POST')
6362
})
6463
})
6564

6665
it('should call request() with proper params (with args) when objID is omitted', function() {
6766
return this.api.execute('foo', null, 'baz', {foo: 'barbaz'}).then(function(data) {
6867
const [url, opts] = fetchMock.lastCall('execute')
69-
should(url).endWith('foo?foo=barbaz&action=baz')
70-
should(opts.body).be.null()
71-
should(opts.method).equal('PUT')
68+
should(url).containEql('method=PUT')
69+
should(url).containEql('action=baz')
70+
should(opts.body).containEql(`updates=${encodeURIComponent(JSON.stringify({foo: 'barbaz'}))}`)
71+
should(opts.method).equal('POST')
7272
})
7373
})
7474

7575
it('should call request() with proper params (without args) when objID is omitted', function() {
7676
return this.api.execute('foo', null, 'baz').then(function(data) {
7777
const [url, opts] = fetchMock.lastCall('execute')
78-
should(url).endWith('foo?action=baz')
79-
should(opts.body).be.null()
80-
should(opts.method).equal('PUT')
78+
should(url).containEql('action=baz')
79+
should(url).containEql('method=PUT')
80+
should(opts.body).not.be.ok()
81+
should(opts.method).equal('POST')
8182
})
8283
})
8384
})

0 commit comments

Comments
 (0)