From fdba46121741fa99a15f7dbcc11792b79a7212dc Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Wed, 19 May 2021 10:51:40 -0700 Subject: [PATCH] tests: improve test coverage for request body --- test/index.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/index.ts b/test/index.ts index 46fb165..4ad9be9 100644 --- a/test/index.ts +++ b/test/index.ts @@ -357,6 +357,46 @@ describe('teeny', () => { }); }); + it('should accept a Buffer as the body of a request', done => { + const scope = nock(uri).post('/', 'hello').reply(200, '🌍'); + teenyRequest( + {uri, method: 'POST', body: Buffer.from('hello')}, + (error, response, body) => { + assert.ifError(error); + assert.strictEqual(response.statusCode, 200); + assert.strictEqual(body, '🌍'); + scope.done(); + done(); + } + ); + }); + + it('should accept a plain string as the body of a request', done => { + const scope = nock(uri).post('/', 'hello').reply(200, '🌍'); + teenyRequest( + {uri, method: 'POST', body: 'hello'}, + (error, response, body) => { + assert.ifError(error); + assert.strictEqual(response.statusCode, 200); + assert.strictEqual(body, '🌍'); + scope.done(); + done(); + } + ); + }); + + it('should accept json as the body of a request', done => { + const body = {hello: '🌍'}; + const scope = nock(uri).post('/', JSON.stringify(body)).reply(200, '👋'); + teenyRequest({uri, method: 'POST', json: body}, (error, response, body) => { + assert.ifError(error); + assert.strictEqual(response.statusCode, 200); + assert.strictEqual(body, '👋'); + scope.done(); + done(); + }); + }); + // TODO multipart is broken with 2 strings // see: https://github.com/googleapis/teeny-request/issues/168 it.skip('should track stats, multipart mode, success', done => {