Skip to content

Commit

Permalink
fix: remove path params when provided via API level options (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Jun 25, 2019
1 parent 90d807e commit 96d940a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/apirequest.ts
Expand Up @@ -160,6 +160,13 @@ async function createAPIRequestAsync<T>(parameters: APIRequestParams) {
// query
parameters.pathParams.forEach(param => {
delete params[param];
if (
parameters.context &&
parameters.context._options &&
parameters.context._options.params
) {
delete parameters.context._options.params[param];
}
});

// if authClient is actually a string, use it as an API KEY
Expand Down
25 changes: 25 additions & 0 deletions test/test.apirequest.ts
Expand Up @@ -229,5 +229,30 @@ describe('createAPIRequest', () => {
assert.strictEqual(res.config.headers!['Global-Header'], 'global');
assert.strictEqual(res.config.headers!['Local-Header'], 'local');
});

it('should remove path params from the querystring when set in API level options', async () => {
const optUrl = `${url}/projects/{projectId}`;
const projectId = 'not-a-project';
const path = `/projects/${projectId}`;
const scope = nock(url)
.get(path)
.reply(200);
const res = await createAPIRequest<FakeParams>({
options: {url: optUrl},
params: {},
requiredParams: [],
pathParams: ['projectId'],
context: {
_options: {
params: {
projectId,
},
},
},
});
scope.done();
const expectedUrl = `${url}/projects/${projectId}`;
assert.strictEqual(res.config.url, expectedUrl);
});
});
});

0 comments on commit 96d940a

Please sign in to comment.