From d40f0105e87c638b662a745aad9845549ca02e18 Mon Sep 17 00:00:00 2001 From: sandeep-vedam Date: Tue, 2 Jun 2020 00:15:03 +0530 Subject: [PATCH] Added test cases related to Firmware Upgrade plugin --- src/commonMethods/constants.js | 1 + src/commonMethods/firmwarecontrol.js | 30 +++++++ .../Firmware_Upgrade_Upgrade_001.test.js | 80 +++++++++++++++++++ .../Firmware_Upgrade_Upgrade_002.test.js | 34 ++++++++ .../Firmware_Upgrade_Upgrade_003.test.js | 42 ++++++++++ 5 files changed, 187 insertions(+) create mode 100644 src/commonMethods/firmwarecontrol.js create mode 100644 src/tests/firmwarecontrol/Firmware_Upgrade_Upgrade_001.test.js create mode 100644 src/tests/firmwarecontrol/Firmware_Upgrade_Upgrade_002.test.js create mode 100644 src/tests/firmwarecontrol/Firmware_Upgrade_Upgrade_003.test.js diff --git a/src/commonMethods/constants.js b/src/commonMethods/constants.js index 44f410f..289d60e 100755 --- a/src/commonMethods/constants.js +++ b/src/commonMethods/constants.js @@ -24,6 +24,7 @@ export default { provisioningPlugin: 'Provisioning', dhcpserver: 'DHCPServer', traceControlPlugin: 'TraceControl', + firmwareUpgradePlugin: 'FirmwareControl', WPEProcess: 'WPEProcess', remoteControlPlugin: 'RemoteControl', invalidAddress: 'invalidstring', diff --git a/src/commonMethods/firmwarecontrol.js b/src/commonMethods/firmwarecontrol.js new file mode 100644 index 0000000..b57008c --- /dev/null +++ b/src/commonMethods/firmwarecontrol.js @@ -0,0 +1,30 @@ +/** + * This function is used to upgrade the firmware + * @param name + * @param location + * @param type + * @param progressinterval + * @param hmac + * @returns {Promise} + */ +export const firmwareUpgrade = function(name, location, type, progressinterval, hmac) { + return this.$thunder.api.FirmwareControl.upgrade({ + name: name, + location: location, + type: type, + progressinterval: progressinterval, + hmac: hmac, + }) + .then(result => result) + .catch(err => err) +} + +/** + * This function is used to get the status of firmware upgrade + * @returns {Promise} + */ +export const upgradeStatus = function() { + return this.$thunder.api.FirmwareControl.status() + .then(result => result) + .catch(err => err) +} diff --git a/src/tests/firmwarecontrol/Firmware_Upgrade_Upgrade_001.test.js b/src/tests/firmwarecontrol/Firmware_Upgrade_Upgrade_001.test.js new file mode 100644 index 0000000..8de23ce --- /dev/null +++ b/src/tests/firmwarecontrol/Firmware_Upgrade_Upgrade_001.test.js @@ -0,0 +1,80 @@ +import { firmwareUpgrade, upgradeStatus } from '../../commonMethods/firmwarecontrol' +import { pluginActivate, pluginDeactivate } from '../../commonMethods/controller' +import constants from '../../commonMethods/constants' + +let listener + +export default { + title: 'Firmware Upgrade - 001', + description: 'Check the Upgrade of the device to the specified firmware', + context: { + state: 'completed', + }, + setup() { + return this.$sequence([ + () => pluginDeactivate.call(this, constants.firmwareUpgradePlugin), + () => pluginActivate.call(this, constants.firmwareUpgradePlugin), + () => { + listener = this.$thunder.api.FirmwareControl.on( + 'upgradeprogress', + data => { + this.$data.write('upgradeStatus', data.status) + }, + e => { + this.$log('Error subscribing to upgradeprogress: ', e) + } + ) + return true + }, + ]) + }, + steps: [ + { + description: 'Upgrade the firmware and check whether it is completed', + sleep: 5, + test() { + //TODO - Update the test to enter the 'name', 'location', 'type', 'progressinterval', 'hmac' through User prompt + return firmwareUpgrade.call(this, 'name', 'location', 'type', 'progressinterval', 'hmac') + }, + validate(res) { + if (res == null) { + return true + } else { + throw new Error(`FirmwareUpgrade is not invoked properly and the result is ${res}`) + } + }, + }, + { + description: 'Sleep until Completed event is detected', + sleep() { + // Purpose of this sleep is to wait until current step gets 'upgradeprogress' response from the listener + return new Promise((resolve, reject) => { + let attempts = 0 + const interval = setInterval(() => { + attempts++ + if (this.$data.read('upgradeStatus') === this.$context.read('state')) { + clearInterval(interval) + setTimeout(resolve, 5000) //give it some time to load + } else if (attempts > 100) { + clearInterval(interval) + reject('Upgrade Not completed') + } + }, 1000) + }) + }, + }, + { + description: 'Get Upgrade Status and validate the result', + test() { + return upgradeStatus.call(this) + }, + validate(res) { + if (res == 'completed') { + return true + } else { + throw new Error('Firmware upgrade not completed successfully') + } + }, + }, + ], +} diff --git a/src/tests/firmwarecontrol/Firmware_Upgrade_Upgrade_002.test.js b/src/tests/firmwarecontrol/Firmware_Upgrade_Upgrade_002.test.js new file mode 100644 index 0000000..e049c10 --- /dev/null +++ b/src/tests/firmwarecontrol/Firmware_Upgrade_Upgrade_002.test.js @@ -0,0 +1,34 @@ +import { firmwareUpgrade } from '../../commonMethods/firmwarecontrol' +import { pluginActivate, pluginDeactivate } from '../../commonMethods/controller' +import constants from '../../commonMethods/constants' + +export default { + title: 'Firmware Upgrade - 002', + description: 'Check the upgrade Functionality when upgrade is already in progress', + setup() { + return this.$sequence([ + () => pluginDeactivate.call(this, constants.firmwareUpgradePlugin), + () => pluginActivate.call(this, constants.firmwareUpgradePlugin), + ]) + }, + steps: [ + { + description: + 'Invoke Upgrade firmware when already firmware upgrade in progres and validate the result', + sleep: 5, + test() { + //TODO - Update the test to enter the 'name', 'location', 'type', 'progressinterval', 'hmac' through User prompt + firmwareUpgrade.call(this, 'name', 'location', 'type', 'progressinterval', 'hmac') + return firmwareUpgrade.call(this, 'name', 'location', 'type', 'progressinterval', 'hmac') + }, + validate(res) { + if (res.code === 12 && res.message === 'ERROR_INPROGRESS') { + return true + } else { + this.$log('Proper error message is not shown') + return false + } + }, + }, + ], +} diff --git a/src/tests/firmwarecontrol/Firmware_Upgrade_Upgrade_003.test.js b/src/tests/firmwarecontrol/Firmware_Upgrade_Upgrade_003.test.js new file mode 100644 index 0000000..adbefe6 --- /dev/null +++ b/src/tests/firmwarecontrol/Firmware_Upgrade_Upgrade_003.test.js @@ -0,0 +1,42 @@ +import { firmwareUpgrade } from '../../commonMethods/firmwarecontrol' +import { pluginActivate, pluginDeactivate } from '../../commonMethods/controller' +import constants from '../../commonMethods/constants' + +export default { + title: 'Firmware Upgrade - 002', + description: 'Check the upgrade Functionality when upgrade is already in progress', + context: { + invalidURL: 'incorrectURL', + }, + setup() { + return this.$sequence([ + () => pluginDeactivate.call(this, constants.firmwareUpgradePlugin), + () => pluginActivate.call(this, constants.firmwareUpgradePlugin), + ]) + }, + steps: [ + { + description: + 'Invoke Upgrade firmware when already firmware upgrade in progres and validate the result', + sleep: 5, + test() { + return firmwareUpgrade.call( + this, + 'firmware_v.0', + this.$context.read('invalidURL'), + 'CDL', + '10', + 'hmac' + ) + }, + validate(res) { + if (res.code === 15 && res.message === 'ERROR_INCORRECT_URL') { + return true + } else { + this.$log('Proper error message is not shown') + return false + } + }, + }, + ], +}