From ce8bd17ec788e51c950b5b2c86285f6e680b7cc7 Mon Sep 17 00:00:00 2001 From: brysonjbest <103070659+brysonjbest@users.noreply.github.com> Date: Tue, 17 Dec 2024 13:57:24 -0800 Subject: [PATCH] Remove duplicate klamm rule service. --- src/api/klamm/klamm.controller.spec.ts | 6 +++--- src/api/klamm/klamm.controller.ts | 2 +- src/api/klamm/klamm.service.spec.ts | 16 ---------------- src/api/klamm/klamm.service.ts | 9 --------- 4 files changed, 4 insertions(+), 29 deletions(-) diff --git a/src/api/klamm/klamm.controller.spec.ts b/src/api/klamm/klamm.controller.spec.ts index 126ed7e..db03c80 100644 --- a/src/api/klamm/klamm.controller.spec.ts +++ b/src/api/klamm/klamm.controller.spec.ts @@ -15,7 +15,7 @@ describe('KlammController', () => { useValue: { getKlammBREFields: jest.fn(() => Promise.resolve('expected result')), getKlammBREFieldFromName: jest.fn((fieldName) => Promise.resolve(`result for ${fieldName}`)), // Mock implementation - getKlammBRERules: jest.fn(() => Promise.resolve('rules result')), + _getAllKlammFields: jest.fn(() => Promise.resolve('rules result')), }, }, ], @@ -37,8 +37,8 @@ describe('KlammController', () => { expect(service.getKlammBREFieldFromName).toHaveBeenCalledTimes(1); }); - it('should call getKlammBRERules and return expected result', async () => { + it('should call _getAllKlammFields and return expected result', async () => { expect(await controller.getKlammBRERules()).toBe('rules result'); - expect(service.getKlammBRERules).toHaveBeenCalledTimes(1); + expect(service._getAllKlammFields).toHaveBeenCalledTimes(1); }); }); diff --git a/src/api/klamm/klamm.controller.ts b/src/api/klamm/klamm.controller.ts index b55350d..9080f61 100644 --- a/src/api/klamm/klamm.controller.ts +++ b/src/api/klamm/klamm.controller.ts @@ -13,7 +13,7 @@ export class KlammController { @Get('/brerules') async getKlammBRERules() { - return await this.klammService.getKlammBRERules(); + return await this.klammService._getAllKlammFields(); } @Get('/brefield/:fieldName') diff --git a/src/api/klamm/klamm.service.spec.ts b/src/api/klamm/klamm.service.spec.ts index c165b9b..50fb132 100644 --- a/src/api/klamm/klamm.service.spec.ts +++ b/src/api/klamm/klamm.service.spec.ts @@ -349,22 +349,6 @@ describe('KlammService', () => { await expect(service.getKlammBREFieldFromName(fieldName)).rejects.toThrow('Error fetching from Klamm'); }); - it('should get Klamm BRE rules correctly', async () => { - const mockData = ['rule1', 'rule2']; - jest.spyOn(service.axiosKlammInstance, 'get').mockResolvedValue({ data: mockData }); - - const result = await service.getKlammBRERules(); - - expect(service.axiosKlammInstance.get).toHaveBeenCalledWith(`${process.env.KLAMM_API_URL}/api/brerules`); - expect(result).toEqual(mockData); - }); - - it('should handle error in getKlammBRERules', async () => { - jest.spyOn(service.axiosKlammInstance, 'get').mockRejectedValue(new Error('Error')); - - await expect(service.getKlammBRERules()).rejects.toThrow('Error fetching from Klamm'); - }); - it('should throw InvalidFieldRequest error if field name does not exist', async () => { const fieldName = 'field1'; jest.spyOn(service.axiosKlammInstance, 'get').mockResolvedValue({ data: { data: [] } }); diff --git a/src/api/klamm/klamm.service.ts b/src/api/klamm/klamm.service.ts index ca30d56..c418aca 100644 --- a/src/api/klamm/klamm.service.ts +++ b/src/api/klamm/klamm.service.ts @@ -73,15 +73,6 @@ export class KlammService { } } - async getKlammBRERules(): Promise { - try { - const { data } = await this.axiosKlammInstance.get(`${process.env.KLAMM_API_URL}/api/brerules`); - return data; - } catch (err) { - throw new HttpException('Error fetching from Klamm', HttpStatus.INTERNAL_SERVER_ERROR); - } - } - async getKlammBREFieldFromName(fieldName: string): Promise { try { const sanitizedFieldName = encodeURIComponent(fieldName.trim());