Skip to content

Commit

Permalink
21779 Add handling for static documents object (bcgov#668)
Browse files Browse the repository at this point in the history
- app version = 7.3.1
- added handling for static documents object
- updated unit tests

Co-authored-by: Severin Beauvais <[email protected]>
  • Loading branch information
severinbeauvais and Severin Beauvais authored Jun 17, 2024
1 parent fc64ad7 commit a28e44d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 54 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
14 changes: 11 additions & 3 deletions src/stores/filingHistoryListStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}`
Expand Down
83 changes: 39 additions & 44 deletions tests/unit/FilingHistoryList1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -2227,42 +2224,36 @@ 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()

// 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

Expand All @@ -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 },
Expand All @@ -2302,21 +2295,23 @@ 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
expect(wrapper.findComponent(DocumentsList).exists()).toBe(true)

// 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()
})
})
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/legal-services.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand Down

0 comments on commit a28e44d

Please sign in to comment.