Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Record Service Continuation In Integration #3203

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,28 @@ export default defineComponent({
if (!documentKey || !documentName) return // safety check

state.isDownloading = true
await BusinessService.downloadDocument(documentKey, documentName).catch(error => {
const documentClass = 'CORP'
try {
const docUrl: string = await BusinessService.getDownloadUrl(documentKey, documentClass)
const link = document.createElement('a')
seeker25 marked this conversation as resolved.
Show resolved Hide resolved
link.href = docUrl
link.download = documentName
link.target = '_blank' // This opens the link in a new browser tab

// Append to the document and trigger the download
document.body.appendChild(link)
link.click()

// Remove the link after the download is triggered
document.body.removeChild(link)
state.isDownloading = false
} catch (error) {
// eslint-disable-next-line no-console
console.log('downloadDocument() error =', error)
state.dialogTitle = 'Unable to download document'
state.dialogText = 'An error occurred while downloading the document. Please try again.'
const v = errorDialogComponent.value as any; v.open()
})
state.isDownloading = false
}
}

/**
Expand Down
24 changes: 23 additions & 1 deletion auth-web/src/services/business.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default class BusinessService {
static async fetchFiling (url: string): Promise<any> {
// safety check
if (!url) throw new Error('Invalid parameters')

return axios.get(url)
.then(response => {
const filing = response?.data?.filing
Expand Down Expand Up @@ -206,6 +206,28 @@ export default class BusinessService {
})
}

/**
* Get download url from Document Record Service
* @param documentServiceId the unique id on Document Record Service
* @param documentClass the document class defined for the document service. e.g. 'CORP'
* @returns a promise to return the string of file download.
*/
static async getDownloadUrl (documentKey: string, documentClass: string): Promise<string> {
// safety checks
if (!documentKey || !documentClass) throw new Error('Invalid parameters')

const url = `${ConfigHelper.getLegalAPIV2Url()}/documents/drs/${documentClass}/${documentKey}`

return axios.get(url).then(response => {
seeker25 marked this conversation as resolved.
Show resolved Hide resolved
if (!response) throw new Error('Null response')

return response.data.documentURL
}).catch(error => {
console.log(error)
return ''
})
}

static async searchReviews (reviewFilter: ReviewFilterParams) {
const params = new URLSearchParams()
for (const key in reviewFilter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ const localVue = createLocalVue()
const vuetify = new Vuetify({})

const review = {}

const documentClass = 'CORP'
const filing = {
continuationIn: {
authorization: {
date: '2024-07-01',
files: [
{
fileKey: '0071dbd6-6095-46f6-b5e4-cc859b0ebf27.pdf',
fileKey: 'DS01000000',
fileName: 'My Authorization Document.pdf'
}
]
},
foreignJurisdiction: {
affidavitFileKey: '007bd7bd-d421-49a9-9925-03ce561d044f.pdf',
affidavitFileKey: 'DS99999999',
affidavitFileName: 'My Director Affidavit.pdf',
country: 'CA',
identifier: 'AB-5444',
Expand Down Expand Up @@ -120,12 +120,14 @@ describe('HomeJurisdictionInformation component', () => {
})

it('rendered a functional authorization download button', () => {
BusinessService.downloadDocument = vi.fn().mockResolvedValue(null)
BusinessService.getDownloadUrl = vi.fn().mockResolvedValue(null)

const button = wrapper.findAll('section').at(5).find('.download-authorization-btn')
button.trigger('click')
expect(BusinessService.downloadDocument).toHaveBeenCalledWith('0071dbd6-6095-46f6-b5e4-cc859b0ebf27.pdf',
'My Authorization Document.pdf')
expect(BusinessService.getDownloadUrl).toHaveBeenCalledWith(
'DS01000000',
documentClass
)

vi.clearAllMocks()
})
Expand Down
Loading