Skip to content

Commit

Permalink
Add test for default and unknown/unsupported command
Browse files Browse the repository at this point in the history
  • Loading branch information
waldbaer committed Jan 27, 2023
1 parent 252e622 commit af2684f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions nodes/persistent-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ module.exports = function(RED) {

currentValue = inputValue;
}
// -- Command: unknown / unsupported --
else {
node.error(`Unknown or unsupported persistent value command '${node.command}' used!`);
return null;
}

// -- BlockIf --
const blockFlow = checkBlockIfCondition(node, currentValue);
Expand Down
19 changes: 19 additions & 0 deletions test/persistent_values_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ describe('persistent value node', function() {
it('should read the default value - string', function(done) {
const flow = structuredClone(FlowNodeAllVariants);
flow[0].value = ConfigValueString;
flow[0].command = undefined; // Extra test variant: Force usage of default command (read)

helper.load([configNode, valueNode], flow, function() {
const c = helper.getNode(NodeIdConfig);
Expand Down Expand Up @@ -970,4 +971,22 @@ describe('persistent value node', function() {
v.receive({payload: AnyInputString});
});
});

// ==== Other / Error Handling Tests ========================================

it('should reject unknown / unsupported commands', function(done) {
const flow = structuredClone(FlowNodeAllVariants);
const unsupportedCommand = 'unsupported command';
flow[0].command = unsupportedCommand;

helper.load([configNode, valueNode], flow, function() {
const v = helper.getNode(NodeIdPersistentValue);

v.receive({payload: AnyInputString});

v.error.should.be.calledWithMatch(`Unknown or unsupported persistent value command '${unsupportedCommand}' used!`);
v.send.should.have.callCount(0);
done();
});
});
});

0 comments on commit af2684f

Please sign in to comment.