7
7
CompanionStaticUpgradeScript ,
8
8
} from '../../module-api/upgrade.js'
9
9
import { runThroughUpgradeScripts } from '../upgrade.js'
10
- import { ActionInstance } from '../../host-api/api.js'
10
+ import { ActionInstance , UpgradeActionInstance } from '../../host-api/api.js'
11
11
12
12
type MockUpgradeScript < TConfig > = Mock < CompanionStaticUpgradeScript < TConfig > >
13
13
@@ -32,18 +32,18 @@ const createMockScripts = <TConfig>(count: number): MockUpgradeScript<TConfig>[]
32
32
return result
33
33
}
34
34
35
- function makeActionsInput ( ...actions : ActionInstance [ ] ) : { [ id : string ] : ActionInstance } {
36
- const res : { [ id : string ] : ActionInstance } = { }
35
+ function makeActionsInput ( ...actions : UpgradeActionInstance [ ] ) : UpgradeActionInstance [ ] {
36
+ const res : UpgradeActionInstance [ ] = [ ]
37
37
38
38
for ( const action of actions ) {
39
- if ( res [ action . id ] ) throw new Error ( `Duplicate id "${ action . id } "` )
40
- res [ action . id ] = clone ( action )
39
+ // if (res[action.id]) throw new Error(`Duplicate id "${action.id}"`)
40
+ res . push ( clone ( action ) )
41
41
}
42
42
43
43
return res
44
44
}
45
45
46
- function stripActionInstance ( action : ActionInstance ) : CompanionMigrationAction {
46
+ function stripActionInstance ( action : UpgradeActionInstance ) : CompanionMigrationAction {
47
47
return {
48
48
id : action . id ,
49
49
controlId : action . controlId ,
@@ -61,13 +61,13 @@ describe('runThroughUpgradeScripts', () => {
61
61
62
62
it ( 'nothing to upgrade' , ( ) => {
63
63
const scripts = createMockScripts ( 2 )
64
- const result = runThroughUpgradeScripts ( { } , { } , null , scripts , { } , true )
64
+ const result = runThroughUpgradeScripts ( [ ] , [ ] , null , scripts , { } , true )
65
65
66
66
// Check result looks sane
67
67
expect ( result ) . toBeTruthy ( )
68
68
expect ( result . updatedConfig ) . toBeUndefined ( )
69
- expect ( result . updatedActions ) . toEqual ( { } )
70
- expect ( result . updatedFeedbacks ) . toEqual ( { } )
69
+ expect ( result . updatedActions ) . toEqual ( [ ] )
70
+ expect ( result . updatedFeedbacks ) . toEqual ( [ ] )
71
71
72
72
// check scripts
73
73
expect ( scripts ) . toHaveLength ( 2 )
@@ -81,13 +81,13 @@ describe('runThroughUpgradeScripts', () => {
81
81
something : true ,
82
82
}
83
83
const scripts = createMockScripts ( 2 )
84
- const result = runThroughUpgradeScripts ( { } , { } , null , scripts , { ...configBefore } , false )
84
+ const result = runThroughUpgradeScripts ( [ ] , [ ] , null , scripts , { ...configBefore } , false )
85
85
86
86
// Check result looks sane
87
87
expect ( result ) . toBeTruthy ( )
88
88
expect ( result . updatedConfig ) . toEqual ( undefined )
89
- expect ( result . updatedActions ) . toEqual ( { } )
90
- expect ( result . updatedFeedbacks ) . toEqual ( { } )
89
+ expect ( result . updatedActions ) . toEqual ( [ ] )
90
+ expect ( result . updatedFeedbacks ) . toEqual ( [ ] )
91
91
92
92
// check scripts
93
93
expect ( scripts ) . toHaveLength ( 2 )
@@ -112,15 +112,15 @@ describe('runThroughUpgradeScripts', () => {
112
112
} )
113
113
} )
114
114
115
- const result = runThroughUpgradeScripts ( { } , { } , 0 , scripts , { ...configBefore } , false )
115
+ const result = runThroughUpgradeScripts ( [ ] , [ ] , 0 , scripts , { ...configBefore } , false )
116
116
// Check result looks sane
117
117
expect ( result ) . toBeTruthy ( )
118
118
expect ( result . updatedConfig ) . toEqual ( {
119
119
...configBefore ,
120
120
added : 123 ,
121
121
} )
122
- expect ( result . updatedActions ) . toEqual ( { } )
123
- expect ( result . updatedFeedbacks ) . toEqual ( { } )
122
+ expect ( result . updatedActions ) . toEqual ( [ ] )
123
+ expect ( result . updatedFeedbacks ) . toEqual ( [ ] )
124
124
125
125
// check scripts
126
126
expect ( scripts ) . toHaveLength ( 2 )
@@ -138,20 +138,26 @@ describe('runThroughUpgradeScripts', () => {
138
138
} )
139
139
140
140
it ( 'just the actions to upgrade, from v0' , ( ) => {
141
- const action0Before : ActionInstance = {
141
+ const action0Before : UpgradeActionInstance = {
142
142
id : 'act0' ,
143
143
upgradeIndex : null ,
144
144
disabled : false ,
145
145
actionId : 'my-action' ,
146
- options : { a : 1 , b : 2 } ,
146
+ options : {
147
+ a : { value : 1 , isExpression : false } ,
148
+ b : { value : 2 , isExpression : false } ,
149
+ } ,
147
150
controlId : 'control0' ,
148
151
}
149
- const action1Before : ActionInstance = {
152
+ const action1Before : UpgradeActionInstance = {
150
153
id : 'act1' ,
151
154
upgradeIndex : null ,
152
155
disabled : false ,
153
156
actionId : 'my-action' ,
154
- options : { c : 1 , d : 2 } ,
157
+ options : {
158
+ c : { value : 1 , isExpression : false } ,
159
+ d : { value : 2 , isExpression : false } ,
160
+ } ,
155
161
controlId : 'control1' ,
156
162
}
157
163
@@ -175,18 +181,18 @@ describe('runThroughUpgradeScripts', () => {
175
181
} )
176
182
177
183
const actionsInput = makeActionsInput ( action0Before , action1Before )
178
- const result = runThroughUpgradeScripts ( actionsInput , { } , 0 , scripts , { } , true )
184
+ const result = runThroughUpgradeScripts ( actionsInput , [ ] , 0 , scripts , { } , true )
179
185
180
186
// Check result looks sane
181
187
expect ( result ) . toBeTruthy ( )
182
188
expect ( result . updatedConfig ) . toBeUndefined ( )
183
- expect ( result . updatedActions ) . toEqual ( {
184
- [ action0Before . id ] : {
189
+ expect ( result . updatedActions ) . toEqual ( [
190
+ {
185
191
...action0Before ,
186
192
actionId : 'new-action' ,
187
193
} ,
188
- } )
189
- expect ( result . updatedFeedbacks ) . toEqual ( { } )
194
+ ] )
195
+ expect ( result . updatedFeedbacks ) . toEqual ( [ ] )
190
196
191
197
// check scripts
192
198
expect ( scripts ) . toHaveLength ( 2 )
@@ -195,25 +201,31 @@ describe('runThroughUpgradeScripts', () => {
195
201
196
202
// Check input was mutated in place
197
203
const expectedInput = makeActionsInput ( action0Before , action1Before )
198
- expectedInput [ action0Before . id ] . actionId = 'new-action'
204
+ expectedInput [ 0 ] . actionId = 'new-action'
199
205
expect ( actionsInput ) . toEqual ( expectedInput )
200
206
} )
201
207
202
208
it ( 'an actions to upgrade, from earlier than the rest' , ( ) => {
203
- const action0Before : ActionInstance = {
209
+ const action0Before : UpgradeActionInstance = {
204
210
id : 'act0' ,
205
211
upgradeIndex : null ,
206
212
disabled : false ,
207
213
actionId : 'my-action' ,
208
- options : { a : 1 , b : 2 } ,
214
+ options : {
215
+ a : { value : 1 , isExpression : false } ,
216
+ b : { value : 2 , isExpression : false } ,
217
+ } ,
209
218
controlId : 'control0' ,
210
219
}
211
- const action1Before : ActionInstance = {
220
+ const action1Before : UpgradeActionInstance = {
212
221
id : 'act1' ,
213
222
upgradeIndex : - 1 ,
214
223
disabled : false ,
215
224
actionId : 'my-action' ,
216
- options : { c : 1 , d : 2 } ,
225
+ options : {
226
+ c : { value : 1 , isExpression : false } ,
227
+ d : { value : 2 , isExpression : false } ,
228
+ } ,
217
229
controlId : 'control1' ,
218
230
}
219
231
@@ -236,22 +248,22 @@ describe('runThroughUpgradeScripts', () => {
236
248
} )
237
249
238
250
const actionsInput = makeActionsInput ( action0Before , action1Before )
239
- const result = runThroughUpgradeScripts ( actionsInput , { } , 0 , scripts , { } , true )
251
+ const result = runThroughUpgradeScripts ( actionsInput , [ ] , 0 , scripts , { } , true )
240
252
241
253
// Check result looks sane
242
254
expect ( result ) . toBeTruthy ( )
243
255
expect ( result . updatedConfig ) . toBeUndefined ( )
244
- expect ( result . updatedActions ) . toEqual ( {
245
- [ action0Before . id ] : {
256
+ expect ( result . updatedActions ) . toEqual ( [
257
+ {
246
258
...action0Before ,
247
259
actionId : 'new-action' ,
248
260
} ,
249
- [ action1Before . id ] : {
261
+ {
250
262
// Reported to confirm the upgrade
251
263
...action1Before ,
252
264
} ,
253
- } )
254
- expect ( result . updatedFeedbacks ) . toEqual ( { } )
265
+ ] )
266
+ expect ( result . updatedFeedbacks ) . toEqual ( [ ] )
255
267
256
268
// check scripts
257
269
expect ( scripts ) . toHaveLength ( 2 )
@@ -261,7 +273,7 @@ describe('runThroughUpgradeScripts', () => {
261
273
262
274
// Check input was mutated in place
263
275
const expectedInput = makeActionsInput ( action0Before , action1Before )
264
- expectedInput [ action0Before . id ] . actionId = 'new-action'
276
+ expectedInput [ 0 ] . actionId = 'new-action'
265
277
expect ( actionsInput ) . toEqual ( expectedInput )
266
278
} )
267
279
} )
0 commit comments