-
Notifications
You must be signed in to change notification settings - Fork 9.2k
/
Copy pathHTTPRequest.test.ts
61 lines (50 loc) · 2.14 KB
/
HTTPRequest.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import {describe, it} from 'node:test';
import expect from 'expect';
import {HTTPRequest} from './HTTPRequest.js';
describe('HTTPRequest', () => {
describe('getResponse', () => {
it('should get body length from empty string', async () => {
const response = HTTPRequest.getResponse('');
expect(response.contentLength).toBe(Buffer.from('').byteLength);
});
it('should get body length from latin string', async () => {
const body = 'Lorem ipsum dolor sit amet';
const response = HTTPRequest.getResponse(body);
expect(response.contentLength).toBe(Buffer.from(body).byteLength);
});
it('should get body length from string with emoji', async () => {
const body = 'How Long is this string in bytes 📏?';
const response = HTTPRequest.getResponse(body);
expect(response.contentLength).toBe(Buffer.from(body).byteLength);
});
it('should get body length from Uint8Array', async () => {
const body = Buffer.from('How Long is this string in bytes 📏?');
const response = HTTPRequest.getResponse(body);
expect(response.contentLength).toBe(body.byteLength);
});
it('should get base64 from empty string', async () => {
const response = HTTPRequest.getResponse('');
expect(response.base64).toBe(Buffer.from('').toString('base64'));
});
it('should get base64 from latin string', async () => {
const body = 'Lorem ipsum dolor sit amet';
const response = HTTPRequest.getResponse(body);
expect(response.base64).toBe(Buffer.from(body).toString('base64'));
});
it('should get base64 from string with emoji', async () => {
const body = 'What am I in base64 🤔?';
const response = HTTPRequest.getResponse(body);
expect(response.base64).toBe(Buffer.from(body).toString('base64'));
});
it('should get base64 length from Uint8Array', async () => {
const body = Buffer.from('What am I in base64 🤔?');
const response = HTTPRequest.getResponse(body);
expect(response.base64).toBe(body.toString('base64'));
});
});
});