Class EntryRecordingReporter

A recording reporter that also keeps every entry of global metadata it receives, in order, each with the kind of the event it received last before it, so that a test can check when an entry was set, and every value a key was given, not only the latest. Like RecordingReporter, it never fails.

import assert from "node:assert/strict";
import { LocalExecutor } from "itinera/executor";
import { None, Some } from "itinera/option";
import {
type Outcome,
Step,
stepReporter,
type StepReporter,
} from "itinera/step";
import { EntryRecordingReporter } from "itinera/testing";
import { Workflow } from "itinera/workflow";

class Lookup extends Step {
override async run(reporter: StepReporter): Promise<Outcome> {
await reporter.setGlobalMetadata("user_id", "u-7");
await reporter.setGlobalMetadata("user_id", "u-8");
return this.succeed();
}
}

class Orders extends Workflow {}

export default (async () => {
const orders = Orders.builder()
.name("orders")
.step(Lookup.builder("lookup").run(stepReporter()))
.build();
const recorder = new EntryRecordingReporter();
const instance = orders.instance({}, { reporters: [recorder] });

await new LocalExecutor().run(instance);

assert.deepEqual(recorder.entries, [
{ key: "journey_id", value: instance.journeyId, after: None },
{ key: "user_id", value: "u-7", after: Some("attempt_started") },
{ key: "user_id", value: "u-8", after: Some("global_metadata_set") },
]);
assert.equal(recorder.globalMetadata.get("user_id"), "u-8");
})();

Hierarchy (View Summary)

Index

  • get globalMetadata(): ReadonlyMap<string, PlainValue>

    The global metadata it has received so far: each key with its latest value, in the order the keys were first set. The journey ID is the first entry, under journey_id.

    Returns ReadonlyMap<string, PlainValue>

  • get path(): readonly string[]

    The path of the journey so far: one line for each event of its flow, in the order it received them, so that a test can compare it with the path it expects, or with an approved file through path.join("\n").

    Only the flow has lines: the outcome of each attempt, each decision on a step, and how the journey ended. Inputs, services, hooks, contributions, the events steps, hooks and service providers emit, and global metadata have none, and no line holds a timestamp, a sequence number or an ID, so a path changes only when the flow does. The lines read:

    • charge attempt 1 succeeded; charge attempt 1 failed: declined, with the reason's code; charge attempt 1 skipped, with : and the reason's code when it has one; and charge attempt 1 terminated abnormally: timeout, with the error's message. A rescue step's attempts read the same under its own name, such as charge_rescue.
    • charge retrying; charge given up: retries exhausted, or the other cause, failure or abnormal termination; and charge given up: FailWorkflow from fraud_check when a hook of the policy fraud_check gave it up.
    • charge rescuing with charge_rescue and charge rescued by charge_rescue.
    • journey succeeded, or journey succeeded, decided by early_exit when a hook of the policy early_exit decided it; journey failed at charge: declined, with the code of the reason the journey failed for, or the error's message when there is no reason; and journey aborted at charge: step could not be built, with the abort reason, or journey aborted: reporter failed when the abort concerns no step.

    A refused journey has no events, so its path is empty.

    Returns readonly string[]