@@ -3,12 +3,8 @@ import { TableAlerts } from "../table-alerts";
3
3
import { render , screen , waitFor , within } from "@/lib/test-utils" ;
4
4
import { server } from "@/mocks/msw/node" ;
5
5
import { http , HttpResponse } from "msw" ;
6
- import {
7
- AlertConversation ,
8
- ProviderType ,
9
- QuestionType ,
10
- TokenUsageAggregate ,
11
- } from "@/api/generated" ;
6
+ import { makeMockAlert } from "../../mocks/alert.mock" ;
7
+ import { TOKEN_USAGE_AGG } from "../../mocks/token-usage.mock" ;
12
8
13
9
vi . mock ( "@untitled-ui/icons-react" , async ( ) => {
14
10
const original = await vi . importActual <
@@ -21,63 +17,6 @@ vi.mock("@untitled-ui/icons-react", async () => {
21
17
} ;
22
18
} ) ;
23
19
24
- const TOKEN_USAGE_AGG = {
25
- tokens_by_model : {
26
- "claude-3-5-sonnet-latest" : {
27
- provider_type : ProviderType . ANTHROPIC ,
28
- model : "claude-3-5-sonnet-latest" ,
29
- token_usage : {
30
- input_tokens : 1183 ,
31
- output_tokens : 433 ,
32
- input_cost : 0.003549 ,
33
- output_cost : 0.006495 ,
34
- } ,
35
- } ,
36
- } ,
37
- token_usage : {
38
- input_tokens : 1183 ,
39
- output_tokens : 433 ,
40
- input_cost : 0.003549 ,
41
- output_cost : 0.006495 ,
42
- } ,
43
- } as const satisfies TokenUsageAggregate ;
44
-
45
- const makeMockAlert = ( {
46
- token_usage_agg,
47
- } : {
48
- token_usage_agg : TokenUsageAggregate | null ;
49
- } ) => {
50
- return {
51
- conversation : {
52
- question_answers : [
53
- {
54
- question : {
55
- message : "foo" ,
56
- timestamp : "2025-01-28T14:32:57.836445Z" ,
57
- message_id : "cfdf1acd-999c-430b-bb57-4c4db6cec6c9" ,
58
- } ,
59
- answer : {
60
- message : "bar" ,
61
- timestamp : "2025-01-28T14:32:59.107793Z" ,
62
- message_id : "c2b88968-06b3-485d-a42b-7b54f973eef9" ,
63
- } ,
64
- } ,
65
- ] ,
66
- provider : "anthropic" ,
67
- type : QuestionType . CHAT ,
68
- chat_id : "cfdf1acd-999c-430b-bb57-4c4db6cec6c9" ,
69
- conversation_timestamp : "2025-01-28T14:32:57.836445Z" ,
70
- token_usage_agg,
71
- } ,
72
- alert_id : "2379b08b-1e2b-4d6b-b425-e58a0b4fe7bc" ,
73
- code_snippet : null ,
74
- trigger_string : "foo" ,
75
- trigger_type : "codegate-secrets" ,
76
- trigger_category : "critical" ,
77
- timestamp : "2025-01-28T14:32:57.599032Z" ,
78
- } as const satisfies AlertConversation ;
79
- } ;
80
-
81
20
const INPUT_TOKENS =
82
21
TOKEN_USAGE_AGG . tokens_by_model [
83
22
"claude-3-5-sonnet-latest"
@@ -92,7 +31,7 @@ test("renders token usage cell correctly", async () => {
92
31
server . use (
93
32
http . get ( "*/workspaces/:name/alerts" , ( ) => {
94
33
return HttpResponse . json ( [
95
- makeMockAlert ( { token_usage_agg : TOKEN_USAGE_AGG } ) ,
34
+ makeMockAlert ( { token_usage : true , type : "malicious" } ) ,
96
35
] ) ;
97
36
} ) ,
98
37
) ;
@@ -118,7 +57,9 @@ test("renders token usage cell correctly", async () => {
118
57
test ( "renders N/A when token usage is missing" , async ( ) => {
119
58
server . use (
120
59
http . get ( "*/workspaces/:name/alerts" , ( ) => {
121
- return HttpResponse . json ( [ makeMockAlert ( { token_usage_agg : null } ) ] ) ;
60
+ return HttpResponse . json ( [
61
+ makeMockAlert ( { token_usage : false , type : "malicious" } ) ,
62
+ ] ) ;
122
63
} ) ,
123
64
) ;
124
65
0 commit comments