File size: 1,373 Bytes
9580dce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { resolveProblem, registerProblem } from "../store";
import { PROBLEM_BANK } from "../bank";

describe("resolveProblem", () => {
  it("resolves a bank problem by its canonical id", () => {
    const id = PROBLEM_BANK[0].id;
    expect(resolveProblem(id)?.id).toBe(id);
  });

  it("resolves an instance id (bankId::uuid) back to the bank problem", () => {
    // This is the key serverless property: a fresh lambda instance that never
    // saw the registration must still resolve a bank-derived instance id.
    const bank = PROBLEM_BANK[0];
    const instanceId = `${bank.id}::00000000-0000-0000-0000-000000000000`;
    const resolved = resolveProblem(instanceId);
    expect(resolved).not.toBeNull();
    expect(resolved!.type).toBe(bank.type);
    expect(resolved!.title).toBe(bank.title);
  });

  it("prefers an exactly-registered instance over the bank fallback", () => {
    const bank = PROBLEM_BANK.find((p) => p.type === "code-creation")!;
    const instanceId = `${bank.id}::deadbeef`;
    const custom = { ...bank, id: instanceId, title: "CUSTOM" };
    registerProblem(custom);
    expect(resolveProblem(instanceId)?.title).toBe("CUSTOM");
  });

  it("returns null for an unknown id with no bank prefix", () => {
    expect(resolveProblem("not-a-real-problem")).toBeNull();
    expect(resolveProblem("not-a-real-problem::abc")).toBeNull();
  });
});