From 3ce68ad56179b033a874bf66ff10eed87e59d33f Mon Sep 17 00:00:00 2001 From: panish16 Date: Thu, 26 Nov 2026 21:07:36 -0700 Subject: [PATCH 1/4] chore(ui): bump examiner, host and strata versions (REGBACKLOG-476) --- strr-examiner-web/package.json | 2 +- strr-host-pm-web/package.json | 2 +- strr-strata-web/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/strr-examiner-web/package.json b/strr-examiner-web/package.json index 4891b675c..f28cf75de 100644 --- a/strr-examiner-web/package.json +++ b/strr-examiner-web/package.json @@ -2,7 +2,7 @@ "name": "strr-examiner-web", "private": true, "type": "module", - "version": "0.2.72", + "version": "0.2.73", "engines": { "node": ">=24" }, diff --git a/strr-host-pm-web/package.json b/strr-host-pm-web/package.json index 295e42849..dbf9932ad 100644 --- a/strr-host-pm-web/package.json +++ b/strr-host-pm-web/package.json @@ -2,7 +2,7 @@ "name": "strr-host-pm-web", "private": true, "type": "module", - "version": "1.3.38", + "version": "1.3.39", "engines": { "node": ">=24" }, diff --git a/strr-strata-web/package.json b/strr-strata-web/package.json index 37395c27b..43c7b7d2e 100644 --- a/strr-strata-web/package.json +++ b/strr-strata-web/package.json @@ -2,7 +2,7 @@ "name": "strr-strata-web", "private": true, "type": "module", - "version": "1.2.14", + "version": "1.2.15", "engines": { "node": ">=24" }, From 5df49e6638afc4f93abf467fa229aedee4a95661 Mon Sep 17 00:00:00 2001 From: panish16 Date: Thu, 26 Nov 2026 21:22:34 -0700 Subject: [PATCH 2/4] fix(ui): drop removeStoredDocument from failed dashboard upload catch (REGBACKLOG-476) The doc is only pushed to storedDocuments as the last step of the try, so on failure there is nothing to remove. Calling it with a doc not in the list hit splice(-1, 1) and dropped the last stored doc. Replaces the index === -1 guard (Sonar flagged the duplicated guard in host/strata). --- strr-host-pm-web/app/stores/document.ts | 4 ---- strr-strata-web/app/stores/document.ts | 4 ---- 2 files changed, 8 deletions(-) diff --git a/strr-host-pm-web/app/stores/document.ts b/strr-host-pm-web/app/stores/document.ts index e31705176..555889f4f 100644 --- a/strr-host-pm-web/app/stores/document.ts +++ b/strr-host-pm-web/app/stores/document.ts @@ -355,9 +355,6 @@ export const useDocumentStore = defineStore('host/document', () => { async function removeStoredDocument (uiDoc: UiDocument) { // Remove document from local list to ensure createApplicationBody uses updated list const index = storedDocuments.value.findIndex(item => uiDoc.id === item.id) - if (index === -1) { - return // not in the list (e.g. upload failed before it was added), nothing to remove - } storedDocuments.value.splice(index, 1) // Save draft with updated document list @@ -436,7 +433,6 @@ export const useDocumentStore = defineStore('host/document', () => { } catch (e) { logFetchError(e, 'Error uploading document') strrModal.openErrorModal(t('error.docUpload.generic.title'), t('error.docUpload.generic.description'), false) - await removeStoredDocument(uiDoc) } finally { // cleanup loading on ui object uiDoc.loading = false diff --git a/strr-strata-web/app/stores/document.ts b/strr-strata-web/app/stores/document.ts index 0b7156a64..8750f81c2 100644 --- a/strr-strata-web/app/stores/document.ts +++ b/strr-strata-web/app/stores/document.ts @@ -41,9 +41,6 @@ export const useDocumentStore = defineStore('strata/document', () => { async function removeStoredDocument (uiDoc: UiDocument) { const index = storedDocuments.value.findIndex(item => uiDoc.id === item.id) - if (index === -1) { - return // not in the list (e.g. upload failed before it was added), nothing to remove - } storedDocuments.value.splice(index, 1) if (uiDoc.apiDoc.fileKey) { await deleteDocument(uiDoc.apiDoc.fileKey) @@ -83,7 +80,6 @@ export const useDocumentStore = defineStore('strata/document', () => { } catch (e) { logFetchError(e, 'Error uploading document') strrModal.openErrorModal(t('error.docUpload.generic.title'), t('error.docUpload.generic.description'), false) - await removeStoredDocument(uiDoc) } finally { // cleanup loading on ui object uiDoc.loading = false From 4214758ddba6a36630755ae31929294f84bbad26 Mon Sep 17 00:00:00 2001 From: panish16 Date: Fri, 27 Nov 2026 11:52:33 -0700 Subject: [PATCH 3/4] fix(ui): address #1938 review (REGBACKLOG-476) - base: guard removeDocumentFromList against index -1 (bump base to 0.0.64) - examiner: JSDoc says upload fns always resolve; add addDocumentToApplication failure test - strata: add rejected dashboard upload test (list unchanged, no DELETE) --- .../BaseUploadAdditionalDocuments.vue | 4 ++- strr-base-web/package.json | 2 +- strr-examiner-web/app/stores/document.ts | 4 +-- .../tests/unit/store-document.spec.ts | 26 +++++++++++++++ .../tests/unit/store-document.spec.ts | 33 ++++++++++++++++++- 5 files changed, 64 insertions(+), 5 deletions(-) diff --git a/strr-base-web/app/components/BaseUploadAdditionalDocuments.vue b/strr-base-web/app/components/BaseUploadAdditionalDocuments.vue index 61e29e9d9..6dd5c0803 100644 --- a/strr-base-web/app/components/BaseUploadAdditionalDocuments.vue +++ b/strr-base-web/app/components/BaseUploadAdditionalDocuments.vue @@ -42,7 +42,9 @@ const addDocumentToList = (doc: File) => { const removeDocumentFromList = (uiDoc: UiDocument) => { const index = documentList.value.findIndex(item => uiDoc.id === item.id) - documentList.value.splice(index, 1) + if (index !== -1) { + documentList.value.splice(index, 1) + } } const cancelDocumentsUpload = () => { diff --git a/strr-base-web/package.json b/strr-base-web/package.json index e6c8927e3..91028e8b0 100644 --- a/strr-base-web/package.json +++ b/strr-base-web/package.json @@ -2,7 +2,7 @@ "name": "strr-base-web", "private": true, "type": "module", - "version": "0.0.63", + "version": "0.0.64", "engines": { "node": ">=24" }, diff --git a/strr-examiner-web/app/stores/document.ts b/strr-examiner-web/app/stores/document.ts index 8ee064e66..b7026244d 100644 --- a/strr-examiner-web/app/stores/document.ts +++ b/strr-examiner-web/app/stores/document.ts @@ -96,7 +96,7 @@ export const useExaminerDocumentStore = defineStore('examiner/document', () => { * * @param {UiDocument} uiDoc - The document to upload, containing file data and metadata. * @param {number} registrationId - The registration ID to which the document is being added. - * @returns {Promise} A promise that resolves when the document has been added or rejects if an error occurs. + * @returns {Promise} Always resolves; upload errors are shown in an error modal instead of being thrown. */ async function addDocumentToRegistration (uiDoc: UiDocument, registrationId: number): Promise { try { @@ -140,7 +140,7 @@ export const useExaminerDocumentStore = defineStore('examiner/document', () => { * * @param {UiDocument} uiDoc - The document to upload, containing file data and metadata. * @param {string} applicationNumber - The application number to which the document is being added. - * @returns {Promise} A promise that resolves when the document has been added or rejects if an error occurs. + * @returns {Promise} Always resolves; upload errors are shown in an error modal instead of being thrown. */ async function addDocumentToApplication (uiDoc: UiDocument, applicationNumber: string): Promise { try { diff --git a/strr-examiner-web/tests/unit/store-document.spec.ts b/strr-examiner-web/tests/unit/store-document.spec.ts index 5553e3fdd..1b72a995a 100644 --- a/strr-examiner-web/tests/unit/store-document.spec.ts +++ b/strr-examiner-web/tests/unit/store-document.spec.ts @@ -80,6 +80,32 @@ describe('Document Store', () => { expect(exStore.activeReg!.documents).toHaveLength(mockDocuments.length) // no doc appended }) + it('should show error modal and resolve when adding document to application fails', async () => { + const exStore = useExaminerStore() + exStore.activeRecord = { ...mockHostRegistration, documents: [...mockDocuments] } + const recordBefore = exStore.activeRecord + + const docStore = useExaminerDocumentStore() + mockStrrApi.mockRejectedValueOnce(new Error('Upload failed')) + + const uiDoc = { + file: new File(['content'], 'utility-bill.pdf', { type: 'application/pdf' }), + type: DocumentUploadType.UTILITY_BILL, + loading: false + } as UiDocument + + await expect(docStore.addDocumentToApplication(uiDoc, 'APP12345')).resolves.toBeUndefined() + + expect(mockOpenErrorModal).toHaveBeenCalledWith( + 'error.docUpload.generic.title', + 'error.docUpload.generic.description', + false + ) + expect(uiDoc.loading).toBe(false) + expect(exStore.activeRecord).toBe(recordBefore) // record not replaced + expect(exStore.activeReg!.documents).toHaveLength(mockDocuments.length) + }) + it('should append document to activeReg when adding document to registration', async () => { const exStore = useExaminerStore() exStore.activeRecord = { ...mockHostRegistration, documents: [...mockDocuments] } diff --git a/strr-strata-web/tests/unit/store-document.spec.ts b/strr-strata-web/tests/unit/store-document.spec.ts index e7989b974..a3c6b589c 100644 --- a/strr-strata-web/tests/unit/store-document.spec.ts +++ b/strr-strata-web/tests/unit/store-document.spec.ts @@ -1,9 +1,23 @@ -import { describe, beforeEach, it, expect } from 'vitest' +import { describe, beforeEach, it, expect, vi } from 'vitest' +import { mockNuxtImport } from '@nuxt/test-utils/runtime' import { mockStoredDocument } from '../mocks/mockedData' +const mockStrrApi = vi.fn().mockResolvedValue(undefined) +const mockOpenErrorModal = vi.fn() + +mockNuxtImport('useNuxtApp', original => () => Object.assign(Object.create(original()), { + $strrApi: mockStrrApi, + $i18n: { t: (key: string) => key } +})) + +mockNuxtImport('useStrrModals', () => () => ({ openErrorModal: mockOpenErrorModal })) + describe('Document Store', () => { beforeEach(() => { useDocumentStore().$reset() + mockStrrApi.mockReset() + mockStrrApi.mockResolvedValue(undefined) + mockOpenErrorModal.mockClear() }) it('reset function clears storedDocuments', () => { @@ -70,4 +84,21 @@ describe('Document Store', () => { await store.resetApiDocs() expect(store.storedDocuments).toHaveLength(0) }) + + it('keeps existing documents and deletes nothing when a dashboard upload is rejected', async () => { + const store = useDocumentStore() + store.storedDocuments.push(mockStoredDocument) + mockStrrApi.mockRejectedValueOnce(new Error('File contents do not match the file type')) + // upload never succeeded, so the new doc has no apiDoc and was never added to storedDocuments + const rejectedDoc: UiDocument = { ...mockStoredDocument, id: 'doc-rejected', apiDoc: {} as ApiDocument } + + await store.addDocumentToApplication(rejectedDoc, 'APP-123') + + expect(mockOpenErrorModal).toHaveBeenCalled() + expect(store.storedDocuments).toHaveLength(1) + expect(store.storedDocuments[0]!.id).toBe(mockStoredDocument.id) + // only the failed PUT, no DELETE /documents/{fileKey} + expect(mockStrrApi).toHaveBeenCalledTimes(1) + expect(mockStrrApi).toHaveBeenCalledWith('/applications/APP-123/documents', expect.objectContaining({ method: 'PUT' })) + }) }) From f97662238d10c448342eee2fe3cefeac47edcaae Mon Sep 17 00:00:00 2001 From: panish16 Date: Fri, 27 Nov 2026 13:29:43 -0700 Subject: [PATCH 4/4] fix(ui): keep the not-found guard in removeStoredDocument (REGBACKLOG-476) findIndex returns -1 for a doc that's not in the list (double click on remove, or removed while its upload was still running), and splice(-1, 1) then drops the last real document. Return early in host and strata, with a regression test in each. --- strr-host-pm-web/app/stores/document.ts | 4 ++++ .../tests/unit/store-document.spec.ts | 15 +++++++++++++++ strr-strata-web/app/stores/document.ts | 3 +++ .../tests/unit/store-document.spec.ts | 16 ++++++++++++++++ 4 files changed, 38 insertions(+) diff --git a/strr-host-pm-web/app/stores/document.ts b/strr-host-pm-web/app/stores/document.ts index 555889f4f..b76c46cc9 100644 --- a/strr-host-pm-web/app/stores/document.ts +++ b/strr-host-pm-web/app/stores/document.ts @@ -355,6 +355,10 @@ export const useDocumentStore = defineStore('host/document', () => { async function removeStoredDocument (uiDoc: UiDocument) { // Remove document from local list to ensure createApplicationBody uses updated list const index = storedDocuments.value.findIndex(item => uiDoc.id === item.id) + if (index === -1) { + // already removed (e.g. double click) or never added - splice(-1, 1) would drop the last document + return + } storedDocuments.value.splice(index, 1) // Save draft with updated document list diff --git a/strr-host-pm-web/tests/unit/store-document.spec.ts b/strr-host-pm-web/tests/unit/store-document.spec.ts index e534e17d0..97b096832 100644 --- a/strr-host-pm-web/tests/unit/store-document.spec.ts +++ b/strr-host-pm-web/tests/unit/store-document.spec.ts @@ -511,6 +511,21 @@ describe('Document Removal', () => { expect(mockSubmitApplication).not.toHaveBeenCalled() }) + it('should leave the list alone and not save or delete when the document is not in it', async () => { + const store = useDocumentStore() + const docA = makeUiDoc('1', DocumentUploadType.BC_DRIVERS_LICENSE) + const docB = makeUiDoc('2', DocumentUploadType.UTILITY_BILL) + store.storedDocuments = [docA, docB] + mockPermitStore.application = { header: { status: 'draft', applicationNumber: 'APP-123' } } + + // e.g. second click on remove, or a doc removed while its upload was still running + await store.removeStoredDocument(makeUiDoc('3', DocumentUploadType.UTILITY_BILL)) + + expect(store.storedDocuments.map(d => d.id)).toEqual(['1', '2']) + expect(mockSubmitApplication).not.toHaveBeenCalled() + expect(mockStrrApi).not.toHaveBeenCalled() + }) + it('should not remove any document if names do not match the given types', async () => { const store = useDocumentStore() store.storedDocuments = [makeUiDoc('1', DocumentUploadType.BC_DRIVERS_LICENSE)] diff --git a/strr-strata-web/app/stores/document.ts b/strr-strata-web/app/stores/document.ts index 8750f81c2..f9f0be25b 100644 --- a/strr-strata-web/app/stores/document.ts +++ b/strr-strata-web/app/stores/document.ts @@ -41,6 +41,9 @@ export const useDocumentStore = defineStore('strata/document', () => { async function removeStoredDocument (uiDoc: UiDocument) { const index = storedDocuments.value.findIndex(item => uiDoc.id === item.id) + if (index < 0) { + return // not in the list, nothing to remove or delete + } storedDocuments.value.splice(index, 1) if (uiDoc.apiDoc.fileKey) { await deleteDocument(uiDoc.apiDoc.fileKey) diff --git a/strr-strata-web/tests/unit/store-document.spec.ts b/strr-strata-web/tests/unit/store-document.spec.ts index a3c6b589c..128aa06cc 100644 --- a/strr-strata-web/tests/unit/store-document.spec.ts +++ b/strr-strata-web/tests/unit/store-document.spec.ts @@ -85,6 +85,22 @@ describe('Document Store', () => { expect(store.storedDocuments).toHaveLength(0) }) + it('does nothing when removing a document that is not in storedDocuments', async () => { + const store = useDocumentStore() + store.storedDocuments.push(mockStoredDocument) + const missingDoc: UiDocument = { + ...mockStoredDocument, + id: 'doc-missing', + apiDoc: { ...mockStoredDocument.apiDoc, fileKey: 'missing-key' } + } + + await store.removeStoredDocument(missingDoc) + + expect(store.storedDocuments).toHaveLength(1) + expect(store.storedDocuments[0]!.id).toBe(mockStoredDocument.id) + expect(mockStrrApi).not.toHaveBeenCalled() + }) + it('keeps existing documents and deletes nothing when a dashboard upload is rejected', async () => { const store = useDocumentStore() store.storedDocuments.push(mockStoredDocument)