Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Build on top of #163 to add support for falsy query and header values…
Browse files Browse the repository at this point in the history
… as well
  • Loading branch information
domharrington committed Oct 19, 2018
1 parent b70fb90 commit afbf934
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
40 changes: 39 additions & 1 deletion packages/api-explorer/__tests__/lib/oas-to-har.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ describe('path values', () => {
).toBe('https://example.com/param-path/456');
});

test('should add non-undefined values to the url', () => {
test('should add falsy values to the url', () => {
expect(
oasToHar(
{},
Expand Down Expand Up @@ -271,6 +271,25 @@ describe('query values', () => {
).log.entries[0].request.queryString,
).toEqual([{ name: 'a', value: 'test' }]);
});

test('should add falsy values to the querystring', () => {
expect(
oasToHar(
{},
{
path: '/param-path',
method: 'get',
parameters: [
{
name: 'id',
in: 'query'
},
],
},
{ query: { id: 0 } },
).log.entries[0].request.queryString,
).toEqual([{ name: 'id', value: '0' }]);
});
});

describe('header values', () => {
Expand Down Expand Up @@ -389,6 +408,25 @@ describe('header values', () => {
).log.entries[0].request.headers,
).toEqual([{ name: 'Accept', value: 'application/xml' }]);
});

test('should add falsy values to the headers', () => {
expect(
oasToHar(
{},
{
path: '/param-path',
method: 'get',
parameters: [
{
name: 'id',
in: 'header'
},
],
},
{ header: { id: 0 } },
).log.entries[0].request.headers,
).toEqual([{ name: 'id', value: '0' }]);
});
});

const pathOperation = {
Expand Down
4 changes: 2 additions & 2 deletions packages/api-explorer/src/lib/oas-to-har.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ module.exports = (
if (queryStrings && queryStrings.length) {
queryStrings.forEach(queryString => {
const value = formatter(formData, queryString, 'query', true);
if (!value) return;
if (typeof value === 'undefined') return;
har.queryString.push({
name: queryString.name,
value: String(value),
Expand Down Expand Up @@ -152,7 +152,7 @@ module.exports = (
if (headers && headers.length) {
headers.forEach(header => {
const value = formatter(formData, header, 'header', true);
if (!value) return;
if (typeof value === 'undefined') return;
har.headers.push({
name: header.name,
value: String(value),
Expand Down

0 comments on commit afbf934

Please sign in to comment.