« get me outta code hell

data: misc. improvements for input validation & infrastructure - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/test/unit
diff options
context:
space:
mode:
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
commitb5cfc2a793f22da60606a4dd7387fcf3d3163843 (patch)
treea759bcd319403262bd6ede26eaf3bd2f30359c86 /test/unit
parent219596b6d52443d1090c94e50244cf79d548a167 (diff)
data: misc. improvements for input validation & infrastructure
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/data/composite/compositeFrom.js78
-rw-r--r--test/unit/data/composite/withResultOfAvailabilityCheck.js2
-rw-r--r--test/unit/data/things/track.js1
3 files changed, 74 insertions, 7 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, {
+  });
+});
diff --git a/test/unit/data/composite/withResultOfAvailabilityCheck.js b/test/unit/data/composite/withResultOfAvailabilityCheck.js
index f5229fb3..cac98d3c 100644
--- a/test/unit/data/composite/withResultOfAvailabilityCheck.js
+++ b/test/unit/data/composite/withResultOfAvailabilityCheck.js
@@ -103,7 +103,7 @@ t.test(`withResultOfAvailabilityCheck: default mode`, t => {
   });
 
   t.match(template.toDescription(), {
-    inputs: {
+    inputMapping: {
       from: input.dependency('foo'),
       mode: input.value('null'),
     },
diff --git a/test/unit/data/things/track.js b/test/unit/data/things/track.js
index 5e7fd829..f68510c6 100644
--- a/test/unit/data/things/track.js
+++ b/test/unit/data/things/track.js
@@ -1,5 +1,6 @@
 import t from 'tap';
 
+import {showAggregate} from '#sugar';
 import {linkAndBindWikiData} from '#test-lib';
 import thingConstructors from '#things';