Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('returns true', () => {
expect(matrixStyleDeserializer.supports(HttpParamStyles.Matrix)).toBe(true);
});
});
it('generates matrix style', () => {
assertRight(
createExamplePath({
id: '123',
path: '/path/{p}',
method: 'get',
request: { path: [{ name: 'p', style: HttpParamStyles.Matrix, examples: [{ key: 'foo', value: 'test' }] }] },
responses: [{ code: '200' }],
}),
r => expect(r).toEqual('/path/;p=test')
);
});
});
it('generates correct path', () => {
assertRight(
createExamplePath({
id: '123',
path: '/path/{p1}/{p2}/{p3}',
method: 'get',
request: {
path: [
{ name: 'p1', style: HttpParamStyles.Simple, examples: [{ key: 'foo', value: 'test1' }] },
{ name: 'p2', style: HttpParamStyles.Label, examples: [{ key: 'foo', value: ['test1', 'test2'] }] },
{ name: 'p3', style: HttpParamStyles.Matrix, examples: [{ key: 'foo', value: ['test1', 'test2'] }] },
],
query: [
{ name: 'q1', style: HttpParamStyles.Form, examples: [{ key: 'foo', value: 'test1' }] },
{
name: 'q2',
style: HttpParamStyles.SpaceDelimited,
examples: [{ key: 'foo', value: ['test1', 'test2'] }],
},
{
name: 'q3',
style: HttpParamStyles.PipeDelimited,
examples: [{ key: 'foo', value: ['test1', 'test2'] }],
},
{
name: 'q4',
style: HttpParamStyles.PipeDelimited,
it('calls the path validator', () => {
validator.validateInput({
resource: {
method: 'get',
path: '/a/{a}/b/{b}',
id: '1',
request: {
path: [
{ name: 'a', style: HttpParamStyles.Simple },
{ name: 'b', style: HttpParamStyles.Matrix },
],
},
responses: [{ code: '200' }],
},
element: { method: 'get', url: { path: '/a/1/b/;b=2' } },
});
expect(validator.pathValidator.validate).toHaveBeenCalledWith({ a: '1', b: ';b=2' }, [
{ name: 'a', style: HttpParamStyles.Simple },
{ name: 'b', style: HttpParamStyles.Matrix },
]);
});
});
path: '/a/{a}/b/{b}',
id: '1',
request: {
path: [
{ name: 'a', style: HttpParamStyles.Simple },
{ name: 'b', style: HttpParamStyles.Matrix },
],
},
responses: [{ code: '200' }],
},
element: { method: 'get', url: { path: '/a/1/b/;b=2' } },
});
expect(validator.pathValidator.validate).toHaveBeenCalledWith({ a: '1', b: ';b=2' }, [
{ name: 'a', style: HttpParamStyles.Simple },
{ name: 'b', style: HttpParamStyles.Matrix },
]);
});
});
function createParamUriTemplate(name: string, style: HttpParamStyles, explode: boolean) {
const starOrVoid = explode ? '*' : '';
switch (style) {
case HttpParamStyles.Simple:
return E.right(`{${name}${starOrVoid}}`);
case HttpParamStyles.Label:
return E.right(`{.${name}${starOrVoid}}`);
case HttpParamStyles.Matrix:
return E.right(`{;${name}${starOrVoid}}`);
default:
return E.left(new Error(`Unsupported parameter style: ${style}`));
}
}
public supports(style: HttpParamStyles) {
return style === HttpParamStyles.Matrix;
}