Skip to content

Commit 32986c3

Browse files
author
Joe Wiggins
committed
Fixing tests around changing to JSON bodies
1 parent 9541662 commit 32986c3

7 files changed

Lines changed: 16 additions & 17 deletions

File tree

src/Api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ export class Api {
385385
headers.append('Content-Type', 'application/json')
386386
bodyParams = JSON.stringify(params)
387387
if (options.method === Api.Methods.GET) {
388-
if (bodyParams) {
388+
if (bodyParams && Object.keys(params).length > 0) {
389389
queryString = '?' + Object.keys(params).reduce(function(a, k) {
390390
a.push(k + '=' + encodeURIComponent(params[k]))
391391
return a

test/integration/copy.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('Copy', function() {
5050
const [url, opts] = fetchMock.lastCall('copy')
5151
should(url).endWith('foo')
5252
should(opts.method).equal('POST')
53-
should(opts.body).containEql('copySourceID=bar')
53+
should(opts.body).containEql('{"copySourceID":"bar"}')
5454
})
5555
})
5656
it('returns data with a new ID', function() {

test/integration/create.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ describe('Create', function() {
5656
const [url, opts] = fetchMock.lastCall('create')
5757
should(url).endWith(objCode)
5858
should(opts.method).equal('POST')
59-
should(opts.body).containEql('foo=bar')
60-
should(opts.body).containEql(encodeURIComponent(fields.join(',')))
59+
should(opts.body).containEql('{"foo":"bar","fields":"*,zzz:*"}')
6160
})
6261
})
6362
it('should return the new created object', function() {

test/integration/edit.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('Edit', function() {
5858
should(opts.method).equal('PUT')
5959
should(url).endWith(objCode + '/' + objID)
6060
should(opts.headers.get('apiKey')).equal('testapikey')
61-
should(opts.body).containEql('name=' + encodeURIComponent('api test 2'))
61+
should(opts.body).containEql(JSON.stringify(params))
6262

6363
should(data).have.properties(['ID', 'name', 'objCode'])
6464
should(data.objCode).equal(objCode)

test/integration/editUsingGet.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ describe('Edit', function() {
5757
return this.api.edit(objCode, objID, params).then(function(data) {
5858
const [url, opts] = fetchMock.lastCall('edit')
5959
should(opts.method).equal('GET')
60-
should(url).endWith(objCode + '/' + objID)
60+
should(url).containEql(objCode + '/' + objID)
6161
should(opts.headers.get('apiKey')).equal('testapikey')
62-
should(opts.body).containEql('name=' + encodeURIComponent('api test 2'))
63-
should(opts.body).containEql('method=PUT')
62+
should(opts.body).equal(null)
63+
should(url).containEql('name=' + encodeURIComponent('api test 2') + '&method=PUT')
6464

6565
should(data).have.properties(['ID', 'name', 'objCode'])
6666
should(data.objCode).equal(objCode)

test/integration/execute.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('Execute', function() {
4949
return this.api.execute('foo', 'bar', 'baz').then(function() {
5050
const [url, opts] = fetchMock.lastCall('execute')
5151
should(url).endWith('foo/bar/baz')
52-
should(opts.body).equal('')
52+
should(opts.body).equal('{}')
5353
should(opts.method).equal('POST')
5454
})
5555
})
@@ -58,7 +58,7 @@ describe('Execute', function() {
5858
return this.api.execute('foo', 'bar', 'baz', {foo: 'barbaz'}).then(function() {
5959
const [url, opts] = fetchMock.lastCall('execute')
6060
should(url).endWith('foo/bar/baz')
61-
should(opts.body).containEql('foo=barbaz')
61+
should(opts.body).containEql('{"foo":"barbaz"}')
6262
should(opts.method).equal('POST')
6363
})
6464
})
@@ -67,9 +67,9 @@ describe('Execute', function() {
6767
return this.api.execute('foo', null, 'baz', {foo: 'barbaz'}).then(function() {
6868
const [url, opts] = fetchMock.lastCall('execute')
6969
should(url).endWith('foo')
70-
should(opts.body).containEql('action=baz')
71-
should(opts.body).containEql('foo=barbaz')
72-
should(opts.body).containEql('method=PUT')
70+
should(opts.body).containEql('"action":"baz"')
71+
should(opts.body).containEql('"foo":"barbaz"')
72+
should(opts.body).containEql('"method":"PUT"')
7373
should(opts.method).equal('POST')
7474
})
7575
})
@@ -78,9 +78,9 @@ describe('Execute', function() {
7878
return this.api.execute('foo', null, 'baz').then(function() {
7979
const [url, opts] = fetchMock.lastCall('execute')
8080
should(url).endWith('foo')
81-
should(opts.body).containEql('action=baz')
81+
should(opts.body).containEql('"action":"baz"')
8282
should(opts.method).equal('POST')
83-
should(opts.body).containEql('method=PUT')
83+
should(opts.body).containEql('"method":"PUT"')
8484
})
8585
})
8686
})

test/integration/login.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ describe('Login', function() {
6666
this.api.login('foo', 'bar')
6767
const [url, opts] = fetchMock.lastCall('login')
6868
should(url).endWith('login')
69-
should(opts.body).containEql('username=foo')
70-
should(opts.body).containEql('password=bar')
69+
should(opts.body).containEql('"username":"foo"')
70+
should(opts.body).containEql('"password":"bar"')
7171
})
7272
})
7373
describe('authentication exception', function() {

0 commit comments

Comments
 (0)