Skip to content

Commit

Permalink
Implement CacheInterface, better JSON serialize
Browse files Browse the repository at this point in the history
  • Loading branch information
doochik committed Nov 18, 2024
1 parent c1fc0cc commit 9796fe5
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/httpBlock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,45 @@ describe('http', <
expect(result.result).toEqual(RESPONSE);
});

it('application/json serialization', async() => {
const path = getPath();

const RESPONSE = {
text: 'Привет!',
};
fake.add(path, (req: ClientRequest, res: ServerResponse) => {
const buffer = Buffer.from(JSON.stringify(RESPONSE));
res.setHeader('content-length', Buffer.byteLength(buffer));
res.setHeader('content-type', 'application/json; charset=utf-8');
res.end(buffer);
});

const block = baseBlock({
block: {
pathname: path,
},
options: {
after: ({ result }: { result: DescriptHttpBlockResult<typeof RESPONSE> }) => JSON.stringify(result),
},
});

const result = await de.run(block);

expect(JSON.parse(result)).toEqual({
headers: {
connection: 'keep-alive',
'content-length': '24',
'content-type': 'application/json; charset=utf-8',
date: expect.stringMatching(/^.* GMT$/),
'keep-alive': 'timeout=5',
},
result: {
text: 'Привет!',
},
statusCode: 200,
});
});

it('text/plain, is_json: true', async() => {
const path = getPath();

Expand Down

0 comments on commit 9796fe5

Please sign in to comment.