-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayment-intent.test.ts
More file actions
111 lines (101 loc) · 3.45 KB
/
payment-intent.test.ts
File metadata and controls
111 lines (101 loc) · 3.45 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { describe, test, expect } from "vitest"
import {
classifyPaymentIntent,
type PaymentIntentContext,
} from "../payment-intent"
describe("classifyPaymentIntent", () => {
const baseContext: PaymentIntentContext = {
userMessage: "",
hasActiveJob: false,
hasAnyJob: false,
}
test("status keywords with active job -> status_check", () => {
const result = classifyPaymentIntent({
...baseContext,
userMessage: "What's the status of my order?",
hasActiveJob: true,
hasAnyJob: true,
})
expect(result.intent).toBe("status_check")
expect(result.confidence).toBe("high")
})
test("purchase keywords without active job -> new_purchase", () => {
const result = classifyPaymentIntent({
...baseContext,
userMessage: "I want to buy the ergonomic mouse",
hasActiveJob: false,
hasAnyJob: false,
})
expect(result.intent).toBe("new_purchase")
expect(result.confidence).toBe("high")
})
test("purchase keywords WITH active job -> status_check (safety-first)", () => {
const result = classifyPaymentIntent({
...baseContext,
userMessage: "Buy me another one",
hasActiveJob: true,
hasAnyJob: true,
})
// Safety-first: reclassified to status_check when active job exists
expect(result.intent).toBe("status_check")
})
test("ambiguous message with active job -> unknown", () => {
const result = classifyPaymentIntent({
...baseContext,
userMessage: "Hello, can you help me?",
hasActiveJob: true,
hasAnyJob: true,
})
expect(result.intent).toBe("unknown")
})
test("status keywords without any job -> unknown", () => {
// Use a message with only status keywords (no purchase keywords like "order")
const result = classifyPaymentIntent({
...baseContext,
userMessage: "Where is my delivery?",
hasActiveJob: false,
hasAnyJob: false,
})
expect(result.intent).toBe("unknown")
expect(result.confidence).toBe("low")
})
test("both status and purchase keywords with active job -> status_check", () => {
const result = classifyPaymentIntent({
...baseContext,
userMessage:
"Buy me a new one and check the status of the previous order",
hasActiveJob: true,
hasAnyJob: true,
})
expect(result.intent).toBe("status_check")
})
test("no matching keywords -> unknown with low confidence", () => {
const result = classifyPaymentIntent({
...baseContext,
userMessage: "Tell me about the weather today",
})
expect(result.intent).toBe("unknown")
expect(result.confidence).toBe("low")
})
test("does not match purchase keywords as substrings within larger words", () => {
const result = classifyPaymentIntent({
...baseContext,
userMessage: "Goodbye and thanks for your help!",
})
expect(result.intent).toBe("unknown")
expect(result.confidence).toBe("low")
})
test("checkout does not trigger status keyword substring collision", () => {
const result = classifyPaymentIntent({
...baseContext,
userMessage: "Go ahead and checkout now",
hasActiveJob: true,
hasAnyJob: true,
})
// If "check" matched as a substring in "checkout", this would be
// classified as ambiguous_with_active_job_safety_first instead.
expect(result.intent).toBe("status_check")
expect(result.confidence).toBe("medium")
expect(result.reason).toBe("purchase_intent_overridden_by_active_job")
})
})