{
  "id": "765d2e7525414a11",
  "name": "n8n-check: fixed amounts: ascending, complete order rows",
  "active": false,
  "nodes": [
    {
      "id": "50c36f91-e009-4878-bff1-a020f42d798c",
      "name": "n8n-check start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -400,
        0
      ],
      "parameters": {}
    },
    {
      "id": "orders",
      "name": "Orders",
      "position": [
        0,
        0
      ],
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "return JSON.parse(\"[{\\\"id\\\":\\\"order-A\\\",\\\"orderTotal\\\":\\\"96.74\\\",\\\"customer\\\":\\\"Example Alpha\\\"},{\\\"id\\\":\\\"order-B\\\",\\\"orderTotal\\\":\\\"83.28\\\",\\\"customer\\\":\\\"Example Beta\\\"},{\\\"id\\\":\\\"order-C\\\",\\\"orderTotal\\\":\\\"452.8\\\",\\\"customer\\\":\\\"Example Gamma\\\"}]\").map(json => ({json}));"
      }
    },
    {
      "id": "numeric-key",
      "name": "Add numeric sort key",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        0
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "amount-key",
              "name": "_amountSortKey",
              "value": "={{ Number($json.orderTotal) }}",
              "type": "number"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      }
    },
    {
      "id": "sort-ascending",
      "name": "Sort orders",
      "type": "n8n-nodes-base.sort",
      "typeVersion": 1,
      "position": [
        480,
        0
      ],
      "parameters": {
        "type": "simple",
        "sortFieldsUi": {
          "sortField": [
            {
              "fieldName": "_amountSortKey",
              "order": "ascending"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "original-orders",
      "name": "Return original orders",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        720,
        0
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "return $input.all().map(item => {\n  const { _amountSortKey, ...json } = item.json;\n  return { ...item, json };\n});"
      }
    },
    {
      "id": "82d63902-bacc-4ce8-9634-03337673926b",
      "name": "Check expected output",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -400,
        240
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "// Generated by n8n-check. Fixed fixture, one run per node; leave this branch last.\nfunction equalJson(a, b) {\n  if (Object.is(a, b)) return true;\n  if (!a || !b || typeof a !== 'object' || typeof b !== 'object') return false;\n  if (Array.isArray(a) !== Array.isArray(b)) return false;\n  const keys = Object.keys(a);\n  return keys.length === Object.keys(b).length &&\n    keys.every(key => Object.hasOwn(b, key) && equalJson(a[key], b[key]));\n}\nfunction checkItems(items, assertion) {\n  const label = `${assertion.node}: output ${assertion.output ?? 0}`;\n  if (assertion.count !== undefined && items.length !== assertion.count)\n    throw new Error(`n8n-check: ${label} expected ${assertion.count} items, got ${items.length}`);\n  if (assertion.equals !== undefined) {\n    const values = items.map((item, index) => {\n      if (!assertion.pluck) return item.json;\n      let value = item;\n      for (const key of assertion.pluck.split('.')) {\n        if (value === null || typeof value !== 'object' || !Object.hasOwn(value, key))\n          throw new Error(`n8n-check: ${label} item ${index} is missing ${assertion.pluck}`);\n        value = value[key];\n      }\n      return value;\n    });\n    if (!equalJson(values, assertion.equals))\n      throw new Error(`n8n-check: ${label}${assertion.pluck ? ` ${assertion.pluck}` : ''} differs. Expected ${JSON.stringify(assertion.equals)}; got ${JSON.stringify(values)}`);\n  }\n  return { node: assertion.node, output: assertion.output ?? 0, count: items.length, passed: true };\n}\nconst assertions = JSON.parse(\"[{\\\"node\\\":\\\"Return original orders\\\",\\\"count\\\":3,\\\"equals\\\":[{\\\"id\\\":\\\"order-B\\\",\\\"orderTotal\\\":\\\"83.28\\\",\\\"customer\\\":\\\"Example Beta\\\"},{\\\"id\\\":\\\"order-A\\\",\\\"orderTotal\\\":\\\"96.74\\\",\\\"customer\\\":\\\"Example Alpha\\\"},{\\\"id\\\":\\\"order-C\\\",\\\"orderTotal\\\":\\\"452.8\\\",\\\"customer\\\":\\\"Example Gamma\\\"}]}]\");\nconst checks = assertions.map(assertion => {\n  const node = $(assertion.node);\n  const items = node.isExecuted ? node.all(assertion.output ?? 0, 0) : [];\n  return checkItems(items, assertion);\n});\nreturn [{ json: { status: 'passed', checks } }];"
      }
    }
  ],
  "connections": {
    "Orders": {
      "main": [
        [
          {
            "node": "Add numeric sort key",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add numeric sort key": {
      "main": [
        [
          {
            "node": "Sort orders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sort orders": {
      "main": [
        [
          {
            "node": "Return original orders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "n8n-check start": {
      "main": [
        [
          {
            "node": "Orders",
            "type": "main",
            "index": 0
          },
          {
            "node": "Check expected output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "executionTimeout": 60,
    "saveExecutionProgress": true
  }
}
