Skip to content

Commit 19ee7d8

Browse files
committed
test(NODE-3928): add additional test cases
1 parent f2c3ea4 commit 19ee7d8

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

test/unit/cmap/commands.test.js

+30-11
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,37 @@ describe('commands', function () {
55
describe('Response', function () {
66
describe('#parse', function () {
77
context('when the message body is invalid', function () {
8-
const message = Buffer.from([]);
9-
const header = {
10-
length: 0,
11-
requestId: 0,
12-
responseTo: 0,
13-
opCode: 0
14-
};
15-
const body = Buffer.from([]);
8+
context('when the buffer is empty', function () {
9+
const message = Buffer.from([]);
10+
const header = {
11+
length: 0,
12+
requestId: 0,
13+
responseTo: 0,
14+
opCode: 0
15+
};
16+
const body = Buffer.from([]);
1617

17-
it('throws an exception', function () {
18-
const response = new Response(message, header, body);
19-
expect(() => response.parse()).to.throw();
18+
it('throws an exception', function () {
19+
const response = new Response(message, header, body);
20+
expect(() => response.parse()).to.throw(RangeError, /outside buffer bounds/);
21+
});
22+
});
23+
24+
context('when numReturned is invalid', function () {
25+
const message = Buffer.from([]);
26+
const header = {
27+
length: 0,
28+
requestId: 0,
29+
responseTo: 0,
30+
opCode: 0
31+
};
32+
const body = Buffer.alloc(5 * 4);
33+
body.writeInt32LE(-1, 16);
34+
35+
it('throws an exception', function () {
36+
const response = new Response(message, header, body);
37+
expect(() => response.parse()).to.throw(RangeError, /Invalid array length/);
38+
});
2039
});
2140
});
2241
});

0 commit comments

Comments
 (0)