Skip to content

Commit 8fbf888

Browse files
fixed unit test
1 parent 8511ca3 commit 8fbf888

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/interface/cli/commands/offline-logs/ensure-index.cmd.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { MongoClient } = require("mongodb");
22
const Command = require("../../Command");
33
const cmd = require("./base.cmd");
4-
const { ensureIndex, defaultCollections } = require('./utils')
4+
const utils = require('./utils')
55

66
const command = new Command({
77
command: "ensure-index",
@@ -22,9 +22,9 @@ const command = new Command({
2222
await client.connect();
2323
const database = client.db(db);
2424
const failedCollections = [];
25-
for (const collection of defaultCollections) {
25+
for (const collection of utils.defaultCollections) {
2626
try {
27-
await ensureIndex(database, collection);
27+
await utils.ensureIndex(database, collection);
2828
} catch (error) {
2929
console.error(`failed to ensure index of collection '${collection}', error: ${error.message}`);
3030
failedCollections.push(collection);

lib/interface/cli/commands/offline-logs/ensure-index.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ describe("ensure-index", () => {
2828
mockCollection.indexExists.mockReturnValue(false);
2929
utils.getUserInput.mockReturnValue(true);
3030
const collection = 'whatever';
31-
const expectedIndexObj = { jobId: 1, accountId: 1, time: 1 }
31+
const expectedIndexObj = { accountId: 1, jobId: 1, time: 1 }
3232

3333
//execute
3434
await utils.ensureIndex(mockDatabase, collection);
3535

3636
//check
3737
expect(mockCollection.indexExists).toBeCalledTimes(1);
38-
expect(mockCollection.indexExists).toBeCalledWith("jobId_1_accountId_1_time_1");
38+
expect(mockCollection.indexExists).toBeCalledWith("accountId_1_jobId_1_time_1");
3939
expect(mockCollection.estimatedDocumentCount).toBeCalledTimes(1);
4040
expect(utils.getUserInput).toBeCalledTimes(1);
4141
expect(mockCollection.createIndex).toBeCalledTimes(1);
@@ -52,7 +52,7 @@ describe("ensure-index", () => {
5252

5353
//check
5454
expect(mockCollection.indexExists).toBeCalledTimes(1);
55-
expect(mockCollection.indexExists).toBeCalledWith("jobId_1_accountId_1_time_1");
55+
expect(mockCollection.indexExists).toBeCalledWith("accountId_1_jobId_1_time_1");
5656
expect(mockCollection.estimatedDocumentCount).toBeCalledTimes(1);
5757
expect(utils.getUserInput).toBeCalledTimes(1);
5858
expect(mockCollection.createIndex).toBeCalledTimes(0);
@@ -67,7 +67,7 @@ describe("ensure-index", () => {
6767

6868
//check
6969
expect(mockCollection.indexExists).toBeCalledTimes(1);
70-
expect(mockCollection.indexExists).toBeCalledWith("jobId_1_accountId_1_time_1");
70+
expect(mockCollection.indexExists).toBeCalledWith("accountId_1_jobId_1_time_1");
7171
expect(mockCollection.estimatedDocumentCount).toBeCalledTimes(0);
7272
expect(utils.getUserInput).toBeCalledTimes(0);
7373
expect(mockCollection.createIndex).toBeCalledTimes(0);

0 commit comments

Comments
 (0)