Skip to content

Commit

Permalink
Add tests for #58
Browse files Browse the repository at this point in the history
  • Loading branch information
doochik committed Apr 28, 2024
1 parent d273a3c commit 8c0b1dd
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/http_block.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const Server = require( './server' );
const { get_path, get_result_block } = require( './helpers' );

const strip_null_and_undefined_values = require( '../lib/strip_null_and_undefined_values' );
const { gunzipSync } = require( 'node:zlib' );

// --------------------------------------------------------------------------------------------------------------- //

Expand Down Expand Up @@ -836,6 +837,30 @@ describe( 'http', () => {
expect( body.toString() ).toBe( qs_.stringify( BODY ) );
} );

it( 'with body_compress', async () => {
const path = get_path();

const spy = jest.fn( ( req, res ) => res.end() );

fake.add( path, spy );

const block = base_block( {
block: {
pathname: path,
method: 'POST',
body: 'Привет!',
body_compress: true,
},
} );

await de.run( block );

expect( spy ).toHaveBeenCalledTimes( 1 );
const body = spy.mock.calls[ 0 ][ 2 ];
expect( body.slice( 0, 2 ).equals( Buffer.from( '1f8b', 'hex' ) ) ).toBe( true );
expect( body ).toHaveLength( 34 );
expect( gunzipSync( body ).toString( 'utf-8' ) ).toBe( 'Привет!' );
} );
} );

describe( 'parse response', () => {
Expand Down

0 comments on commit 8c0b1dd

Please sign in to comment.