-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
2 changed files
with
134 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
const { expect } = require('chai'); | ||
const { Response } = require('../../../src/cmap/commands'); | ||
|
||
describe('commands', function () { | ||
describe('Response', function () { | ||
describe('#parse', function () { | ||
context('when the message body is invalid', function () { | ||
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(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/); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('#constructor', 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([]); | ||
|
||
it('does not throw an exception', function () { | ||
let error; | ||
try { | ||
new Response(message, header, body); | ||
} catch (err) { | ||
error = err; | ||
} | ||
expect(error).to.be.undefined; | ||
}); | ||
|
||
it('initializes the documents to an empty array', function () { | ||
const response = new Response(message, header, body); | ||
expect(response.documents).to.be.empty; | ||
}); | ||
|
||
it('does not set the responseFlags', function () { | ||
const response = new Response(message, header, body); | ||
expect(response.responseFlags).to.be.undefined; | ||
}); | ||
|
||
it('does not set the cursorNotFound flag', function () { | ||
const response = new Response(message, header, body); | ||
expect(response.cursorNotFound).to.be.undefined; | ||
}); | ||
|
||
it('does not set the cursorId', function () { | ||
const response = new Response(message, header, body); | ||
expect(response.cursorId).to.be.undefined; | ||
}); | ||
|
||
it('does not set startingFrom', function () { | ||
const response = new Response(message, header, body); | ||
expect(response.startingFrom).to.be.undefined; | ||
}); | ||
|
||
it('does not set numberReturned', function () { | ||
const response = new Response(message, header, body); | ||
expect(response.numberReturned).to.be.undefined; | ||
}); | ||
|
||
it('does not set queryFailure', function () { | ||
const response = new Response(message, header, body); | ||
expect(response.queryFailure).to.be.undefined; | ||
}); | ||
|
||
it('does not set shardConfigStale', function () { | ||
const response = new Response(message, header, body); | ||
expect(response.shardConfigStale).to.be.undefined; | ||
}); | ||
|
||
it('does not set awaitCapable', function () { | ||
const response = new Response(message, header, body); | ||
expect(response.awaitCapable).to.be.undefined; | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |