From 76d8b2e03ab50ec3a7cfd2014eb99fff1b6da336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Ch=C3=A1vez?= Date: Wed, 22 Oct 2025 17:07:24 -0500 Subject: [PATCH] feat: Add error messages for partial migration [FC-0107] (#2555) Adds the error messages for partial migrations --- .../LegacyLibMigrationPage.test.tsx | 2 +- .../data/api.mocks.ts | 74 +++++++++++++++++++ src/legacy-libraries-migration/data/api.ts | 1 + src/legacy-libraries-migration/messages.ts | 12 ++- .../LibraryAuthoringPage.test.tsx | 28 ++++++- .../LibraryAuthoringPage.tsx | 17 ++++- 6 files changed, 130 insertions(+), 4 deletions(-) diff --git a/src/legacy-libraries-migration/LegacyLibMigrationPage.test.tsx b/src/legacy-libraries-migration/LegacyLibMigrationPage.test.tsx index a752dc686..79110706a 100644 --- a/src/legacy-libraries-migration/LegacyLibMigrationPage.test.tsx +++ b/src/legacy-libraries-migration/LegacyLibMigrationPage.test.tsx @@ -418,7 +418,7 @@ describe('', () => { expect(axiosMock.history.post[0].data).toBe( '{"sources":["library-v1:MBA+123","library-v1:UNIX+LG1","library-v1:MBA+1234"],"target":"lib:SampleTaxonomyOrg1:TL1","create_collections":true,"repeat_handling_strategy":"fork"}', ); - expect(mockShowToast).toHaveBeenCalledWith('Legacy libraries migration failed.'); + expect(mockShowToast).toHaveBeenCalledWith('Legacy libraries migration have failed'); }); it('should show help sidebar', async () => { diff --git a/src/legacy-libraries-migration/data/api.mocks.ts b/src/legacy-libraries-migration/data/api.mocks.ts index a4d2d583f..2386fb474 100644 --- a/src/legacy-libraries-migration/data/api.mocks.ts +++ b/src/legacy-libraries-migration/data/api.mocks.ts @@ -6,6 +6,10 @@ export async function mockGetMigrationStatus(migrationId: string): Promise', () => { }, }); - await waitFor(() => expect(mockShowToast).toHaveBeenCalledWith('Legacy libraries migration failed.')); + await waitFor(() => expect(mockShowToast).toHaveBeenCalledWith('Legacy libraries migration have failed')); + }); + + it('Should show fail multiple legacy libraries in a migration', async () => { + render(, { + path, + routerProps: { + initialEntries: [ + `/library/${mockContentLibrary.libraryId}?migration_task=${mockGetMigrationStatus.migrationIdMultiple}`, + ], + }, + }); + + await waitFor(() => expect(mockShowToast).toHaveBeenCalledWith('Multiple legacy libraries have failed')); + }); + + it('Should show fail one legacy library in a migration', async () => { + render(, { + path, + routerProps: { + initialEntries: [ + `/library/${mockContentLibrary.libraryId}?migration_task=${mockGetMigrationStatus.migrationIdOneLibrary}`, + ], + }, + }); + + await waitFor(() => expect(mockShowToast).toHaveBeenCalledWith('The legacy library with this key has failed: legacy-lib-1')); }); }); diff --git a/src/library-authoring/LibraryAuthoringPage.tsx b/src/library-authoring/LibraryAuthoringPage.tsx index 90ee0040e..63689635f 100644 --- a/src/library-authoring/LibraryAuthoringPage.tsx +++ b/src/library-authoring/LibraryAuthoringPage.tsx @@ -225,10 +225,25 @@ const LibraryAuthoringPage = ({ if (migrationId) { let deleteMigrationIdParam = false; if (migrationStatusData?.state === 'Succeeded') { - showToast(intl.formatMessage(migrationMessages.migrationSuccess)); + // Check if any library migrations failed. + // A `Succeeded` state means that the bulk migration ended, but some libraries might have failed. + const failedMigrations = migrationStatusData.parameters.filter(item => item.isFailed); + if (failedMigrations.length > 1) { + showToast(intl.formatMessage(migrationMessages.migrationFailedMultiple)); + } else if (failedMigrations.length === 1) { + showToast(intl.formatMessage( + migrationMessages.migrationFailedOneLibrary, + { + key: failedMigrations[0].source, + }, + )); + } else { + showToast(intl.formatMessage(migrationMessages.migrationSuccess)); + } queryClient.invalidateQueries({ predicate: (query) => libraryQueryPredicate(query, libraryId) }); deleteMigrationIdParam = true; } else if (migrationStatusData?.state === 'Failed') { + // A `Failed` state means that the entire bulk migration has failed. showToast(intl.formatMessage(migrationMessages.migrationFailed)); deleteMigrationIdParam = true; } else if (migrationStatusData?.state === 'Canceled') {