Skip to content

Commit e8c3131

Browse files
committed
Add settings api test
1 parent 7370451 commit e8c3131

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/api/settings.test.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { axiosInstance } from 'api';
2+
3+
import { fetchSettings, SettingsType } from './settings';
4+
5+
test('api get cost category keys', () => {
6+
fetchSettings(SettingsType.costCategories, '');
7+
expect(axiosInstance.get).toBeCalledWith('settings/aws_category_keys/');
8+
});
9+
10+
test('api get platform projects', () => {
11+
fetchSettings(SettingsType.platformProjects, '');
12+
expect(axiosInstance.get).toBeCalledWith('settings/cost-groups/');
13+
});
14+
15+
test('api get child tag mappings', () => {
16+
fetchSettings(SettingsType.tagsMappingsChild, '');
17+
expect(axiosInstance.get).toBeCalledWith('settings/tags/mappings/child');
18+
});
19+
20+
test('api get parent tag mappings', () => {
21+
fetchSettings(SettingsType.tagsMappingsParent, '');
22+
expect(axiosInstance.get).toBeCalledWith('settings/tags/mappings/parent');
23+
});
24+
25+
test('api get tag mappings', () => {
26+
fetchSettings(SettingsType.tagsMappings, '');
27+
expect(axiosInstance.get).toBeCalledWith('settings/tags/mappings');
28+
});
29+
30+
test('api get tags', () => {
31+
fetchSettings(SettingsType.tags, '');
32+
expect(axiosInstance.get).toBeCalledWith('settings/tags');
33+
});

src/api/settings.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export const SettingsTypePaths: Partial<Record<SettingsType, string>> = {
7171

7272
export function fetchSettings(settingsType: SettingsType, query: string) {
7373
const path = SettingsTypePaths[settingsType];
74-
return axiosInstance.get<Settings>(`${path}?${query}`);
74+
const queryString = query ? `?${query}` : '';
75+
return axiosInstance.get<Settings>(`${path}${queryString}`);
7576
}
7677

7778
export function updateSettings(settingsType: SettingsType, payload: SettingsPayload) {

0 commit comments

Comments
 (0)