diff --git a/frontend/src/views/admin/GroupsView.vue b/frontend/src/views/admin/GroupsView.vue index d019a24b8ef1..612624904d7b 100644 --- a/frontend/src/views/admin/GroupsView.vue +++ b/frontend/src/views/admin/GroupsView.vue @@ -6087,7 +6087,7 @@ const handleCreateGroup = async () => { } } catch (error: any) { appStore.showError( - error.response?.data?.detail || t("admin.groups.failedToCreate"), + extractApiErrorMessage(error, t("admin.groups.failedToCreate")), ); console.error("Error creating group:", error); // Don't advance tour on error @@ -6358,7 +6358,7 @@ const handleUpdateGroup = async () => { loadGroups(); } catch (error: any) { appStore.showError( - error.response?.data?.detail || t("admin.groups.failedToUpdate"), + extractApiErrorMessage(error, t("admin.groups.failedToUpdate")), ); console.error("Error updating group:", error); } finally { diff --git a/frontend/src/views/admin/__tests__/GroupsView.duplicate.spec.ts b/frontend/src/views/admin/__tests__/GroupsView.duplicate.spec.ts index 151737e04921..10690d87e338 100644 --- a/frontend/src/views/admin/__tests__/GroupsView.duplicate.spec.ts +++ b/frontend/src/views/admin/__tests__/GroupsView.duplicate.spec.ts @@ -8,6 +8,7 @@ import GroupsView from '@/views/admin/GroupsView.vue' const { listGroups, duplicateGroup, + updateGroup, getModelsListCandidates, getUsageSummary, getCapacitySummary, @@ -17,6 +18,7 @@ const { } = vi.hoisted(() => ({ listGroups: vi.fn(), duplicateGroup: vi.fn(), + updateGroup: vi.fn(), getModelsListCandidates: vi.fn(), getUsageSummary: vi.fn(), getCapacitySummary: vi.fn(), @@ -36,7 +38,7 @@ vi.mock('@/api/admin', () => ({ getLiveCapability, getAll: vi.fn(), create: vi.fn(), - update: vi.fn(), + update: updateGroup, delete: vi.fn(), updateSortOrder: vi.fn() }, @@ -136,6 +138,13 @@ const DataTableStub = defineComponent({ template: '
' }) +const BaseDialogStub = defineComponent({ + props: { + show: { type: Boolean, default: false } + }, + template: '
' +}) + function mountView() { return mount(GroupsView, { global: { @@ -144,7 +153,7 @@ function mountView() { TablePageLayout: TablePageLayoutStub, DataTable: DataTableStub, Pagination: true, - BaseDialog: true, + BaseDialog: BaseDialogStub, ConfirmDialog: true, EmptyState: true, Select: true, @@ -166,6 +175,7 @@ describe('GroupsView duplicate action', () => { for (const fn of [ listGroups, duplicateGroup, + updateGroup, getModelsListCandidates, getUsageSummary, getCapacitySummary, @@ -270,4 +280,26 @@ describe('GroupsView duplicate action', () => { expect(showError).not.toHaveBeenCalledWith('admin.groups.duplicateFailed') wrapper.unmount() }) + + it('shows the standardized API message when updating a group fails', async () => { + updateGroup.mockRejectedValueOnce({ + status: 409, + code: 409, + message: 'group name already exists', + reason: 'GROUP_EXISTS' + }) + const wrapper = mountView() + await flushPromises() + + const editButton = wrapper.findAll('button').find((button) => button.text() === 'common.edit') + expect(editButton).toBeTruthy() + await editButton!.trigger('click') + await flushPromises() + await wrapper.get('#edit-group-form').trigger('submit') + await flushPromises() + + expect(updateGroup).toHaveBeenCalledTimes(1) + expect(showError).toHaveBeenCalledWith('group name already exists') + wrapper.unmount() + }) })