-
-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add "application/protobuf" handling test (#1443)
Co-authored-by: Daniel Gollings <[email protected]> Co-authored-by: Artem Zakharchenko <[email protected]>
- Loading branch information
1 parent
5d01b40
commit c652d90
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
test/node/rest-api/request/body/body-protobuf.node.test.ts
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,38 @@ | ||
// @vitest-environment node | ||
import { http, HttpResponse } from 'msw' | ||
import { setupServer } from 'msw/node' | ||
|
||
const server = setupServer( | ||
http.post('https://example.com/protobuf', async ({ request }) => { | ||
const buffer = await request.arrayBuffer() | ||
|
||
return new HttpResponse(new Uint8Array(buffer), { | ||
headers: { | ||
'Content-Type': 'application/protobuf', | ||
}, | ||
}) | ||
}), | ||
) | ||
|
||
beforeAll(() => { | ||
server.listen() | ||
}) | ||
|
||
afterAll(() => { | ||
server.close() | ||
}) | ||
|
||
it('responds with a "application/protobuf" mocked response', async () => { | ||
const payload = new Uint8Array([138, 1, 6, 10, 4, 10, 2, 32, 1]) | ||
|
||
const response = await fetch('https://example.com/protobuf', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/protobuf', | ||
}, | ||
body: payload, | ||
}) | ||
const body = await response.arrayBuffer() | ||
|
||
expect(new Uint8Array(body)).toEqual(payload) | ||
}) |