diff --git a/src/api/models/field.spec.js b/src/api/models/field.spec.js index f02168ff5..0a3bdbdf5 100644 --- a/src/api/models/field.spec.js +++ b/src/api/models/field.spec.js @@ -6,6 +6,10 @@ import fieldFactory, { import { URI_FIELD_NAME } from '../../common/uris'; import { SCOPE_DOCUMENT, SCOPE_COLLECTION } from '../../common/scope'; +const listCollections = { + toArray: () => [true], +}; + describe('field', () => { describe('fieldFactory', () => { let fieldCollection; @@ -39,9 +43,9 @@ describe('field', () => { Promise.resolve({ value: 'result' }), ), }; - db = { collection: jest.fn().mockImplementation(() => fieldCollection), + listCollections: () => listCollections, }; field = await fieldFactory(db); @@ -285,10 +289,14 @@ describe('field', () => { .mockImplementation(() => Promise.resolve({})), insertOne: jest.fn(), }; + const listCollections = { + toArray: () => [true], + }; const dbNoUri = { collection: jest .fn() .mockImplementation(() => fieldCollectionNoUri), + listCollections: () => listCollections, }; const fieldNoUri = await fieldFactory(dbNoUri); @@ -366,6 +374,7 @@ describe('field', () => { collection: jest .fn() .mockImplementation(() => fieldCollection), + listCollections: () => listCollections, }; field = await fieldFactory(db); @@ -399,6 +408,7 @@ describe('field', () => { collection: jest .fn() .mockImplementation(() => fieldCollection), + listCollections: () => listCollections, }; field = await fieldFactory(db); diff --git a/src/api/models/publishedDataset.spec.js b/src/api/models/publishedDataset.spec.js index 91a7ba8de..d9fa9689e 100644 --- a/src/api/models/publishedDataset.spec.js +++ b/src/api/models/publishedDataset.spec.js @@ -7,8 +7,12 @@ describe('publishedDataset', () => { createIndex: jest.fn(), findOneAndUpdate: jest.fn(), }; + const listCollections = { + toArray: () => [true], + }; const db = { collection: () => collection, + listCollections: () => listCollections, }; let publishedDatasetCollection; @@ -59,8 +63,12 @@ describe('publishedDataset', () => { updateOne: jest.fn(), createIndex: jest.fn(), }; + const listCollections = { + toArray: () => [true], + }; const db = { collection: () => collection, + listCollections: () => listCollections, }; let publishedDatasetCollection; @@ -174,8 +182,12 @@ describe('publishedDataset', () => { updateOne: jest.fn(), createIndex: jest.fn(), }; + const listCollections = { + toArray: () => [true], + }; const db = { collection: () => collection, + listCollections: () => listCollections, }; let publishedDatasetCollection; @@ -235,11 +247,15 @@ describe('publishedDataset', () => { skip, count, })); + const listCollections = { + toArray: () => [true], + }; const db = { collection: () => ({ find, createIndex: jest.fn(), }), + listCollections: () => listCollections, }; let publishedDatasetCollection; @@ -300,12 +316,15 @@ describe('publishedDataset', () => { skip: skipToEmpty, count, })); - + const listCollections = { + toArray: () => [true], + }; publishedDatasetCollection = await publishedDataset({ collection: () => ({ find: emptyFind, createIndex: jest.fn(), }), + listCollections: () => listCollections, }); await publishedDatasetCollection.findPage({ @@ -404,11 +423,15 @@ describe('publishedDataset', () => { describe('create', () => { const insertOne = jest.fn().mockImplementation(() => 'inserted'); + const listCollections = { + toArray: () => [true], + }; const db = { collection: () => ({ insertOne, createIndex: jest.fn(), }), + listCollections: () => listCollections, }; let publishedDatasetCollection; diff --git a/src/api/services/repositoryMiddleware.spec.js b/src/api/services/repositoryMiddleware.spec.js index 11bcd9cb7..1821bc8fe 100644 --- a/src/api/services/repositoryMiddleware.spec.js +++ b/src/api/services/repositoryMiddleware.spec.js @@ -2,8 +2,12 @@ import { mongoClientFactory } from './repositoryMiddleware'; describe('mongoClient middleware', () => { it('it should add db and collections to ctx', async () => { + const listCollections = { + toArray: () => [true], + }; const db = { collection: () => ({ createIndex: () => {} }), + listCollections: () => listCollections, }; const next = () => Promise.resolve();