Testing a process
A test runs a process on an engine of its own, with a clock it moves by hand and randomness from a seed, so the same test runs the same way every time.
A test of the claim
This test starts two claims, one within its appraisal and one over it, answers the adjuster’s wait on the second, and checks that both end paid, each payment made once.
import { describe, expect, it } from 'vite-plus/test';
import { Engine, Status } from '@trestlerun/engine';
import { ManualClock, SeededRandomness } from '@trestlerun/process/fakes';
import { EdgePoint, OutcomeKind } from '@trestlerun/process/graph';
import { claim, payments } from './landing-claim.js';
describe('landing', () => {
it('pays a claim within its appraisal, and one over it once approved', async () => {
const engine = new Engine({
processes: [claim],
clock: new ManualClock(),
randomness: new SeededRandomness({ seed: 1 }),
});
const within = await engine.start(claim, {
input: { policy: 'HOME-1', amount: 900 },
});
expect(within.end?.name).toBe('paid');
const over = await engine.start(claim, {
input: { policy: 'HOME-2', amount: 20_000 },
});
await over.answer('Adjuster approves', true);
const done = await over.until(Status.Done);
expect(done.end?.name).toBe('paid');
// Each payment reached the bank once.
expect([...payments.values()]).toEqual([900, 20_000]);
// The graph draws the approved claim's way to payment.
const graph = await engine.graph(claim);
expect(graph.edges).toContainEqual({
from: { kind: EdgePoint.Node, path: 'Approved?' },
outcome: { kind: OutcomeKind.Case, name: 'yes' },
to: { kind: EdgePoint.Node, path: 'Pay the claim' },
isBack: false,
});
});
});import { describe, expect, it } from 'vite-plus/test';
import { Engine, Status } from '@trestlerun/engine';
import {
ManualClock,
SeededRandomness,
} from '@trestlerun/process/fakes';
import { EdgePoint, OutcomeKind } from '@trestlerun/process/graph';
import { claim, payments } from './landing-claim.js';
describe('landing', () => {
it('pays a claim within its appraisal, and one over it once approved', async () => {
const engine = new Engine({
processes: [claim],
clock: new ManualClock(),
randomness: new SeededRandomness({ seed: 1 }),
});
const within = await engine.start(claim, {
input: { policy: 'HOME-1', amount: 900 },
});
expect(within.end?.name).toBe('paid');
const over = await engine.start(claim, {
input: { policy: 'HOME-2', amount: 20_000 },
});
await over.answer('Adjuster approves', true);
const done = await over.until(Status.Done);
expect(done.end?.name).toBe('paid');
// Each payment reached the bank once.
expect([...payments.values()]).toEqual([900, 20_000]);
// The graph draws the approved claim's way to payment.
const graph = await engine.graph(claim);
expect(graph.edges).toContainEqual({
from: { kind: EdgePoint.Node, path: 'Approved?' },
outcome: { kind: OutcomeKind.Case, name: 'yes' },
to: { kind: EdgePoint.Node, path: 'Pay the claim' },
isBack: false,
});
});
});import { describe, expect, it } from 'vite-plus/test';
import { Engine, Status } from '@trestlerun/engine';
import {
ManualClock,
SeededRandomness,
} from '@trestlerun/process/fakes';
import {
EdgePoint,
OutcomeKind,
} from '@trestlerun/process/graph';
import { claim, payments } from './landing-claim.js';
describe('landing', () => {
it('pays a claim within its appraisal, and one over it once approved', async () => {
const engine = new Engine({
processes: [claim],
clock: new ManualClock(),
randomness: new SeededRandomness({ seed: 1 }),
});
const within = await engine.start(claim, {
input: { policy: 'HOME-1', amount: 900 },
});
expect(within.end?.name).toBe('paid');
const over = await engine.start(claim, {
input: { policy: 'HOME-2', amount: 20_000 },
});
await over.answer('Adjuster approves', true);
const done = await over.until(Status.Done);
expect(done.end?.name).toBe('paid');
// Each payment reached the bank once.
expect([...payments.values()]).toEqual([900, 20_000]);
// The graph draws the approved claim's way to payment.
const graph = await engine.graph(claim);
expect(graph.edges).toContainEqual({
from: { kind: EdgePoint.Node, path: 'Approved?' },
outcome: { kind: OutcomeKind.Case, name: 'yes' },
to: { kind: EdgePoint.Node, path: 'Pay the claim' },
isBack: false,
});
});
});import {
describe,
expect,
it,
} from 'vite-plus/test';
import {
Engine,
Status,
} from '@trestlerun/engine';
import {
ManualClock,
SeededRandomness,
} from '@trestlerun/process/fakes';
import {
EdgePoint,
OutcomeKind,
} from '@trestlerun/process/graph';
import {
claim,
payments,
} from './landing-claim.js';
describe('landing', () => {
it('pays a claim within its appraisal, and one over it once approved', async () => {
const engine = new Engine({
processes: [claim],
clock: new ManualClock(),
randomness: new SeededRandomness({
seed: 1,
}),
});
const within = await engine.start(claim, {
input: { policy: 'HOME-1', amount: 900 },
});
expect(within.end?.name).toBe('paid');
const over = await engine.start(claim, {
input: { policy: 'HOME-2', amount: 20_000 },
});
await over.answer('Adjuster approves', true);
const done = await over.until(Status.Done);
expect(done.end?.name).toBe('paid');
// Each payment reached the bank once.
expect([...payments.values()]).toEqual([
900, 20_000,
]);
// The graph draws the approved claim's way to
// payment.
const graph = await engine.graph(claim);
expect(graph.edges).toContainEqual({
from: {
kind: EdgePoint.Node,
path: 'Approved?',
},
outcome: {
kind: OutcomeKind.Case,
name: 'yes',
},
to: {
kind: EdgePoint.Node,
path: 'Pay the claim',
},
isBack: false,
});
});
});import {
describe,
expect,
it,
} from 'vite-plus/test';
import {
Engine,
Status,
} from '@trestlerun/engine';
import {
ManualClock,
SeededRandomness,
} from '@trestlerun/process/fakes';
import {
EdgePoint,
OutcomeKind,
} from '@trestlerun/process/graph';
import {
claim,
payments,
} from './landing-claim.js';
describe('landing', () => {
it('pays a claim within its appraisal, and one over it once approved', async () => {
const engine = new Engine({
processes: [claim],
clock: new ManualClock(),
randomness: new SeededRandomness({
seed: 1,
}),
});
const within = await engine.start(
claim,
{
input: {
policy: 'HOME-1',
amount: 900,
},
},
);
expect(within.end?.name).toBe('paid');
const over = await engine.start(
claim,
{
input: {
policy: 'HOME-2',
amount: 20_000,
},
},
);
await over.answer(
'Adjuster approves',
true,
);
const done = await over.until(
Status.Done,
);
expect(done.end?.name).toBe('paid');
// Each payment reached the bank once.
expect([
...payments.values(),
]).toEqual([900, 20_000]);
// The graph draws the approved
// claim's way to payment.
const graph =
await engine.graph(claim);
expect(graph.edges).toContainEqual({
from: {
kind: EdgePoint.Node,
path: 'Approved?',
},
outcome: {
kind: OutcomeKind.Case,
name: 'yes',
},
to: {
kind: EdgePoint.Node,
path: 'Pay the claim',
},
isBack: false,
});
});
});import {
describe,
expect,
it,
} from 'vite-plus/test';
import {
Engine,
Status,
} from '@trestlerun/engine';
import {
ManualClock,
SeededRandomness,
} from '@trestlerun/process/fakes';
import {
EdgePoint,
OutcomeKind,
} from '@trestlerun/process/graph';
import {
claim,
payments,
} from './landing-claim.js';
describe('landing', () => {
it('pays a claim within its appraisal, and one over it once approved', async () => {
const engine = new Engine({
processes: [claim],
clock: new ManualClock(),
randomness:
new SeededRandomness({
seed: 1,
}),
});
const within =
await engine.start(claim, {
input: {
policy: 'HOME-1',
amount: 900,
},
});
expect(within.end?.name).toBe(
'paid',
);
const over = await engine.start(
claim,
{
input: {
policy: 'HOME-2',
amount: 20_000,
},
},
);
await over.answer(
'Adjuster approves',
true,
);
const done = await over.until(
Status.Done,
);
expect(done.end?.name).toBe(
'paid',
);
// Each payment reached the bank
// once.
expect([
...payments.values(),
]).toEqual([900, 20_000]);
// The graph draws the approved
// claim's way to payment.
const graph =
await engine.graph(claim);
expect(
graph.edges,
).toContainEqual({
from: {
kind: EdgePoint.Node,
path: 'Approved?',
},
outcome: {
kind: OutcomeKind.Case,
name: 'yes',
},
to: {
kind: EdgePoint.Node,
path: 'Pay the claim',
},
isBack: false,
});
});
});import {
describe,
expect,
it,
} from 'vite-plus/test';
import {
Engine,
Status,
} from '@trestlerun/engine';
import {
ManualClock,
SeededRandomness,
} from '@trestlerun/process/fakes';
import {
EdgePoint,
OutcomeKind,
} from '@trestlerun/process/graph';
import {
claim,
payments,
} from './landing-claim.js';
describe('landing', () => {
it('pays a claim within its appraisal, and one over it once approved', async () => {
const engine = new Engine(
{
processes: [claim],
clock:
new ManualClock(),
randomness:
new SeededRandomness(
{ seed: 1 },
),
},
);
const within =
await engine.start(
claim,
{
input: {
policy: 'HOME-1',
amount: 900,
},
},
);
expect(
within.end?.name,
).toBe('paid');
const over =
await engine.start(
claim,
{
input: {
policy: 'HOME-2',
amount: 20_000,
},
},
);
await over.answer(
'Adjuster approves',
true,
);
const done =
await over.until(
Status.Done,
);
expect(
done.end?.name,
).toBe('paid');
// Each payment reached
// the bank once.
expect([
...payments.values(),
]).toEqual([900, 20_000]);
// The graph draws the
// approved claim's way to
// payment.
const graph =
await engine.graph(
claim,
);
expect(
graph.edges,
).toContainEqual({
from: {
kind: EdgePoint.Node,
path: 'Approved?',
},
outcome: {
kind: OutcomeKind.Case,
name: 'yes',
},
to: {
kind: EdgePoint.Node,
path: 'Pay the claim',
},
isBack: false,
});
});
});What to test
| Test | Why |
|---|---|
| Each end a run can reach | Every way through the process is checked once. |
| Each answer a wait can be given | A person’s answer changes which way the run goes. |
| A wait whose window runs out | The run must do the right thing when nobody answers. |