From 41ff2f9b385777b9590245ee3789a80d50436b5c Mon Sep 17 00:00:00 2001 From: Kathrin Koebel Date: Wed, 14 Aug 2024 16:22:23 +0545 Subject: [PATCH 1/4] adding error if trashbin wasn't deleted properly --- tests/e2e/hooks.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/e2e/hooks.ts b/tests/e2e/hooks.ts index bd73dfda..8fb7dd2e 100644 --- a/tests/e2e/hooks.ts +++ b/tests/e2e/hooks.ts @@ -40,6 +40,13 @@ const deleteDicomFile = async function (): Promise { await sendRequest({ method: 'DELETE', path: href }) } -const emptyTrashbin = async function (): Promise { - await sendRequest({ method: 'DELETE', path: 'remote.php/dav/trash-bin/admin' }) +const emptyTrashbin = async function (): Promise { + const response = await sendRequest({ + method: 'DELETE', + path: 'remote.php/dav/trash-bin/admin' + }) + if (response.status !== 204) { + throw new Error(`Failed to empty trashbin`) + } + return response.status } From d1571bcd74e7531c438273ebc281083cc6836067 Mon Sep 17 00:00:00 2001 From: Kathrin Koebel Date: Wed, 14 Aug 2024 16:33:41 +0545 Subject: [PATCH 2/4] adding error if file hasn't been properly deleted --- tests/e2e/hooks.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/e2e/hooks.ts b/tests/e2e/hooks.ts index 8fb7dd2e..8ae02450 100644 --- a/tests/e2e/hooks.ts +++ b/tests/e2e/hooks.ts @@ -30,14 +30,20 @@ After(async function (): Promise { await global.page.close() }) -const deleteDicomFile = async function (): Promise { +const deleteDicomFile = async function (): Promise { const response = await sendRequest({ method: 'PROPFIND', path: 'remote.php/dav/files/admin' }) const xmlResponse = response.data 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 file`) + } + return response2.status } const emptyTrashbin = async function (): Promise { From 7ff32d465aab2c7f16b98d70c66abc9646902683 Mon Sep 17 00:00:00 2001 From: Kathrin Koebel Date: Wed, 14 Aug 2024 17:06:03 +0545 Subject: [PATCH 3/4] removing unnecessary return values --- tests/e2e/hooks.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/e2e/hooks.ts b/tests/e2e/hooks.ts index 8ae02450..f6d61d23 100644 --- a/tests/e2e/hooks.ts +++ b/tests/e2e/hooks.ts @@ -30,7 +30,7 @@ After(async function (): Promise { await global.page.close() }) -const deleteDicomFile = async function (): Promise { +const deleteDicomFile = async function (): Promise { const response = await sendRequest({ method: 'PROPFIND', path: 'remote.php/dav/files/admin' }) const xmlResponse = response.data const result = xml2js(xmlResponse, { compact: true }) @@ -41,12 +41,11 @@ const deleteDicomFile = async function (): Promise { path: href }) if (response2.status !== 204) { - throw new Error(`Failed to delete file`) + throw new Error(`Failed to delete dicom file`) } - return response2.status } -const emptyTrashbin = async function (): Promise { +const emptyTrashbin = async function (): Promise { const response = await sendRequest({ method: 'DELETE', path: 'remote.php/dav/trash-bin/admin' @@ -54,5 +53,4 @@ const emptyTrashbin = async function (): Promise { if (response.status !== 204) { throw new Error(`Failed to empty trashbin`) } - return response.status } From 4ed9e1326ed4eab84ba0c63c8b628a522977d97d Mon Sep 17 00:00:00 2001 From: Kathrin Koebel Date: Wed, 14 Aug 2024 17:06:31 +0545 Subject: [PATCH 4/4] adding try & catch to API request --- tests/e2e/api/APIHelper.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/tests/e2e/api/APIHelper.ts b/tests/e2e/api/APIHelper.ts index adc92139..06036d88 100644 --- a/tests/e2e/api/APIHelper.ts +++ b/tests/e2e/api/APIHelper.ts @@ -3,17 +3,20 @@ import axios from 'axios' import join from 'join-path' export const sendRequest = function ({ method, path, header = null, data = null }): Promise { - 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 - }) }