From 0953ccdb0bf67336b5e97921ce4f58d9f028c65e Mon Sep 17 00:00:00 2001 From: Dipak Acharya Date: Tue, 22 Sep 2020 09:19:00 +0545 Subject: [PATCH 1/2] [Tests-Only] Improve error handling in tests --- tests/acceptance/helpers/httpHelper.js | 15 +++++++++------ .../stepDefinitions/generalContext.js | 18 +++++++++++++++--- .../stepDefinitions/provisioningContext.js | 3 +++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/tests/acceptance/helpers/httpHelper.js b/tests/acceptance/helpers/httpHelper.js index a97a970bd96..7671a9a7444 100644 --- a/tests/acceptance/helpers/httpHelper.js +++ b/tests/acceptance/helpers/httpHelper.js @@ -36,29 +36,32 @@ const createOCSRequestHeaders = function(userId) { * @throws Error * @returns {node-fetch.Response} */ -const checkStatus = function(response, message) { +const checkStatus = function(response, message = '') { if (response.ok) { // response.status >= 200 && response.status < 300 return response } else { - throw Error(message + ' Status:' + response.status + ' ' + response.statusText) + throw Error( + `HTTP Request Failed: ${message}, Status: ${response.status} ${response.statusCode}` + ) } } /** * - * @param {node-fetch.Response} response + * @param {Object} response the response body in json * @param {string} message * * @throws Error - * @returns {node-fetch.Response} + * @returns {Object} the body of the response */ -const checkOCSStatus = function(response, message) { +const checkOCSStatus = async function(response, message = '') { const statusCode = _.get(response, 'ocs.meta.statuscode') + const ocsMessage = _.get(response, 'ocs.meta.message') if (statusCode === 200) { return response } else { - throw Error(message + ' Status:' + statusCode) + throw Error(`OCS Request Failed: ${message}, Status: ${statusCode}, Message: ${ocsMessage}`) } } diff --git a/tests/acceptance/stepDefinitions/generalContext.js b/tests/acceptance/stepDefinitions/generalContext.js index e9d31e51d94..61e3e44d55e 100644 --- a/tests/acceptance/stepDefinitions/generalContext.js +++ b/tests/acceptance/stepDefinitions/generalContext.js @@ -21,6 +21,9 @@ Given( ) const getConfigJsonContent = function(fullPathOfConfigFile) { + if (!fs.existsSync(fullPathOfConfigFile)) { + throw Error('Could not find configfile') + } const rawdata = fs.readFileSync(fullPathOfConfigFile) return JSON.parse(rawdata) } @@ -265,12 +268,21 @@ After(async function(testCase) { }) Before(function() { - this.fullPathOfConfigFile = client.globals.phoenix_config - initialConfigJsonSettings = getConfigJsonContent(client.globals.phoenix_config) + try { + this.fullPathOfConfigFile = client.globals.phoenix_config + initialConfigJsonSettings = getConfigJsonContent(client.globals.phoenix_config) + } catch (err) { + console.log( + '\x1b[33m%s\x1b[0m', + `\tCould not read config file.\n\tSet correct path of config file in PHOENIX_CONFIG env variable to fix this.\n\tSome tests may fail as a result.` + ) + } }) After(function() { - fs.writeFileSync(this.fullPathOfConfigFile, JSON.stringify(initialConfigJsonSettings, null, 4)) + if (initialConfigJsonSettings) { + fs.writeFileSync(this.fullPathOfConfigFile, JSON.stringify(initialConfigJsonSettings, null, 4)) + } }) Given('the app {string} has been disabled', function(app) { diff --git a/tests/acceptance/stepDefinitions/provisioningContext.js b/tests/acceptance/stepDefinitions/provisioningContext.js index 4cfc2e34b12..7a4efbda9fb 100644 --- a/tests/acceptance/stepDefinitions/provisioningContext.js +++ b/tests/acceptance/stepDefinitions/provisioningContext.js @@ -37,6 +37,9 @@ function createUser(userId, password, displayName = false, email = false) { const url = 'cloud/users' return httpHelper .postOCS(url, 'admin', body) + .then(res => httpHelper.checkStatus(res, 'Failed while creating user')) + .then(res => res.json()) + .then(res => httpHelper.checkOCSStatus(res, 'Failed while creating user')) .then(() => { if (client.globals.ocis) { const skelDir = client.globals.ocis_skeleton_dir From af75295f2b872bc061cf372bae21d2c4241b4104 Mon Sep 17 00:00:00 2001 From: Dipak Acharya Date: Tue, 22 Sep 2020 20:12:56 +0545 Subject: [PATCH 2/2] Bump ocis commit id for UI tests in CI --- .drone.star | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.star b/.drone.star index ba586ff9ca0..0e701f5dd76 100644 --- a/.drone.star +++ b/.drone.star @@ -119,7 +119,7 @@ config = { 'defaults': { 'acceptance': { 'ocisBranch': 'master', - 'ocisCommit': '0c6478c9350f56ff6d7c402b5d9d60a68b0f6f75', + 'ocisCommit': '7b8e9bc2981c0fd9917bc576a291ab5231c02685', } },