Skip to content

Commit

Permalink
Merge pull request #54 from owncloud/error-checking-for-helper-functions
Browse files Browse the repository at this point in the history
adding error checking for hooks & API helper functions
  • Loading branch information
koebel authored Aug 20, 2024
2 parents 12df68f + 4ed9e13 commit e528bd1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
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`)
}
}

0 comments on commit e528bd1

Please sign in to comment.