« get me outta code hell

test: withPropertiesFromObject: dynamic input validation - 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-30 19:23:38 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-30 19:23:38 -0300
commitb09540f108de841a067f8f6a8e62c82335221ee9 (patch)
tree439c5fcd694fa16900c79e3aee7413a65603a24f /test/unit
parent902ebbafb7cfb56f7a878d33cf94e5708861ff4a (diff)
test: withPropertiesFromObject: dynamic input validation
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/data/composite/common-utilities/withPropertiesFromObject.js57
1 files changed, 45 insertions, 12 deletions
diff --git a/test/unit/data/composite/common-utilities/withPropertiesFromObject.js b/test/unit/data/composite/common-utilities/withPropertiesFromObject.js
index 835767cb..3431382e 100644
--- a/test/unit/data/composite/common-utilities/withPropertiesFromObject.js
+++ b/test/unit/data/composite/common-utilities/withPropertiesFromObject.js
@@ -7,21 +7,21 @@ import {
   withPropertiesFromObject,
 } from '#composite';
 
-t.test(`withPropertiesFromObject: basic behavior`, t => {
-  t.plan(4);
+const composite = compositeFrom({
+  compose: false,
 
-  const composite = compositeFrom({
-    compose: false,
+  steps: [
+    withPropertiesFromObject({
+      object: 'object',
+      properties: 'properties',
+    }),
 
-    steps: [
-      withPropertiesFromObject({
-        object: 'object',
-        properties: 'properties',
-      }),
+    exposeDependency({dependency: '#object'}),
+  ],
+});
 
-      exposeDependency({dependency: '#object'}),
-    ],
-  });
+t.test(`withPropertiesFromObject: basic behavior`, t => {
+  t.plan(4);
 
   t.match(composite, {
     expose: {
@@ -216,3 +216,36 @@ t.test(`withPropertiesFromObject: validate static inputs`, t => {
       ]},
     ]});
 });
+
+t.test(`withPropertiesFromObject: validate dynamic inputs`, t => {
+  t.plan(2);
+
+  t.throws(
+    () => composite.expose.compute({
+      object: 'intriguing',
+      properties: 'onceMore',
+    }),
+    {message: `Error computing composition`, cause:
+      {message: `Error computing composition withPropertiesFromObject`, cause:
+        {message: `Errors in input values provided to withPropertiesFromObject`, errors: [
+          {message: `object: Expected an object, got string`},
+          {message: `properties: Expected an array, got string`},
+        ]}}});
+
+  t.throws(
+    () => composite.expose.compute({
+      object: [['abc', 1], ['def', 2], [123, 3]],
+      properties: ['abc', 'def', 123],
+    }),
+    {message: `Error computing composition`, cause:
+      {message: `Error computing composition withPropertiesFromObject`, cause:
+        {message: `Errors in input values provided to withPropertiesFromObject`, errors: [
+          {message: `object: Expected an object, got array`},
+          {message: `properties: Errors validating array items`, errors: [
+            {
+              [Symbol.for('hsmusic.decorate.indexInSourceArray')]: 2,
+              message: /Expected a string, got number/,
+            },
+          ]},
+        ]}}});
+});