-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate 'data' for 'body', and respect existing query strings (#11)
* Deprecate 'data' in favor of 'body' * Fix 'query' to use existing query string if present * Linting * Add tests for deprecated data option * Upgrade deps * Color the deprecation warning yellow
- Loading branch information
1 parent
f8f3dca
commit 5999855
Showing
16 changed files
with
312 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const { expect } = require('chai') | ||
const property = require('prop-factory') | ||
const stream = require('stream') | ||
|
||
const gimme = require('..') | ||
const { url } = require('./00-setup') | ||
|
||
describe('body', () => { | ||
const body = { foo: 'bar' } | ||
const res = property() | ||
|
||
beforeEach(() => { | ||
res(undefined) | ||
}) | ||
|
||
describe('when body is not a stream', () => { | ||
beforeEach(() => | ||
gimme({ body, method: 'POST', url }).then(res) | ||
) | ||
|
||
it('serializes it in the request body', () => | ||
expect(res().body.body).to.eql(body) | ||
) | ||
}) | ||
|
||
describe('when body is a stream', () => { | ||
const body = new stream.PassThrough() | ||
const value = 'some streamed body' | ||
|
||
beforeEach(() => { | ||
const promise = gimme({ | ||
body, | ||
deserialize: JSON.parse, | ||
json: false, | ||
method: 'POST', | ||
url | ||
}).then(res) | ||
|
||
body.end(value) | ||
return promise | ||
}) | ||
|
||
it('pipes the body into the request', () => | ||
expect(res().body.body).to.equal(value) | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,26 @@ | ||
const { expect } = require('chai') | ||
const property = require('prop-factory') | ||
const stream = require('stream') | ||
|
||
const gimme = require('..') | ||
const { url } = require('./00-setup') | ||
|
||
describe('data', () => { | ||
const data = { foo: 'bar' } | ||
const res = property() | ||
const body = { baz: 'bop' } | ||
const res = property() | ||
|
||
beforeEach(() => { | ||
res(undefined) | ||
}) | ||
|
||
describe('when method is not GET', () => { | ||
describe('and data is not a stream', () => { | ||
beforeEach(() => | ||
gimme({ data, method: 'POST', url }).then(res) | ||
) | ||
beforeEach(() => | ||
gimme({ data: body, method: 'POST', url }).then(res) | ||
) | ||
|
||
it('serializes it in the request body', () => | ||
expect(res().body.body).to.eql(data) | ||
) | ||
}) | ||
it('is used for non-GET request body', () => | ||
expect(res().body.body).to.eql(body) | ||
) | ||
|
||
describe('and data is a stream', () => { | ||
const data = new stream.PassThrough() | ||
const value = 'some streamed data' | ||
|
||
beforeEach(() => { | ||
const promise = gimme({ | ||
data, | ||
deserialize: JSON.parse, | ||
json: false, | ||
method: 'POST', | ||
url | ||
}).then(res) | ||
|
||
data.end(value) | ||
return promise | ||
}) | ||
|
||
it('pipes the data into the request', () => | ||
expect(res().body.body).to.equal(value) | ||
) | ||
}) | ||
}) | ||
it('is deprecated', () => | ||
expect(console.warn.calls[0][0]).to.include('deprecated') | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.