Skip to content

Commit

Permalink
Remove duplicate klamm rule service.
Browse files Browse the repository at this point in the history
  • Loading branch information
brysonjbest committed Dec 17, 2024
1 parent 54efd88 commit ce8bd17
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 29 deletions.
6 changes: 3 additions & 3 deletions src/api/klamm/klamm.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
},
},
],
Expand All @@ -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);
});
});
2 changes: 1 addition & 1 deletion src/api/klamm/klamm.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class KlammController {

@Get('/brerules')
async getKlammBRERules() {
return await this.klammService.getKlammBRERules();
return await this.klammService._getAllKlammFields();
}

@Get('/brefield/:fieldName')
Expand Down
16 changes: 0 additions & 16 deletions src/api/klamm/klamm.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [] } });
Expand Down
9 changes: 0 additions & 9 deletions src/api/klamm/klamm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,6 @@ export class KlammService {
}
}

async getKlammBRERules(): Promise<string[]> {
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<KlammField[]> {
try {
const sanitizedFieldName = encodeURIComponent(fieldName.trim());
Expand Down

0 comments on commit ce8bd17

Please sign in to comment.