-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFirmware_Upgrade_Upgrade_001.test.js
More file actions
80 lines (78 loc) · 2.49 KB
/
Firmware_Upgrade_Upgrade_001.test.js
File metadata and controls
80 lines (78 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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')
}
},
},
],
}