From c45e5c94e5026d05d8210be6ac43efbaca32ddae Mon Sep 17 00:00:00 2001 From: sbriat Date: Tue, 22 Aug 2023 11:30:40 +0200 Subject: [PATCH] default params provider tests --- .../default-param.provider.spec.ts | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/modules/geography/tests/unit/infrastructure/default-param.provider.spec.ts diff --git a/src/modules/geography/tests/unit/infrastructure/default-param.provider.spec.ts b/src/modules/geography/tests/unit/infrastructure/default-param.provider.spec.ts new file mode 100644 index 0000000..72be537 --- /dev/null +++ b/src/modules/geography/tests/unit/infrastructure/default-param.provider.spec.ts @@ -0,0 +1,48 @@ +import { DefaultParams } from '@modules/geography/core/application/types/default-params.type'; +import { DefaultParamsProvider } from '@modules/geography/infrastructure/default-params-provider'; +import { ConfigService } from '@nestjs/config'; +import { Test, TestingModule } from '@nestjs/testing'; + +const mockConfigService = { + get: jest.fn().mockImplementation((value: string) => { + switch (value) { + case 'GEOROUTER_TYPE': + return 'graphhopper'; + case 'GEOROUTER_URL': + return 'http://localhost:8989'; + default: + return 'some_default_value'; + } + }), +}; + +describe('DefaultParamsProvider', () => { + let defaultParamsProvider: DefaultParamsProvider; + + beforeAll(async () => { + const module: TestingModule = await Test.createTestingModule({ + imports: [], + providers: [ + DefaultParamsProvider, + { + provide: ConfigService, + useValue: mockConfigService, + }, + ], + }).compile(); + + defaultParamsProvider = module.get( + DefaultParamsProvider, + ); + }); + + it('should be defined', () => { + expect(defaultParamsProvider).toBeDefined(); + }); + + it('should provide default params', async () => { + const params: DefaultParams = defaultParamsProvider.getParams(); + expect(params.GEOROUTER_TYPE).toBe('graphhopper'); + expect(params.GEOROUTER_URL).toBe('http://localhost:8989'); + }); +});