Skip to content

Commit

Permalink
handle noContentType correctly for fetch adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
aelittaezugbaya committed Dec 11, 2023
1 parent f5d0e5d commit e6d5583
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/oats-fetch-adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function toRequestData(data: runtime.server.RequestBody<any> | undefined) {

function getContentType(response: Response) {
const type = response.headers.get('content-type');
if (!type) {
if (!type || type === runtime.noContentContentType) {
return runtime.noContentContentType;
}
if (response.status === 204) {
Expand Down
23 changes: 23 additions & 0 deletions test/fetch-adapter/fetch-adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,27 @@ describe('fetch adapter', () => {
value: { one: 'the loneliest number' }
});
});

it('correctly calls PATCH(or any) request with noContentType', async () => {
const response = await apiClient['with-patch'].patch({
status: 204,
body: {
contentType: runtime.noContentContentType,
value: { one: 'the loneliest number' }
}
});

expect(response.status).toBe(204);
expect(response.value.contentType).toBe(runtime.noContentContentType);
expect(response.value.value).toBe('done');

expect(receivedContext).toBeDefined();
expect(receivedContext.method).toEqual('patch');
expect(receivedContext.path).toEqual('/with-patch');
expect(receivedContext.headers).toEqual(null);
expect(receivedContext.body).toEqual({
contentType: runtime.noContentContentType,
value: { one: 'the loneliest number' }
});
});
});

0 comments on commit e6d5583

Please sign in to comment.