Skip to content

Commit 63c0979

Browse files
committed
test: refactor list collections unit test
1 parent a31684f commit 63c0979

File tree

3 files changed

+85
-79
lines changed

3 files changed

+85
-79
lines changed

src/operations/list_collections.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,17 @@ export class ListCollectionsOperation extends CommandOperation<string[]> {
9090
return;
9191
}
9292

93-
const command = {
93+
return super.executeCommand(server, session, this.generateCommand(), callback);
94+
}
95+
96+
/** @internal */
97+
generateCommand(): Document {
98+
return {
9499
listCollections: 1,
95100
filter: this.filter,
96101
cursor: this.batchSize ? { batchSize: this.batchSize } : {},
97102
nameOnly: this.nameOnly
98103
};
99-
100-
return super.executeCommand(server, session, command, callback);
101104
}
102105
}
103106

test/functional/unit_db_list_collections.test.js

-76
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
'use strict';
2+
3+
const { expect } = require('chai');
4+
const { ListCollectionsOperation } = require('../../../src/operations/list_collections');
5+
6+
describe('ListCollectionsOperation', function () {
7+
const db = 'test';
8+
9+
describe('#constructor', function () {
10+
context('when nameOnly is provided', function () {
11+
context('when nameOnly is true', function () {
12+
const operation = new ListCollectionsOperation(db, {}, { nameOnly: true, dbName: db });
13+
14+
it('sets nameOnly to true', function () {
15+
expect(operation.nameOnly).to.be.true;
16+
});
17+
});
18+
19+
context('when nameOnly is false', function () {
20+
const operation = new ListCollectionsOperation(db, {}, { nameOnly: false, dbName: db });
21+
22+
it('sets nameOnly to false', function () {
23+
expect(operation.nameOnly).to.be.false;
24+
});
25+
});
26+
});
27+
28+
context('when nameOnly is not provided', function () {
29+
const operation = new ListCollectionsOperation(db, {}, { dbName: db });
30+
31+
it('sets nameOnly to false', function () {
32+
expect(operation.nameOnly).to.be.false;
33+
});
34+
});
35+
});
36+
37+
describe('#generateCommand', function () {
38+
context('when nameOnly is provided', function () {
39+
context('when nameOnly is true', function () {
40+
const operation = new ListCollectionsOperation(db, {}, { nameOnly: true, dbName: db });
41+
42+
it('sets nameOnly to true', function () {
43+
expect(operation.generateCommand()).to.deep.equal({
44+
listCollections: 1,
45+
cursor: {},
46+
filter: {},
47+
nameOnly: true
48+
});
49+
});
50+
});
51+
52+
context('when nameOnly is false', function () {
53+
const operation = new ListCollectionsOperation(db, {}, { nameOnly: false, dbName: db });
54+
55+
it('sets nameOnly to false', function () {
56+
expect(operation.generateCommand()).to.deep.equal({
57+
listCollections: 1,
58+
cursor: {},
59+
filter: {},
60+
nameOnly: false
61+
});
62+
});
63+
});
64+
});
65+
66+
context('when nameOnly is not provided', function () {
67+
const operation = new ListCollectionsOperation(db, {}, { dbName: db });
68+
69+
it('sets nameOnly to false', function () {
70+
expect(operation.generateCommand()).to.deep.equal({
71+
listCollections: 1,
72+
cursor: {},
73+
filter: {},
74+
nameOnly: false
75+
});
76+
});
77+
});
78+
});
79+
});

0 commit comments

Comments
 (0)