Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scene: Device get value should deep clone device feature to avoid pollution on subsequent calls #1806

Merged
merged 1 commit into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/lib/scene/scene.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const actionsFunc = {
scope,
`${columnIndex}`,
{
[rowIndex]: deviceFeature,
[rowIndex]: cloneDeep(deviceFeature),
},
{ merge: true },
);
Expand Down
47 changes: 46 additions & 1 deletion server/test/lib/scene/actions/scene.action.getValue.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { fake } = require('sinon');
const { fake, stub } = require('sinon');
const { expect } = require('chai');
const EventEmitter = require('events');

Expand Down Expand Up @@ -107,4 +107,49 @@ describe('device.getValue', () => {
},
});
});
it('should execute multiple get value and get a merged scope with different value', async () => {
const stateManagerStub = stub();
const stateManager = {
get: stateManagerStub,
};
const objectToReturn = { last_value: 10 };
stateManagerStub.onCall(0).returns(objectToReturn);
stateManagerStub.onCall(1).returns({ last_value: 15 });
const device = {
setValue: fake.resolves(null),
};
const scope = {};
await executeActions(
{ stateManager, event, device },
[
[
{
type: ACTIONS.DEVICE.GET_VALUE,
device_feature: 'my-device-feature',
},
],
[
{
type: ACTIONS.DEVICE.GET_VALUE,
device_feature: 'my-device-feature',
},
],
],
scope,
);
// should not affect result
objectToReturn.last_value = 10000;
expect(scope).to.deep.equal({
0: {
0: {
last_value: 10,
},
},
1: {
0: {
last_value: 15,
},
},
});
});
});