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

Commit

Permalink
Modify tests to pass for an unmodified har
Browse files Browse the repository at this point in the history
  • Loading branch information
uppal101 committed Sep 29, 2017
1 parent 8843177 commit bbe9386
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 29 deletions.
62 changes: 35 additions & 27 deletions packages/api-explorer-ui/__tests__/lib/oas-to-har.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@ const oasToHar = require('../../src/lib/oas-to-har');

test('should output a har format', () => {
expect(oasToHar({})).toEqual({
headers: [{ name: 'Content-Type', value: 'application/json' }],
queryString: [],
postData: {},
method: '',
url: '',
entries: [
{
request: {
headers: [{ name: 'Content-Type', value: 'application/json' }],
method: '',
postData: {},
queryString: [],
url: '',
},
},
],
});
});

test('should uppercase the method', () => {
expect(oasToHar({}, { path: '/', method: 'get' }).method).toBe('GET');
expect(oasToHar({}, { path: '/', method: 'get' }).entries[0].request.method).toBe('GET');
});

describe('url', () => {
test('should default to ""', () => {
expect(oasToHar({}, { path: '', method: '' }).url).toBe('');
expect(oasToHar({}, { path: '/path', method: '' }).url).toBe('/path');
expect(oasToHar({}, { path: '', method: '' }).entries[0].request.url).toBe('');
expect(oasToHar({}, { path: '/path', method: '' }).entries[0].request.url).toBe('/path');
});

test('should be constructed from servers[0]', () => {
Expand All @@ -27,7 +33,7 @@ describe('url', () => {
servers: [{ url: 'http://example.com' }],
},
{ path: '/path', method: 'get' },
).url,
).entries[0].request.url,
).toBe('http://example.com/path');
});

Expand All @@ -38,7 +44,7 @@ describe('url', () => {
servers: [{ url: 'http://example.com' }],
},
{ path: '/path with spaces', method: '' },
).url,
).entries[0].request.url,
).toBe('http://example.com/path%20with%20spaces');
});

Expand All @@ -47,7 +53,9 @@ describe('url', () => {

describe('path values', () => {
test('should pass through unknown path params', () => {
expect(oasToHar({}, { path: '/param-path/{id}', method: '' }).url).toBe('/param-path/id');
expect(oasToHar({}, { path: '/param-path/{id}', method: '' }).entries[0].request.url).toBe(
'/param-path/id',
);
expect(
oasToHar(
{},
Expand All @@ -62,7 +70,7 @@ describe('path values', () => {
},
],
},
).url,
).entries[0].request.url,
).toBe('/param-path/id');
});

Expand All @@ -82,7 +90,7 @@ describe('path values', () => {
],
},
{},
).url,
).entries[0].request.url,
).toBe('/param-path/id');
});

Expand All @@ -102,7 +110,7 @@ describe('path values', () => {
},
],
},
).url,
).entries[0].request.url,
).toBe('/param-path/123');
});

Expand All @@ -122,7 +130,7 @@ describe('path values', () => {
],
},
{ path: { id: '456' } },
).url,
).entries[0].request.url,
).toBe('/param-path/456');
});
});
Expand All @@ -142,7 +150,7 @@ describe('query values', () => {
},
],
},
).queryString,
).entries[0].request.queryString,
).toEqual([]);
});

Expand All @@ -162,7 +170,7 @@ describe('query values', () => {
},
],
},
).queryString,
).entries[0].request.queryString,
).toEqual([{ name: 'a', value: 'value' }]);
});

Expand All @@ -183,7 +191,7 @@ describe('query values', () => {
],
},
{ query: { a: 'test' } },
).queryString,
).entries[0].request.queryString,
).toEqual([{ name: 'a', value: 'test' }]);
});
});
Expand All @@ -203,7 +211,7 @@ describe('header values', () => {
},
],
},
).headers,
).entries[0].request.headers,
).toEqual([{ name: 'Content-Type', value: 'application/json' }]);
});

Expand All @@ -223,7 +231,7 @@ describe('header values', () => {
},
],
},
).headers,
).entries[0].request.headers,
).toEqual([{ name: 'a', value: 'value' }, { name: 'Content-Type', value: 'application/json' }]);
});

Expand All @@ -244,7 +252,7 @@ describe('header values', () => {
],
},
{ header: { a: 'test' } },
).headers,
).entries[0].request.headers,
).toEqual([{ name: 'a', value: 'test' }, { name: 'Content-Type', value: 'application/json' }]);
});
});
Expand Down Expand Up @@ -272,7 +280,7 @@ describe('body values', () => {
},
},
},
).postData.text,
).entries[0].request.postData.text,
).toEqual(undefined);
});

Expand Down Expand Up @@ -301,7 +309,7 @@ describe('body values', () => {
},
},
},
).postData.text,
).entries[0].request.postData.text,
).toEqual(JSON.stringify({ a: 'value' }));
});

Expand Down Expand Up @@ -330,7 +338,7 @@ describe('body values', () => {
},
},
{ body: { a: 'test' } },
).postData.text,
).entries[0].request.postData.text,
).toEqual(JSON.stringify({ a: 'test' }));
});
});
Expand Down Expand Up @@ -362,7 +370,7 @@ describe('auth', () => {
'auth-header': 'value',
},
},
).headers,
).entries[0].request.headers,
).toEqual([
{
name: 'Content-Type',
Expand Down Expand Up @@ -399,7 +407,7 @@ describe('auth', () => {
'auth-query': 'value',
},
},
).queryString,
).entries[0].request.queryString,
).toEqual([
{
name: 'authQuery',
Expand Down Expand Up @@ -430,7 +438,7 @@ describe('auth', () => {
security: [{ 'auth-header': [] }],
},
{ auth: {} },
).headers,
).entries[0].request.headers,
).toEqual([{ name: 'Content-Type', value: 'application/json' }]);
});
});
2 changes: 1 addition & 1 deletion packages/api-explorer-ui/src/lib/generate-code-snippets.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const supportedLanguages = {

module.exports = (oas, operation, values, languages) => {
const har = generateHar(oas, operation, values);
const snippet = new HTTPSnippet(har);
const snippet = new HTTPSnippet(har.entries[0].request);

return languages.reduce((snippets, lang) => {
const language = supportedLanguages[lang];
Expand Down
2 changes: 1 addition & 1 deletion packages/api-explorer-ui/src/lib/oas-to-har.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,5 @@ module.exports = (oas, pathOperation = { path: '', method: '' }, values = {}) =>
har[securityValue.type].push(securityValue.value);
});
}
return har;
return { entries: [{ request: har }] };
};

0 comments on commit bbe9386

Please sign in to comment.