Skip to content

Commit

Permalink
test(NODE-3928): add additional test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Apr 20, 2022
1 parent e603776 commit 70d5dfc
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions test/unit/cmap/commands.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,37 @@ describe('commands', function () {
describe('Response', function () {
describe('#parse', function () {
context('when the message body is invalid', function () {
const message = Buffer.from([]);
const header = {
length: 0,
requestId: 0,
responseTo: 0,
opCode: 0
};
const body = Buffer.from([]);
context('when the buffer is empty', function () {
const message = Buffer.from([]);
const header = {
length: 0,
requestId: 0,
responseTo: 0,
opCode: 0
};
const body = Buffer.from([]);

it('throws an exception', function () {
const response = new Response(message, header, body);
expect(() => response.parse()).to.throw();
it('throws an exception', function () {
const response = new Response(message, header, body);
expect(() => response.parse()).to.throw(RangeError, /outside buffer bounds/);
});
});

context('when numReturned is invalid', function () {
const message = Buffer.from([]);
const header = {
length: 0,
requestId: 0,
responseTo: 0,
opCode: 0
};
const body = Buffer.alloc(5 * 4);
body.writeInt32LE(-1, 16);

it('throws an exception', function () {
const response = new Response(message, header, body);
expect(() => response.parse()).to.throw(RangeError, /Invalid array length/);
});
});
});
});
Expand Down

0 comments on commit 70d5dfc

Please sign in to comment.