From a28e44d846d5a16f88e3c396645986bf16660468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9verin=20Beauvais?= Date: Mon, 17 Jun 2024 10:16:34 -0700 Subject: [PATCH] 21779 Add handling for static documents object (#668) - app version = 7.3.1 - added handling for static documents object - updated unit tests Co-authored-by: Severin Beauvais --- package-lock.json | 4 +- package.json | 2 +- src/stores/filingHistoryListStore.ts | 14 ++++- tests/unit/FilingHistoryList1.spec.ts | 83 +++++++++++++-------------- tests/unit/legal-services.spec.ts | 8 +-- 5 files changed, 57 insertions(+), 54 deletions(-) diff --git a/package-lock.json b/package-lock.json index a819dbff0..2833d33bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "business-filings-ui", - "version": "7.3.0", + "version": "7.3.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "business-filings-ui", - "version": "7.3.0", + "version": "7.3.1", "dependencies": { "@babel/compat-data": "^7.21.5", "@bcrs-shared-components/base-address": "2.0.9", diff --git a/package.json b/package.json index 46492fee2..91a0cd6c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "business-filings-ui", - "version": "7.3.0", + "version": "7.3.1", "private": true, "appName": "Filings UI", "sbcName": "SBC Common Components", diff --git a/src/stores/filingHistoryListStore.ts b/src/stores/filingHistoryListStore.ts index 43a7ae9e5..67955f763 100644 --- a/src/stores/filingHistoryListStore.ts +++ b/src/stores/filingHistoryListStore.ts @@ -294,11 +294,11 @@ export const useFilingHistoryListStore = defineStore('filingHistoryList', { // iterate over documents properties for (const prop in documents) { if (prop === 'legalFilings' && Array.isArray(documents.legalFilings)) { - // iterate over legalFilings array + // iterate over legalFilings array for (const legalFiling of documents.legalFilings) { - // iterate over legalFiling properties + // iterate over legalFiling properties for (const prop in legalFiling) { - // this is a legal filing output + // this is a legal filing output let title: string // use display name for primary document's title if (prop === filing.name) title = filing.displayName @@ -310,6 +310,14 @@ export const useFilingHistoryListStore = defineStore('filingHistoryList', { pushDocument(title, filename, link) } } + } else if (prop === 'staticDocuments' && Array.isArray(documents.staticDocuments)) { + // iterate over staticDocuments array + for (const document of documents.staticDocuments) { + const title = document.name + const filename = title + const link = document.url + pushDocument(title, filename, link) + } } else if (prop === 'uploadedCourtOrder') { const fileNumber = filing.data?.order?.fileNumber || '[unknown]' const title = isStaff ? `${filing.displayName} ${fileNumber}` : `${filing.displayName}` diff --git a/tests/unit/FilingHistoryList1.spec.ts b/tests/unit/FilingHistoryList1.spec.ts index a99a2d99d..e13fd3bde 100644 --- a/tests/unit/FilingHistoryList1.spec.ts +++ b/tests/unit/FilingHistoryList1.spec.ts @@ -26,6 +26,7 @@ import DefaultFiling from '@/components/Dashboard/FilingHistoryList/filings/Defa import AgmExtension from '@/components/Dashboard/FilingHistoryList/filings/AgmExtension.vue' import { FilingTypes } from '@bcrs-shared-components/enums' import { CorpTypeCd, EntityStatus, FilingStatus, FilingSubTypes } from '@/enums' +import { LegalServices } from '@/services' Vue.use(Vuetify) Vue.use(Vuelidate) @@ -2207,13 +2208,9 @@ describe('Filing History List - with documents', () => { // init store filingHistoryListStore.setFilings([FILING_WITH_DOCUMENTS_LINK] as any) - // mock "get documents" - sinon.stub(axios, 'get').withArgs('businesses/CP0001191/filings/111/documents') - .returns(new Promise(resolve => resolve({ - data: { - documents: {} - } - }))) + // mock "fetch documents" + vi.spyOn((LegalServices as any), 'fetchDocuments').mockImplementation( + () => Promise.resolve({})) const wrapper = mount(FilingHistoryList, { vuetify }) await Vue.nextTick() @@ -2227,30 +2224,27 @@ describe('Filing History List - with documents', () => { // expand details await button.trigger('click') + await flushPromises() // wait for expansion transition // verify that Documents List component is not displayed after the item is expanded expect(wrapper.findComponent(DocumentsList).exists()).toBe(false) - sinon.restore() + vi.restoreAllMocks() wrapper.destroy() }) - it.skip('display the documents list when documents are present on a filing', async () => { + it.skip('displays the documents list when documents are present on a filing', async () => { // init store filingHistoryListStore.setFilings([FILING_WITH_DOCUMENTS_LINK] as any) - // mock "get documents" - sinon.stub(axios, 'get').withArgs('businesses/CP0001191/filings/111/documents') - .returns(new Promise(resolve => resolve({ - data: { - documents: { - legalFilings: [ - { annualReport: 'businesses/CP0000840/filings/112758/documents/annualReport' } - ], - receipt: 'businesses/CP0000840/filings/112758/documents/receipt' - } - } - }))) + // mock "fetch documents" + vi.spyOn((LegalServices as any), 'fetchDocuments').mockImplementation( + () => Promise.resolve({ + legalFilings: [ + { annualReport: 'businesses/CP0000840/filings/112758/documents/annualReport' } + ], + receipt: 'businesses/CP0000840/filings/112758/documents/receipt' + })) const wrapper = mount(FilingHistoryList, { vuetify }) await Vue.nextTick() @@ -2258,11 +2252,8 @@ describe('Filing History List - with documents', () => { // verify that Documents List component does not exist before the item is expanded expect(wrapper.findComponent(DocumentsList).exists()).toBe(false) - // verify View Documents button - const button = wrapper.find('.expand-btn') - expect(button.text()).toContain('View Documents') - // expand details + const button = wrapper.find('.expand-btn') await button.trigger('click') await flushPromises() // wait for expansion transition @@ -2272,28 +2263,30 @@ describe('Filing History List - with documents', () => { // verify the number of documents expect(wrapper.findAll('.documents-list .download-one-btn').length).toBe(2) - sinon.restore() + vi.restoreAllMocks() wrapper.destroy() }) - it.skip('computes proper document titles from the documents data', async () => { + it('computes proper document titles from the documents data', async () => { // init store filingHistoryListStore.setFilings([FILING_WITH_DOCUMENTS_LINK] as any) - // mock "get documents" - sinon.stub(axios, 'get').withArgs('businesses/CP0001191/filings/111/documents') - .returns(new Promise(resolve => resolve({ - data: { - documents: { - legalFilings: [ - { annualReport: 'businesses/CP0000840/filings/112758/documents/annualReport' }, - { addressChange: 'businesses/CP0000840/filings/112758/documents/addressChange' }, - { directorChange: 'businesses/CP0000840/filings/112758/documents/directorChange' } - ], - receipt: 'businesses/CP0000840/filings/112758/documents/receipt' + // mock "fetch documents" + vi.spyOn((LegalServices as any), 'fetchDocuments').mockImplementation( + () => Promise.resolve({ + legalFilings: [ + { annualReport: 'businesses/CP0000840/filings/112758/documents/annualReport' }, + { addressChange: 'businesses/CP0000840/filings/112758/documents/addressChange' }, + { directorChange: 'businesses/CP0000840/filings/112758/documents/directorChange' } + ], + staticDocuments: [ + { + name: 'My Static Document.pdf', + url: 'businesses/CP0000840/filings/112758/documents/myStaticDocument.pdf' } - } - }))) + ], + receipt: 'businesses/CP0000840/filings/112758/documents/receipt' + })) const wrapper = mount(FilingHistoryList, { propsData: { highlightId: 666 }, @@ -2302,7 +2295,8 @@ describe('Filing History List - with documents', () => { await Vue.nextTick() // expand details - await wrapper.find('.expand-btn').trigger('click') + const button = wrapper.find('.expand-btn') + await button.trigger('click') await flushPromises() // wait for expansion transition // verify that Documents List component is displayed after the item is expanded @@ -2310,13 +2304,14 @@ describe('Filing History List - with documents', () => { // verify document titles const downloadBtns = wrapper.findAll('.documents-list .download-one-btn') - expect(downloadBtns.length).toBe(4) + expect(downloadBtns.length).toBe(5) expect(downloadBtns.at(0).text()).toContain('Annual Report (2019)') expect(downloadBtns.at(1).text()).toContain('Address Change') expect(downloadBtns.at(2).text()).toContain('Director Change') - expect(downloadBtns.at(3).text()).toContain('Receipt') + expect(downloadBtns.at(3).text()).toContain('My Static Document.pdf') + expect(downloadBtns.at(4).text()).toContain('Receipt') - sinon.restore() + vi.restoreAllMocks() wrapper.destroy() }) }) diff --git a/tests/unit/legal-services.spec.ts b/tests/unit/legal-services.spec.ts index 4b43f9289..b29d1f46c 100644 --- a/tests/unit/legal-services.spec.ts +++ b/tests/unit/legal-services.spec.ts @@ -208,10 +208,10 @@ describe('Legal Services', () => { .returns(new Promise(resolve => resolve({ data: { comments: COMMENTS } }))) // call method - const comments = await LegalServices.fetchComments('COMMENTS_URL') + const response = await LegalServices.fetchComments('COMMENTS_URL') // verify data - expect(comments).toEqual(COMMENTS) + expect(response).toEqual(COMMENTS) }) it('fetches documents correctly', async () => { @@ -230,10 +230,10 @@ describe('Legal Services', () => { .returns(new Promise(resolve => resolve({ data: { documents: DOCUMENTS } }))) // call method - const comments = await LegalServices.fetchDocuments(URL) + const response = await LegalServices.fetchDocuments(URL) // verify data - expect(comments).toEqual(DOCUMENTS) + expect(response).toEqual(DOCUMENTS) }) it('fetches one document correctly', async () => {