Skip to content

Commit

Permalink
test: update test to return default content-type
Browse files Browse the repository at this point in the history
  • Loading branch information
XVincentX committed Apr 16, 2019
1 parent 4257b79 commit 24a19a0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ Object {
}
`;

exports[`http mocker request is valid HttpOperation contains example the media type requested does not match the example throw exception 1`] = `[Error: Requested content type is not defined in the schema]`;

exports[`http mocker request is valid given enforced example key and mediaType should return 200 response 1`] = `
Object {
"body": "{ \\"root\\": \\"second\\" }",
Expand Down
19 changes: 8 additions & 11 deletions packages/http/src/mocker/__tests__/functional.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { httpOperations, httpRequests } from '../../__tests__/fixtures';
import { JSONSchemaExampleGenerator } from '../generator/JSONSchemaExampleGenerator';
import { HttpMocker } from '../index';

// TODO: Turn examples into test cases -> https://stoplightio.atlassian.net/wiki/spaces/PN/pages/5996560/Prism+Feature+List+draft
describe('http mocker', () => {
const mocker = new HttpMocker(new JSONSchemaExampleGenerator());

Expand All @@ -25,20 +24,17 @@ describe('http mocker', () => {
expect(response).toMatchSnapshot();
});

test('and that content type does not exist should throw', () => {
const rejection = mocker.mock({
test('and that content type does not exist should return empty body', () => {

return expect(mocker.mock({
resource: httpOperations[0],
input: httpRequests[0],
config: {
mock: {
mediaType: 'text/funky',
},
},
});

return expect(rejection).rejects.toEqual(
new Error('Requested content type is not defined in the schema')
);
})).resolves.toMatchObject({ headers: { 'Content-type': 'application/json' } });
});
});

Expand Down Expand Up @@ -180,16 +176,17 @@ describe('http mocker', () => {

describe('the media type requested does not match the example', () => {
test('throw exception', () => {
const rejection = mocker.mock({

return expect(mocker.mock({
resource: httpOperations[0],
input: Object.assign({}, httpRequests[0], {
data: Object.assign({}, httpRequests[0].data, {
headers: { 'Content-type': 'application/yaml' },
}),
}),
})).resolves.toMatchObject({
headers: { 'Content-type': 'application/json' }
});

return expect(rejection).rejects.toMatchSnapshot();
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,13 @@ describe('NegotiatorHelpers', () => {
headers: [],
};

expect(() =>
expect(
helpers.negotiateOptionsBySpecificResponse(
httpOperation,
desiredOptions,
httpResponseSchema
)
).toThrow('Requested content type is not defined in the schema');
).toHaveProperty('mediaType', 'text/plain');
});
});

Expand Down Expand Up @@ -596,7 +596,7 @@ describe('NegotiatorHelpers', () => {
helpers.negotiateByPartialOptionsAndHttpContent(partialOptions, httpContent);
}).toThrow(
`Response for contentType: ${
httpContent.mediaType
httpContent.mediaType
} and exampleKey: ${exampleKey} does not exist.`
);
});
Expand Down Expand Up @@ -642,7 +642,7 @@ describe('NegotiatorHelpers', () => {
helpers.negotiateByPartialOptionsAndHttpContent(partialOptions, httpContent);
}).toThrow(
`Tried to force a dynamic response for: ${
httpContent.mediaType
httpContent.mediaType
} but schema is not defined.`
);
});
Expand Down

0 comments on commit 24a19a0

Please sign in to comment.