Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: improve test coverage for request body #226

Merged
merged 1 commit into from May 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions test/index.ts
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