Skip to content

Commit

Permalink
[@typespec/spector] - Modify checks for headers & parameters (#4751)
Browse files Browse the repository at this point in the history
As a continuation of #4725,
while working on removing the handler for the scenarios in the
`typespec-azure` repository, I found some scenarios need added fix in
the `spector` library.

This PR consists of 2 changes:

1. The header keys must be changed to lowercase before reading and
comparing.
2. If the headers and parameters are array values, then we need to
handle them seperately.

I have tested this change with all the scenarios in both the `typespec`
and `typespec-azure` repositories. Once this change is merged, I can
open the PR for the scenario changes in `typespec-azure` repository.

Please review and approve this PR. Thanks
  • Loading branch information
sarangan12 authored Oct 15, 2024
1 parent 115d155 commit e78f52e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/spector/src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,23 @@ function createHandler(apiDefinition: MockApiDefinition) {
if (apiDefinition.request.headers) {
Object.entries(apiDefinition.request.headers).forEach(([key, value]) => {
if (key !== "Content-Type") {
req.expect.containsHeader(key, value as string);
if (Array.isArray(value)) {
req.expect.deepEqual(req.headers[key], value);
} else {
req.expect.containsHeader(key.toLowerCase(), String(value));
}
}
});
}

// Validate query params if present in the request
if (apiDefinition.request.params) {
Object.entries(apiDefinition.request.params).forEach(([key, value]) => {
req.expect.containsQueryParam(key, value as string);
if (Array.isArray(value)) {
req.expect.deepEqual(req.query[key], value);
} else {
req.expect.containsQueryParam(key, String(value));
}
});
}

Expand Down

0 comments on commit e78f52e

Please sign in to comment.