Skip to content

Commit ac2b000

Browse files
committed
test: error cases
1 parent 00f540e commit ac2b000

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

test/unit/operations/get_more.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,54 @@ describe('GetMoreOperation', function () {
192192
}
193193
});
194194
});
195+
196+
context('error cases', () => {
197+
const server = new Server(new Topology([], {} as any), new ServerDescription(''), {} as any);
198+
sinon.stub(server, 'command').yieldsRight();
199+
200+
it('should throw if the cursorId is undefined', async () => {
201+
const getMoreOperation = new GetMoreOperation(
202+
ns('db.collection'),
203+
// @ts-expect-error: Testing undefined cursorId
204+
undefined,
205+
server,
206+
options
207+
);
208+
const error = await promisify(getMoreOperation.execute.bind(getMoreOperation))(
209+
server,
210+
undefined
211+
).catch(error => error);
212+
expect(error).to.be.instanceOf(MongoRuntimeError);
213+
});
214+
215+
it('should throw if the collection is undefined', async () => {
216+
const getMoreOperation = new GetMoreOperation(
217+
ns('db'),
218+
Long.fromNumber(1),
219+
server,
220+
options
221+
);
222+
const error = await promisify(getMoreOperation.execute.bind(getMoreOperation))(
223+
server,
224+
undefined
225+
).catch(error => error);
226+
expect(error).to.be.instanceOf(MongoRuntimeError);
227+
});
228+
229+
it('should throw if the cursorId is zero', async () => {
230+
const getMoreOperation = new GetMoreOperation(
231+
ns('db.collection'),
232+
Long.fromNumber(0),
233+
server,
234+
options
235+
);
236+
const error = await promisify(getMoreOperation.execute.bind(getMoreOperation))(
237+
server,
238+
undefined
239+
).catch(error => error);
240+
expect(error).to.be.instanceOf(MongoRuntimeError);
241+
});
242+
});
195243
});
196244

197245
describe('#hasAspect', function () {

0 commit comments

Comments
 (0)