-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fromOpenApi): support response headers (#14)
* chore(tsconfig): remove path aliases * feat(fromOpenApi): support response headers
- Loading branch information
1 parent
fcd8019
commit 996915a
Showing
4 changed files
with
81 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import fetch from 'cross-fetch' | ||
import { Headers } from 'headers-utils' | ||
import { fromOpenApi } from '../../src/fromOpenApi/fromOpenApi' | ||
import { createOpenApiSpec } from '../../test/support/createOpenApiSpec' | ||
import { withHandlers } from '../support/withHandlers' | ||
|
||
it('supports response headers', async () => { | ||
const handlers = await fromOpenApi( | ||
createOpenApiSpec({ | ||
paths: { | ||
'/user': { | ||
get: { | ||
responses: { | ||
200: { | ||
headers: { | ||
'X-Rate-Limit-Remaining': { | ||
schema: { | ||
type: 'number', | ||
}, | ||
}, | ||
'X-Rate-Limit-Reset': { | ||
schema: { | ||
type: 'string', | ||
format: 'date-time', | ||
}, | ||
}, | ||
}, | ||
content: { | ||
'text/plain': { | ||
schema: { | ||
type: 'string', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}), | ||
) | ||
|
||
const res = await withHandlers(handlers, () => { | ||
return fetch('http://localhost/user') | ||
}) | ||
|
||
expect(res.status).toEqual(200) | ||
const headers = new Headers(res.headers) | ||
|
||
expect(headers.all()).toEqual({ | ||
'content-type': 'text/plain', | ||
'x-powered-by': 'msw', | ||
// Header values are always strings. | ||
'x-rate-limit-remaining': expect.any(String), | ||
'x-rate-limit-reset': expect.stringMatching( | ||
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+?Z$/, | ||
), | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters