[go: up one dir, main page]

Skip to content

Commit

Permalink
tests: improve test coverage for request body (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored May 19, 2021
1 parent d9bcdc3 commit ec2262a
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit ec2262a

Please sign in to comment.