diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-09-28 19:53:18 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-09-28 19:53:18 -0300 |
commit | b606bb424026597560144750d8dcf7b3e2601755 (patch) | |
tree | ef80049bfd09375bec48e48b60ac63f415e01470 /test/unit/data/composite/common-utilities | |
parent | ac37f9db30d997d64de069a7b3b53c3474bdc413 (diff) |
test: withPropertyFromObject (WIP)
Diffstat (limited to 'test/unit/data/composite/common-utilities')
-rw-r--r-- | test/unit/data/composite/common-utilities/withPropertyFromObject.js | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/test/unit/data/composite/common-utilities/withPropertyFromObject.js b/test/unit/data/composite/common-utilities/withPropertyFromObject.js new file mode 100644 index 00000000..c0e3dccf --- /dev/null +++ b/test/unit/data/composite/common-utilities/withPropertyFromObject.js @@ -0,0 +1,124 @@ +import t from 'tap'; + +import { + compositeFrom, + exposeDependency, + input, + withPropertyFromObject, +} from '#composite'; + +t.test(`withPropertyFromObject: basic behavior`, t => { + t.plan(4); + + const composite = compositeFrom({ + compose: false, + + steps: [ + withPropertyFromObject({ + object: 'object', + property: 'property', + }), + + exposeDependency({dependency: '#value'}), + ], + }); + + t.match(composite, { + expose: { + dependencies: ['object', 'property'], + }, + }); + + t.equal(composite.expose.compute({ + object: {foo: 'bar', bim: 'BOOM'}, + property: 'bim', + }), 'BOOM'); + + t.equal(composite.expose.compute({ + object: {value1: 'uwah'}, + property: 'value2', + }), null); + + t.equal(composite.expose.compute({ + object: null, + property: 'oml where did me object go', + }), null); +}); + +t.test(`withPropertyFromObject: output shapes & values`, t => { + t.plan(3 * 3 * 2); + + const dependencies = { + ['object_dependency']: + {foo: 'apple', bar: 'banana', baz: 'orange'}, + [input('object_neither')]: + {foo: 'koala', bar: 'okapi', baz: 'mongoose'}, + ['property_dependency']: + 'foo', + [input('property_neither')]: + 'baz', + }; + + const map = [ + ['object_dependency', [ + ['property_dependency', { + '#value': 'apple', + }], + [input.value('bar'), { + '#object_dependency.bar': 'banana', + }], + [input('property_neither'), { + '#value': 'orange', + }]]], + + [input.value({foo: 'ouh', bar: 'rah', baz: 'nyu'}), [ + ['property_dependency', { + '#value': 'ouh', + }], + [input.value('bar'), { + '#value': 'rah', + }], + [input('property_neither'), { + '#value': 'nyu', + }]]], + + [input('object_neither'), [ + ['property_dependency', { + '#value': 'koala', + }], + [input.value('bar'), { + '#value': 'okapi', + }], + [input('property_neither'), { + '#value': 'mongoose', + }]]], + ]; + + for (const [objectInput, submap] of map) { + for (const [propertyInput, dict] of submap) { + const step = withPropertyFromObject({ + object: objectInput, + property: propertyInput, + }); + + t.same( + Object.keys(step.toDescription().outputs), + Object.keys(dict)); + + const composite = compositeFrom({ + compose: false, + + steps: [ + step, + + { + dependencies: Object.keys(dict), + compute: dependencies => dependencies, + }, + ], + }); + + t.same(composite.expose.compute(dependencies), dict); + } + } +}); |