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

adding error checking for hooks & API helper functions #54

Merged
merged 4 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
27 changes: 15 additions & 12 deletions tests/e2e/api/APIHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ import axios from 'axios'
import join from 'join-path'

export const sendRequest = function ({ method, path, header = null, data = null }): Promise<any> {
const headers = {
...header,
Authorization: `Basic ${Buffer.from(`${config.adminUser}:${config.adminPassword}`).toString(
'base64'
)}`
try {
const headers = {
...header,
Authorization: `Basic ${Buffer.from(`${config.adminUser}:${config.adminPassword}`).toString(
'base64'
)}`
}
return axios({
method,
url: join(config.baseUrlOcis, path),
headers,
data
})
} catch (error) {
throw new Error(error.message)
}

return axios({
method,
url: join(config.baseUrlOcis, path),
headers,
data
})
}
17 changes: 14 additions & 3 deletions tests/e2e/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,21 @@ const deleteDicomFile = async function (): Promise<void> {
const result = xml2js(xmlResponse, { compact: true })
const resp = _.get(result, 'd:multistatus.d:response')
const href = _.get(resp[1], 'd:href._text')

await sendRequest({ method: 'DELETE', path: href })
const response2 = await sendRequest({
method: 'DELETE',
path: href
})
if (response2.status !== 204) {
throw new Error(`Failed to delete dicom file`)
}
}

const emptyTrashbin = async function (): Promise<void> {
await sendRequest({ method: 'DELETE', path: 'remote.php/dav/trash-bin/admin' })
const response = await sendRequest({
method: 'DELETE',
path: 'remote.php/dav/trash-bin/admin'
})
if (response.status !== 204) {
throw new Error(`Failed to empty trashbin`)
}
}