Skip to content

Commit

Permalink
[Fix] Add a to the formatRequest test
Browse files Browse the repository at this point in the history
  • Loading branch information
jennypavlova committed Nov 29, 2024
1 parent fd589b8 commit 2e66949
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@
import { formatRequest } from './format_request';

describe('formatRequest', () => {
const version = 1;
it('should return the correct path if the optional or required param is provided', () => {
const pathParams = { param: 'testParam' };
const resultOptionalEnd = formatRequest('GET /api/endpoint/{param?}', pathParams);
const resultOptionalEnd = formatRequest(`GET /api/endpoint/{param?} ${version}`, pathParams);
expect(resultOptionalEnd.pathname).toBe('/api/endpoint/testParam');
const resultRequiredEnd = formatRequest('GET /api/endpoint/{param}', pathParams);
const resultRequiredEnd = formatRequest(`GET /api/endpoint/{param} ${version}`, pathParams);
expect(resultRequiredEnd.pathname).toBe('/api/endpoint/testParam');
});
it('should return the correct path if the only an optional param is provided', () => {
const resultOptEnd = formatRequest('GET /api/endpoint/{id?}', { id: 123 });
const resultOptEnd = formatRequest(`GET /api/endpoint/{id?} ${version}`, { id: 123 });
expect(resultOptEnd.pathname).toBe('/api/endpoint/123');
});
it('should return the correct path if the optional param is not provided', () => {
const pathParams = {};
const resultEnd = formatRequest('GET /api/endpoint/{pathParamReq?}', pathParams);
const resultEnd = formatRequest(`GET /api/endpoint/{pathParamReq?} ${version}`, pathParams);
expect(resultEnd.pathname).toBe('/api/endpoint');
});
});

0 comments on commit 2e66949

Please sign in to comment.