Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/composables/__tests__/axios.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { describe, expect, it, vi } from 'vitest';
import { useAuthenticatedInstance } from '@/composables/axios';

vi.mock('@/stores/config.ts', () => ({
useConfigStore: () => ({
getConfig: vi.fn(async () => ({ API_URL: 'http://api.test' })),
}),
}));

vi.mock('@/stores/auth', () => ({
useUserStore: () => ({
logout: vi.fn(),
}),
}));

vi.mock('vue-router', () => ({
useRouter: () => ({
push: vi.fn(),
}),
}));

vi.mock('primevue/usetoast', () => ({
useToast: () => ({
add: vi.fn(),
}),
}));

describe('axios response conversion', () => {
it('preserves dashboard suggestion label-map keys inside DataResponse arrays', async () => {
const instance = useAuthenticatedInstance();

const response = await instance.get('/dashboard-suggestions', {
// This endpoint returns camelCase field names; camelcase-keys matches
// stopPaths against the original keys, so the stop path is camelCase too.
camelcaseStopPaths: ['data.proposedFilterLabelSet'],
adapter: async (config) => ({
data: {
data: [
{
id: 'suggestion-1',
proposedFilterLabelSet: {
_policy: 'x',
service_name: 'api',
},
},
],
},
status: 200,
statusText: 'OK',
headers: {},
config,
}),
});

expect(response.data.data[0]).toEqual({
id: 'suggestion-1',
proposedFilterLabelSet: {
_policy: 'x',
service_name: 'api',
},
});
});
});
21 changes: 5 additions & 16 deletions src/composables/useDashboardSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
buildGeneralizeDashboardSuggestionsEndpoint,
buildLatestDashboardSuggestionRunEndpoint,
buildRejectDashboardSuggestionsEndpoint,
DASHBOARD_SUGGESTION_LABEL_STOP_PATHS,
type DashboardSuggestion,
type DashboardSuggestionEvent,
type DashboardSuggestionLabelKey,
Expand Down Expand Up @@ -93,13 +94,9 @@ export function useDashboardSuggestions(
// Preserve raw label keys (e.g. `_policy`) on the originating label set,
// the proposed filter, and the AI baseline used for the edit diff;
// otherwise camelcase conversion strips `_` and the diff shows phantom
// changes.
// changes. See DASHBOARD_SUGGESTION_LABEL_STOP_PATHS for why these are camelCase.
{
camelcaseStopPaths: [
'data.labelSet',
'data.proposedFilterLabelSet',
'data.originalProposedFilterLabelSet',
],
camelcaseStopPaths: DASHBOARD_SUGGESTION_LABEL_STOP_PATHS,
},
);
}
Expand Down Expand Up @@ -194,11 +191,7 @@ export function useDashboardSuggestions(
const response = await fetchHistoryRequest(
buildDashboardSuggestionsEndpoint(sspId.value, status),
{
camelcaseStopPaths: [
'data.labelSet',
'data.proposedFilterLabelSet',
'data.originalProposedFilterLabelSet',
],
camelcaseStopPaths: DASHBOARD_SUGGESTION_LABEL_STOP_PATHS,
},
);
collected.push(...(response?.data.value?.data ?? []));
Expand Down Expand Up @@ -235,11 +228,7 @@ export function useDashboardSuggestions(
data: payload,
transformRequest: [decamelizeKeys],
// Preserve raw label keys (e.g. `_policy`) the user kept in the filter.
camelcaseStopPaths: [
'data.labelSet',
'data.proposedFilterLabelSet',
'data.originalProposedFilterLabelSet',
],
camelcaseStopPaths: DASHBOARD_SUGGESTION_LABEL_STOP_PATHS,
},
);
await refreshPendingSuggestions();
Expand Down
Loading
Loading