Skip to content

Commit

Permalink
test: add "application/protobuf" handling test (#1443)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Gollings <[email protected]>
Co-authored-by: Artem Zakharchenko <[email protected]>
  • Loading branch information
3 people authored Nov 16, 2023
1 parent 5d01b40 commit c652d90
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/node/rest-api/request/body/body-protobuf.node.test.ts
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)
})

0 comments on commit c652d90

Please sign in to comment.