Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
jest.spyOn(helpers, 'negotiateByPartialOptionsAndHttpContent').mockReturnValue(E.right(fakeOperationConfig));
const actualOperationConfig = helpers.negotiateDefaultMediaType(partialOptions, response);
expect(helpers.negotiateByPartialOptionsAndHttpContent).toHaveBeenCalledTimes(1);
expect(helpers.negotiateByPartialOptionsAndHttpContent).toHaveBeenCalledWith(
{
code,
dynamic: partialOptions.dynamic,
exampleKey: partialOptions.exampleKey,
},
contents[1] // Check that the */* has been requested
);
assertRight(actualOperationConfig, operationConfig => {
expect(operationConfig).toEqual(fakeOperationConfig);
});
});
});
it('prefers the first example', () =>
assertRight(eitherResponseWithMultipleExamples, responseWithMultipleExamples =>
expect(responseWithMultipleExamples.body).toHaveProperty('middlename', 'WW')
));
});
it('passes through', () => {
assertRight(
serializeBody(undefined),
result => expect(result).toBeUndefined(),
);
})
});
it('validates positively against schema', () => {
assertRight(
httpQueryValidator.validate({ param: 'abc' }, [
{
name: 'param',
style: HttpParamStyles.Form,
schema: { type: 'string' },
},
])
);
expect(validateAgainstSchemaModule.validateAgainstSchema).toReturnWith(O.none);
});
});
test('return lowest 2xx response and the first example matching the media type', () => {
const response = mock({
config: { dynamic: false },
resource: httpOperations[1],
input: Object.assign({}, httpRequests[0], {
data: Object.assign({}, httpRequests[0].data, {
headers: { accept: 'application/xml' },
}),
}),
})(logger);
assertRight(response, result => {
expect(result.statusCode).toBe(200);
expect(result.headers).toHaveProperty('x-todos-publish');
});
});
it('should use such key', () => {
assertRight(eitherResponse, response => expect(response.body).toHaveProperty('surname', 'Kent'));
});
});
it('does not return warnings', () => {
assertRight(
validateInput({
resource,
element: {
method: 'get',
url: {
path: '/test',
query: {},
},
},
})
);
});
});
it('prefers the default', () =>
assertRight(eitherResponseWithDefault, responseWithDefault =>
expect(responseWithDefault.body).toHaveProperty('middlename', 'JJ')
));
});
it('and cannot find example and dynamic does not exist throw error', () => {
const partialOptions = {
dynamic: false,
code: '200',
};
const httpContent: IMediaTypeContent = {
mediaType: chance.string(),
examples: [],
encodings: [],
};
const proposedResponse = helpers.negotiateByPartialOptionsAndHttpContent(partialOptions, httpContent);
assertRight(proposedResponse, response => {
expect(response).toHaveProperty('code');
expect(response).toHaveProperty('mediaType');
});
});
});
it('should take the first content type', () => {
assertRight(negotiationResult, result => {
expect(result.mediaType).toBe('application/xml');
});
});
});