This repository has been archived by the owner on Dec 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(converter): fix mismatching content-type header with data type (#17)
closes #15
- Loading branch information
Showing
10 changed files
with
218 additions
and
210 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
const { encodeSample } = require('../src'); | ||
const { encodePayload } = require('../src'); | ||
|
||
test('Test encodeSample for application/json', function() { | ||
test('Test encodePayload for application/json', function() { | ||
const jsonSample = { | ||
name: 'Tom', | ||
surname: 'Trailer', | ||
age: 22 | ||
}; | ||
|
||
const jsonEncoded = encodeSample(jsonSample, 'application/json', {}); | ||
expect(jsonEncoded).toEqual(JSON.stringify(jsonSample)); | ||
const jsonEncoded = encodePayload(jsonSample, 'application/json', {}); | ||
expect(jsonEncoded.text).toEqual(JSON.stringify(jsonSample)); | ||
}); |
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,12 +1,12 @@ | ||
const { encodeSample } = require('../src'); | ||
const { encodePayload } = require('../src'); | ||
const querystring = require('querystring'); | ||
|
||
test('Test encodeSample for application/x-www-form-urlencoded', function() { | ||
test('Test encodePayload for application/x-www-form-urlencoded', function() { | ||
const querystringSample = { | ||
name: 'Tom', | ||
surname: 'Trailer', | ||
age: 22 | ||
}; | ||
const queryStringEncoded = encodeSample(querystringSample, 'application/x-www-form-urlencoded', {}); | ||
expect(queryStringEncoded).toEqual(querystring.stringify(querystringSample)); | ||
const queryStringEncoded = encodePayload(querystringSample, 'application/x-www-form-urlencoded', {}); | ||
expect(queryStringEncoded.text).toEqual(querystring.stringify(querystringSample)); | ||
}); |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
const { encodeSample } = require('../src'); | ||
const { encodePayload } = require('../src'); | ||
|
||
test('Test encodeSample for image/*', function() { | ||
const pngSample = encodeSample({}, 'image/png', {}); | ||
const jpgSample = encodeSample({}, 'image/jpg', {}); | ||
test('Test encodePayload for image/*', function() { | ||
const pngSample = encodePayload({}, 'image/png', {}); | ||
const jpgSample = encodePayload({}, 'image/jpg', {}); | ||
|
||
expect(atob(pngSample).includes('PNG')).toEqual(true); | ||
expect(atob(jpgSample).includes('ÿØÿÛ')).toEqual(true); | ||
expect(atob(pngSample.text).includes('PNG')).toEqual(true); | ||
expect(atob(jpgSample.text).includes('ÿØÿÛ')).toEqual(true); | ||
}); |
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 |
---|---|---|
@@ -1,49 +1,44 @@ | ||
const {encodeSample} = require('../src'); | ||
const { encodePayload } = require('../src') | ||
|
||
test('Test encodeSample for multipart/form-data', function () { | ||
test('Test encodePayload for multipart/form-data', function() { | ||
const multipartMixin = { | ||
user: { | ||
username: 'john', | ||
password: 'password' | ||
}, | ||
token: 'user_token', | ||
amount: 100, | ||
buffer: 'base65' | ||
}; | ||
buffer: Buffer.from('base65').toString('base64') | ||
} | ||
|
||
const content = { | ||
encoding: { | ||
user: { | ||
contentType: 'application/json' | ||
}, | ||
token: { | ||
contentType: 'text/plain' | ||
}, | ||
buffer: { | ||
contentType: 'application/octet-stream' | ||
} | ||
user: { | ||
contentType: 'application/json' | ||
}, | ||
buffer: { | ||
contentType: 'application/octet-stream' | ||
} | ||
}; | ||
|
||
const multipartMixinExpected = '--956888039105887155673143\r\n' + | ||
'Content-Disposition: form-data; name="user"\r\n'+ | ||
'Content-Type: application/json\r\n\r\n'+ | ||
'{"username":"john","password":"password"}\r\n'+ | ||
'--956888039105887155673143\r\n'+ | ||
'Content-Disposition: form-data; name="token"\r\n'+ | ||
'Content-Type: text/plain\r\n\r\n'+ | ||
'dXNlcl90b2tlbg==\r\n'+ | ||
'--956888039105887155673143\r\n'+ | ||
'Content-Disposition: form-data; name="amount"\r\n'+ | ||
'Content-Type: text/plain\r\n\r\n'+ | ||
'100\r\n'+ | ||
'--956888039105887155673143\r\n'+ | ||
'Content-Disposition: form-data; name="buffer"; filename="buffer"\r\n'+ | ||
'Content-Type: application/octet-stream\r\n\r\n'+ | ||
'YmFzZTY1\r\n'+ | ||
'--956888039105887155673143--'; | ||
const multipartMixinEncoded = encodeSample(multipartMixin, 'multipart/mixin', content); | ||
} | ||
|
||
expect(multipartMixinEncoded).toEqual(multipartMixinExpected); | ||
const multipartMixinExpected = | ||
'--956888039105887155673143\r\n' + | ||
'Content-Disposition: form-data; name="user"\r\n' + | ||
'Content-Type: application/json\r\n\r\n' + | ||
'{"username":"john","password":"password"}\r\n' + | ||
'--956888039105887155673143\r\n' + | ||
'Content-Disposition: form-data; name="token"\r\n\r\n' + | ||
'user_token\r\n' + | ||
'--956888039105887155673143\r\n' + | ||
'Content-Disposition: form-data; name="amount"\r\n\r\n' + | ||
'100\r\n' + | ||
'--956888039105887155673143\r\n' + | ||
'Content-Disposition: form-data; name="buffer"; filename="buffer"\r\n' + | ||
'Content-Type: application/octet-stream\r\n' + | ||
'Content-Transfer-Encoding: base64\r\n\r\n' + | ||
'YmFzZTY1\r\n' + | ||
'--956888039105887155673143--' | ||
const multipartMixinEncoded = encodePayload(multipartMixin, 'multipart/mixin', content) | ||
|
||
}); | ||
expect(multipartMixinEncoded.text).toEqual(multipartMixinExpected) | ||
expect(multipartMixinEncoded.mimeType).toEqual('multipart/mixin; boundary=956888039105887155673143') | ||
}) |
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,7 +1,7 @@ | ||
const { encodeSample } = require('../src'); | ||
const { encodePayload } = require('../src'); | ||
|
||
test('Test encodeSample for text/plain', function() { | ||
test('Test encodePayload for text/plain', function() { | ||
const primitiveSample = 'primitive'; | ||
const primitiveEncoded = encodeSample(primitiveSample, '*/*', {}); | ||
expect(primitiveEncoded).toEqual(Buffer.from(primitiveSample).toString('base64')); | ||
const primitiveEncoded = encodePayload(primitiveSample, '*/*'); | ||
expect(primitiveEncoded.text).toEqual(primitiveSample); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.