From 8b558369bd5fc300a1ee45c62513dfcd6d9f7397 Mon Sep 17 00:00:00 2001 From: Gleb Bashkatov Date: Mon, 5 Apr 2021 16:36:26 +0300 Subject: [PATCH] fix: fix FireormService provider --- src/fireorm/fireorm.module.spec.ts | 14 +++++++++++++- src/fireorm/fireorm.module.ts | 7 ++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/fireorm/fireorm.module.spec.ts b/src/fireorm/fireorm.module.spec.ts index 50c802a..afe349b 100644 --- a/src/fireorm/fireorm.module.spec.ts +++ b/src/fireorm/fireorm.module.spec.ts @@ -1,5 +1,6 @@ import { getRepositoryToken } from '../nestjs-fireorm'; import { FireormModule, FireormSettings, firestoreProvider } from './fireorm.module'; +jest.mock('./fireorm.service'); import { FireormService } from './fireorm.service'; import 'jest-extended'; jest.mock('@google-cloud/firestore'); @@ -41,7 +42,18 @@ describe('FireormModule', () => { inject: [FireormSettings], useFactory: firestoreProvider, }, - FireormService, + { + provide: FireormService, + inject: [Firestore, FireormSettings], + useFactory: expect.toSatisfy((fun) => { + const fireormService = fun(1, 2); + + expect(fireormService).toBeInstanceOf(FireormService); + expect(FireormService).toBeCalledWith(1, 2); + + return true; + }), + }, ], exports: [FireormService], }); diff --git a/src/fireorm/fireorm.module.ts b/src/fireorm/fireorm.module.ts index abc4e12..1da2bd1 100644 --- a/src/fireorm/fireorm.module.ts +++ b/src/fireorm/fireorm.module.ts @@ -79,7 +79,12 @@ export class FireormModule { inject: [FireormSettings], useFactory: firestoreProvider, }, - FireormService, + { + provide: FireormService, + inject: [Firestore, FireormSettings], + useFactory: (firestore: Firestore, settings: FireormSettings) => + new FireormService(firestore, settings), + }, ], exports: [FireormService], };