From 34179543d73d05e51cf75eb807490b1933b80c10 Mon Sep 17 00:00:00 2001 From: Tirke Date: Mon, 21 Oct 2024 13:03:29 +0200 Subject: [PATCH] feat: fix type and add test --- .../src/lib/node-cache-manager-mongodb.spec.ts | 13 +++++++++++++ .../src/lib/node-cache-manager-mongodb.ts | 1 + 2 files changed, 14 insertions(+) diff --git a/packages/node-cache-manager-mongodb/src/lib/node-cache-manager-mongodb.spec.ts b/packages/node-cache-manager-mongodb/src/lib/node-cache-manager-mongodb.spec.ts index 3522824d..38031e99 100644 --- a/packages/node-cache-manager-mongodb/src/lib/node-cache-manager-mongodb.spec.ts +++ b/packages/node-cache-manager-mongodb/src/lib/node-cache-manager-mongodb.spec.ts @@ -1,4 +1,5 @@ import { caching } from 'cache-manager' +import { MongoClient } from 'mongodb' import { mongoDbStore, MongoCache } from './node-cache-manager-mongodb' @@ -325,3 +326,15 @@ describe('databaseName', () => { await baseCache.reset() }) }) + +describe('reusing Mongo client', () => { + it('should reuse the client', async () => { + const mongoClient = new MongoClient('mongodb://localhost:27017') + const cache = await caching(mongoDbStore, { + client: mongoClient, + }) + + await cache.set('foo', 'bar') + expect(cache.store.client).toEqual(mongoClient) + }) +}) diff --git a/packages/node-cache-manager-mongodb/src/lib/node-cache-manager-mongodb.ts b/packages/node-cache-manager-mongodb/src/lib/node-cache-manager-mongodb.ts index 844250cc..20d4d36e 100644 --- a/packages/node-cache-manager-mongodb/src/lib/node-cache-manager-mongodb.ts +++ b/packages/node-cache-manager-mongodb/src/lib/node-cache-manager-mongodb.ts @@ -19,6 +19,7 @@ type Args = { mongoConfig?: MongoClientOptions collectionName?: string databaseName?: string + client?: MongoClient } & Config