|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | + |
| 3 | +import type { RoutingStep } from "../repositories/RoutingTraceRepository.interface"; |
| 4 | +import { RoutingFormTracePresenter } from "./RoutingFormTracePresenter"; |
| 5 | + |
| 6 | +function makeStep(step: string, data: Record<string, unknown> = {}): RoutingStep { |
| 7 | + return { domain: "routing_form", step, timestamp: Date.now(), data }; |
| 8 | +} |
| 9 | + |
| 10 | +describe("RoutingFormTracePresenter", () => { |
| 11 | + it("presents route_matched", () => { |
| 12 | + const result = RoutingFormTracePresenter.present( |
| 13 | + makeStep("route_matched", { routeId: "route-1", routeName: "Enterprise" }) |
| 14 | + ); |
| 15 | + expect(result).toBe('Route matched: "Enterprise" (ID: route-1)'); |
| 16 | + }); |
| 17 | + |
| 18 | + it("presents fallback_route_used", () => { |
| 19 | + const result = RoutingFormTracePresenter.present( |
| 20 | + makeStep("fallback_route_used", { routeId: "route-2", routeName: "Default" }) |
| 21 | + ); |
| 22 | + expect(result).toBe('Fallback route used: "Default" (ID: route-2)'); |
| 23 | + }); |
| 24 | + |
| 25 | + it("presents attribute-logic-evaluated with all fields", () => { |
| 26 | + const result = RoutingFormTracePresenter.present( |
| 27 | + makeStep("attribute-logic-evaluated", { |
| 28 | + routeName: "APAC", |
| 29 | + routeIsFallback: false, |
| 30 | + attributeRoutingDetails: [ |
| 31 | + { attributeName: "Company Size", attributeValue: "Enterprise" }, |
| 32 | + { attributeName: "Region", attributeValue: "APAC" }, |
| 33 | + ], |
| 34 | + }) |
| 35 | + ); |
| 36 | + expect(result).toBe( |
| 37 | + 'Attribute logic evaluated: Route: "APAC" Attributes: [Company Size=Enterprise, Region=APAC]' |
| 38 | + ); |
| 39 | + }); |
| 40 | + |
| 41 | + it("presents attribute-logic-evaluated with fallback", () => { |
| 42 | + const result = RoutingFormTracePresenter.present( |
| 43 | + makeStep("attribute-logic-evaluated", { |
| 44 | + routeName: "Fallback Route", |
| 45 | + routeIsFallback: true, |
| 46 | + }) |
| 47 | + ); |
| 48 | + expect(result).toBe('Attribute logic evaluated: Route: "Fallback Route" (fallback)'); |
| 49 | + }); |
| 50 | + |
| 51 | + it("presents attribute-logic-evaluated with no optional fields", () => { |
| 52 | + const result = RoutingFormTracePresenter.present(makeStep("attribute-logic-evaluated", {})); |
| 53 | + expect(result).toBe('Attribute logic evaluated: Route: "Unnamed route"'); |
| 54 | + }); |
| 55 | + |
| 56 | + it("presents attribute_fallback_used with routeName", () => { |
| 57 | + const result = RoutingFormTracePresenter.present( |
| 58 | + makeStep("attribute_fallback_used", { routeName: "Default Route" }) |
| 59 | + ); |
| 60 | + expect(result).toBe('Attribute fallback used: "Default Route"'); |
| 61 | + }); |
| 62 | + |
| 63 | + it("presents attribute_fallback_used without routeName", () => { |
| 64 | + const result = RoutingFormTracePresenter.present(makeStep("attribute_fallback_used", {})); |
| 65 | + expect(result).toBe('Attribute fallback used: "Unnamed route"'); |
| 66 | + }); |
| 67 | + |
| 68 | + it("presents route_matched without routeName", () => { |
| 69 | + const result = RoutingFormTracePresenter.present( |
| 70 | + makeStep("route_matched", { routeId: "route-1" }) |
| 71 | + ); |
| 72 | + expect(result).toBe('Route matched: "Unnamed route" (ID: route-1)'); |
| 73 | + }); |
| 74 | + |
| 75 | + it("presents fallback_route_used without routeName", () => { |
| 76 | + const result = RoutingFormTracePresenter.present( |
| 77 | + makeStep("fallback_route_used", { routeId: "route-2" }) |
| 78 | + ); |
| 79 | + expect(result).toBe('Fallback route used: "Unnamed route" (ID: route-2)'); |
| 80 | + }); |
| 81 | + |
| 82 | + it("treats routeName matching routeId as unnamed", () => { |
| 83 | + const result = RoutingFormTracePresenter.present( |
| 84 | + makeStep("route_matched", { routeId: "abc-123", routeName: "abc-123" }) |
| 85 | + ); |
| 86 | + expect(result).toBe('Route matched: "Unnamed route" (ID: abc-123)'); |
| 87 | + }); |
| 88 | + |
| 89 | + it("returns fallback for unknown step", () => { |
| 90 | + const result = RoutingFormTracePresenter.present(makeStep("unknown_step", {})); |
| 91 | + expect(result).toBe("Routing Form: unknown_step"); |
| 92 | + }); |
| 93 | +}); |
0 commit comments