diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-09-25 14:23:23 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-09-25 14:23:23 -0300 |
commit | b5cfc2a793f22da60606a4dd7387fcf3d3163843 (patch) | |
tree | a759bcd319403262bd6ede26eaf3bd2f30359c86 /test/unit/data/composite/compositeFrom.js | |
parent | 219596b6d52443d1090c94e50244cf79d548a167 (diff) |
data: misc. improvements for input validation & infrastructure
Diffstat (limited to 'test/unit/data/composite/compositeFrom.js')
-rw-r--r-- | test/unit/data/composite/compositeFrom.js | 78 |
1 files changed, 72 insertions, 6 deletions
diff --git a/test/unit/data/composite/compositeFrom.js b/test/unit/data/composite/compositeFrom.js index 06a66e61..00296675 100644 --- a/test/unit/data/composite/compositeFrom.js +++ b/test/unit/data/composite/compositeFrom.js @@ -98,12 +98,20 @@ t.test(`compositeFrom: dependencies from inputs`, t => { compose: true, - inputs: { - foo: input('bar'), - pomelo: input.value('delicious'), + inputMapping: { + foo: input('bar'), + pomelo: input.value('delicious'), humorous: input.dependency('#mammal'), - data: input.dependency('albumData'), - ref: input.updateValue(), + data: input.dependency('albumData'), + ref: input.updateValue(), + }, + + inputDescriptions: { + foo: input(), + pomelo: input(), + humorous: input(), + data: input(), + ref: input(), }, steps: [ @@ -233,13 +241,17 @@ t.test(`compositeFrom: update from various sources`, t => { t.plan(3); const composite = compositeFrom({ - inputs: { + inputMapping: { myInput: input.updateValue({ validate: isString, default: 'foo', }), }, + inputDescriptions: { + myInput: input(), + }, + steps: [ { dependencies: [input('myInput')], @@ -277,3 +289,57 @@ t.test(`compositeFrom: update from various sources`, t => { t.equal(continuationValue, 'Xx_foofoo_xX'); }); }); + +t.test(`compositeFrom: dynamic input validation from type`, t => { + t.plan(2); + + const composite = compositeFrom({ + inputMapping: { + string: input('string'), + number: input('number'), + boolean: input('boolean'), + function: input('function'), + object: input('object'), + array: input('array'), + }, + + inputDescriptions: { + string: input({null: true, type: 'string'}), + number: input({null: true, type: 'number'}), + boolean: input({null: true, type: 'boolean'}), + function: input({null: true, type: 'function'}), + object: input({null: true, type: 'object'}), + array: input({null: true, type: 'array'}), + }, + + outputs: {'#result': '#result'}, + + steps: [ + {compute: continuation => continuation({'#result': 'OK'})}, + ], + }); + + const notCalledSymbol = Symbol('continuation not called'); + + let continuationValue; + const continuation = value => { + continuationValue = value; + return continuationSymbol; + }; + + let thrownError; + + try { + continuationValue = notCalledSymbol; + thrownError = null; + composite.expose.compute(continuation, { + [input('string')]: 123, + }); + } catch (error) { + thrownError = error; + } + + t.equal(continuationValue, notCalledSymbol); + t.match(thrownError, { + }); +}); |