All case studies
Case studyOriginal ConceptDemo Ready

Inbound Lead Qualification: n8n Workflow

A 15-node n8n workflow that validates, scores, deduplicates and routes inbound leads. The JavaScript inside its Code nodes is extracted and executed by a 22-test suite, so the logic is verified rather than merely drawn.

This is a working demonstration, not a client engagement. The brand and data are fictional.

Diagram of the 15-node inbound lead qualification workflow

Background

Automation work is usually shown as a screenshot of a canvas, which proves only that nodes were placed. This project exists to show the logic inside the nodes, tested.

The challenge

n8n Code nodes are JavaScript strings inside a JSON document. They are easy to get wrong and, in the usual workflow, untestable short of running the whole automation against live services.

Objectives

  • Show the logic inside an automation, not a screenshot of a canvas with nodes on it.
  • Make the Code nodes testable without running the whole workflow against live services.
  • Keep credentials out of the exported workflow entirely.

My role

Sole author

  • Designed and wrote the 15-node workflow as importable n8n JSON
  • Wrote the validation, scoring, deduplication and routing logic in the Code nodes
  • Built a test harness that reads the workflow file, extracts each Code node's JavaScript and executes it with stubbed n8n globals, so the tests run the real code rather than a copy
  • Wrote 22 tests covering a hot lead, a cold lead, an invalid submission and the deduplication window
  • Drew the workflow diagram as SVG and documented the required credentials by name only

Technical approach

The test suite parses the workflow JSON, pulls each Code node's source and runs it in a function with `$input` and `$getWorkflowStaticData` stubbed. The code under test is literally the code that would run in n8n, so if the workflow file changes, the tests see the change.

What is implemented

  • 15-node workflow: webhook, validation, normalisation, scoring, deduplication, branch, enrichment, notification and response
  • Lead scoring with configurable thresholds and a hot/cold branch
  • Deduplication against workflow static data within a time window
  • Three example payloads (hot, cold and invalid) with asserted end-to-end outcomes

Process

  1. Modelled the pipeline: webhook, validation, normalisation, scoring, deduplication against workflow static data, branch, enrichment, notification, and a response.
  2. Wrote the Code nodes, then the harness that executes them.
  3. Built three example payloads (hot, cold and invalid) and asserted the end-to-end outcome for each.
  4. Documented required credentials by name, with no values anywhere in the repository.

Engineering and creative decisions

  • The tests execute the workflow's own JavaScript

    The suite reads the workflow JSON, extracts each Code node's source and runs it with $input and $getWorkflowStaticData stubbed. The code under test is the code that would run in n8n, so editing the workflow file is visible to the tests.

  • Validation happens before scoring

    An invalid submission is rejected with a reason rather than scored as a zero, which keeps bad data out of the CRM instead of inside it with a low number attached.

  • Credentials are referenced, never embedded

    The export names the credentials it needs and contains no values, tokens or endpoints.

What was delivered

An importable workflow with its business logic under test, plus example inputs and a diagram.

Results

  • 22 tests pass by executing the workflow's own Code-node JavaScript.
  • No credentials, tokens or endpoints are present in the exported workflow, only named credential references.
  • The workflow has not been run inside an n8n instance; the logic is verified, the orchestration is not.

These are tested capabilities of the demonstration, not commercial outcomes.

Technology stack

  • n8n
  • JavaScript
  • Node.js test runner
  • SVG

Get in touch

Have a similar project in mind?

Whether you're launching a brand, developing a digital product, or automating business workflows, let's discuss how to bring your idea to life.