Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Commit

Permalink
Add new test for testing schemas that sepecify utf-8 encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
shinzui committed Apr 11, 2023
1 parent a18d47e commit 4a8ac40
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 3 deletions.
22 changes: 22 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,28 @@ describe('post()', () => {
expect(error).toBe(undefined);
});

it('supports sepecifying utf-8 encoding', async () => {
const mockData = { message: 'My reply' };
const client = createClient<paths>();
fetchMocker.mockResponseOnce(() => ({ status: 201, body: JSON.stringify(mockData) }));
const { data, error, response } = await client.post('/create-reply', {
body: {
message: 'My reply',
replied_at: new Date('2023-03-31T12:00:00Z').getTime(),
},
});

// assert correct URL was called
expect(fetchMocker.mock.calls[0][0]).toBe('/create-reply');

// assert correct data was returned
expect(data).toEqual(mockData);
expect(response.status).toBe(201);

// assert error is empty
expect(error).toBe(undefined);
});

it('supports optional requestBody', async () => {
const mockData = { status: 'success' };
const client = createClient<paths>();
Expand Down
26 changes: 25 additions & 1 deletion test/v1.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ export interface paths {
};
};
};
"/create-reply": {
post: {
requestBody: components["requestBodies"]["CreateReply"];
responses: {
201: components["responses"]["CreateReply"];
500: components["responses"]["Error"];
};
};
};
"/self": {
get: {
responses: {
Expand Down Expand Up @@ -171,6 +180,13 @@ export interface components {
};
};
};
CreateReply: {
content: {
"application/json;charset=utf-8": {
message: string;
};
};
};
Error: {
content: {
"application/json": {
Expand Down Expand Up @@ -206,7 +222,7 @@ export interface components {
requestBodies: {
CreatePost: {
content: {
"application/json;charset=utf-8": {
"application/json": {
title: string;
body: string;
publish_date: number;
Expand All @@ -220,6 +236,14 @@ export interface components {
};
};
};
CreateReply: {
content: {
"application/json;charset=utf-8": {
message: string;
replied_at: number;
};
};
};
};
headers: never;
pathItems: never;
Expand Down
36 changes: 34 additions & 2 deletions test/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ paths:
$ref: '#/components/responses/PostDelete'
500:
$ref: '#/components/responses/Error'

/create-reply:
post:
requestBody:
$ref: '#/components/requestBodies/CreateReply'
responses:
201:
$ref: '#/components/responses/CreateReply'
500:
$ref: '#/components/responses/Error'
/self:
get:
responses:
Expand Down Expand Up @@ -162,7 +170,7 @@ components:
CreatePost:
required: true
content:
'application/json;charset=utf-8':
application/json:
schema:
type: object
properties:
Expand All @@ -184,6 +192,20 @@ components:
properties:
description:
type: string
CreateReply:
required: true
content:
'application/json;charset=utf-8':
schema:
type: object
properties:
message:
type: string
replied_at:
type: number
required:
- message
- replied_at
responses:
CreatePost:
content:
Expand All @@ -205,6 +227,16 @@ components:
type: string
required:
- status
CreateReply:
content:
'application/json;charset=utf-8':
schema:
type: object
properties:
message:
type: string
required:
- message
Error:
content:
application/json:
Expand Down

0 comments on commit 4a8ac40

Please sign in to comment.