utils-get-field-value.json 1.3 KB

12345678910111213141516171819202122232425
  1. {
  2. "name": "verify-utils-get-field-value",
  3. "nodes": [
  4. {"id": "n1", "name": "Trigger", "type": "click-trigger", "position": {"x": 0, "y": 0}, "config": {}},
  5. {"id": "n2", "name": "Probe", "type": "code", "position": {"x": 0, "y": 100},
  6. "config": {"code": "const d = { a: { b: { c: 7 } }, list: [{ id: 'x' }, { id: 'y' }], flat: [10, 20, 30] };\nconst g = smartbotic.utils.getFieldValue;\nreturn {\n nested: g(d, 'a.b.c'),\n bracket: g(d, 'list[1].id'),\n numeric: g(d, 'flat.2'),\n length: g(d, 'flat.length'),\n missing: g(d, 'a.nope.c') === undefined,\n throughNull: g({ a: null }, 'a.b') === undefined,\n emptyPath: g(d, '').a.b.c,\n notAnObject: g(d, 'a.b.c.d') === undefined,\n hugeBracket: g(d, 'flat[99999999999999999999]') === undefined,\n hugeNumeric: g(d, 'flat.99999999999999999999') === undefined\n};"}}
  7. ],
  8. "connections": [
  9. {"sourceNodeId": "n1", "sourceOutput": "main", "targetNodeId": "n2", "targetInput": "data"}
  10. ],
  11. "expect": {
  12. "n2": {"status": "completed", "output": {"result": {
  13. "nested": 7,
  14. "bracket": "y",
  15. "numeric": 30,
  16. "length": 3,
  17. "missing": true,
  18. "throughNull": true,
  19. "emptyPath": 7,
  20. "notAnObject": true,
  21. "hugeBracket": true,
  22. "hugeNumeric": true
  23. }}}
  24. }
  25. }