tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

HTTPRequest.test.ts (2196B)


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