Skip to content

Commit

Permalink
test: error cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Aug 3, 2022
1 parent 00f540e commit ac2b000
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions test/unit/operations/get_more.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,54 @@ describe('GetMoreOperation', function () {
}
});
});

context('error cases', () => {
const server = new Server(new Topology([], {} as any), new ServerDescription(''), {} as any);
sinon.stub(server, 'command').yieldsRight();

it('should throw if the cursorId is undefined', async () => {
const getMoreOperation = new GetMoreOperation(
ns('db.collection'),
// @ts-expect-error: Testing undefined cursorId
undefined,
server,
options
);
const error = await promisify(getMoreOperation.execute.bind(getMoreOperation))(
server,
undefined
).catch(error => error);
expect(error).to.be.instanceOf(MongoRuntimeError);
});

it('should throw if the collection is undefined', async () => {
const getMoreOperation = new GetMoreOperation(
ns('db'),
Long.fromNumber(1),
server,
options
);
const error = await promisify(getMoreOperation.execute.bind(getMoreOperation))(
server,
undefined
).catch(error => error);
expect(error).to.be.instanceOf(MongoRuntimeError);
});

it('should throw if the cursorId is zero', async () => {
const getMoreOperation = new GetMoreOperation(
ns('db.collection'),
Long.fromNumber(0),
server,
options
);
const error = await promisify(getMoreOperation.execute.bind(getMoreOperation))(
server,
undefined
).catch(error => error);
expect(error).to.be.instanceOf(MongoRuntimeError);
});
});
});

describe('#hasAspect', function () {
Expand Down

0 comments on commit ac2b000

Please sign in to comment.