Skip to content

Commit

Permalink
fix(trigger-state): Fix migrations for version 3
Browse files Browse the repository at this point in the history
test(trigger-state): Add test for migrations
  • Loading branch information
zachowj committed Sep 24, 2023
1 parent 7e5b72f commit 4cbbb46
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
13 changes: 6 additions & 7 deletions src/nodes/trigger-state/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ export default [
const newSchema = {
...schema,
version: 3,
entityId: schema.entityConfigNode,
entityIdType: schema.entityidfiltertypeentityConfigNode,
debugEnabled: schema.debugenabledentityConfigNode,
customOutputs: schema.customoutputsentityConfigNode,
outputInitially: schema.outputinitiallyentityConfigNode,
StateType: schema.state_typeentityConfigNode,
entityId: schema.entityid,
entityIdType: schema.entityidfiltertype,
debugEnabled: schema.debugenabled,
customOutputs: schema.customoutputs,
outputInitially: schema.outputinitially,
StateType: schema.state_type,
exposeAsEntityConfig: '',
};

Expand All @@ -71,7 +71,6 @@ export default [
newSchema.customoutputs = undefined;
newSchema.outputinitially = undefined;
newSchema.state_type = undefined;
newSchema.enableInput = undefined;

return newSchema;
},
Expand Down
27 changes: 26 additions & 1 deletion test/migrations/trigger-state.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ const VERSION_2 = {
...VERSION_1,
version: 2,
};
const VERSION_3 = {
...VERSION_2,
version: 3,
entityId: 'entity.id',
entityIdType: 'exact',
debugEnabled: false,
customOutputs: [],
outputInitially: false,
StateType: 'str',
exposeAsEntityConfig: '',

entityid: undefined,
entityidfiltertype: undefined,
debugenabled: undefined,
customoutputs: undefined,
outputinitially: undefined,
state_type: undefined,
};

describe('Migrations - Trigger State Node', function () {
describe('Version 0', function () {
Expand Down Expand Up @@ -90,8 +108,15 @@ describe('Migrations - Trigger State Node', function () {
expect(migratedSchema.entityid).to.have.lengthOf(1);
});
});
describe('Version 3', function () {
it('should update version 2 to version 3', function () {
const migrate = migrations.find((m) => m.version === 3);
const migratedSchema = migrate.up(VERSION_2);
expect(migratedSchema).to.eql(VERSION_3);
});
});
it('should update an undefined version to current version', function () {
const migratedSchema = migrate(VERSION_UNDEFINED);
expect(migratedSchema).to.eql(VERSION_2);
expect(migratedSchema).to.eql(VERSION_3);
});
});

0 comments on commit 4cbbb46

Please sign in to comment.