@@ -4,10 +4,12 @@ import { server } from "@/mocks/msw/node";
4
4
import { emptyStateStrings } from "../../constants/strings" ;
5
5
import { useSearchParams } from "react-router-dom" ;
6
6
import { delay , http , HttpHandler , HttpResponse } from "msw" ;
7
- import { makeMockAlert } from "../../mocks/alert.mock" ;
7
+
8
8
import { AlertsFilterView } from "../../hooks/use-alerts-filter-search-params" ;
9
9
import { TableAlerts } from "../table-alerts" ;
10
10
import { hrefs } from "@/lib/hrefs" ;
11
+ import { mswEndpoint } from "@/test/msw-endpoint" ;
12
+ import { mockAlert } from "@/mocks/msw/mockers/alert.mock" ;
11
13
12
14
enum IllustrationTestId {
13
15
ALERT = "illustration-alert" ,
@@ -78,7 +80,7 @@ const TEST_CASES: TestCase[] = [
78
80
{
79
81
testDescription : "Loading state" ,
80
82
handlers : [
81
- http . get ( "* /api/v1/workspaces", ( ) => {
83
+ http . get ( mswEndpoint ( " /api/v1/workspaces") , ( ) => {
82
84
delay ( "infinite" ) ;
83
85
} ) ,
84
86
] ,
@@ -96,7 +98,7 @@ const TEST_CASES: TestCase[] = [
96
98
{
97
99
testDescription : "Only 1 workspace, no alerts" ,
98
100
handlers : [
99
- http . get ( "* /api/v1/workspaces", ( ) => {
101
+ http . get ( mswEndpoint ( " /api/v1/workspaces") , ( ) => {
100
102
return HttpResponse . json ( {
101
103
workspaces : [
102
104
{
@@ -106,12 +108,12 @@ const TEST_CASES: TestCase[] = [
106
108
] ,
107
109
} ) ;
108
110
} ) ,
109
- http . get ( "* /api/v1/workspaces/archive", ( ) => {
111
+ http . get ( mswEndpoint ( " /api/v1/workspaces/archive") , ( ) => {
110
112
return HttpResponse . json ( {
111
113
workspaces : [ ] ,
112
114
} ) ;
113
115
} ) ,
114
- http . get ( "* /api/v1/workspaces/:name /alerts", ( ) => {
116
+ http . get ( mswEndpoint ( " /api/v1/workspaces/:workspace_name /alerts") , ( ) => {
115
117
return HttpResponse . json ( [ ] ) ;
116
118
} ) ,
117
119
] ,
@@ -135,7 +137,7 @@ const TEST_CASES: TestCase[] = [
135
137
{
136
138
testDescription : "No search results" ,
137
139
handlers : [
138
- http . get ( "* /api/v1/workspaces", ( ) => {
140
+ http . get ( mswEndpoint ( " /api/v1/workspaces") , ( ) => {
139
141
return HttpResponse . json ( {
140
142
workspaces : [
141
143
{
@@ -145,16 +147,14 @@ const TEST_CASES: TestCase[] = [
145
147
] ,
146
148
} ) ;
147
149
} ) ,
148
- http . get ( "* /api/v1/workspaces/archive", ( ) => {
150
+ http . get ( mswEndpoint ( " /api/v1/workspaces/archive") , ( ) => {
149
151
return HttpResponse . json ( {
150
152
workspaces : [ ] ,
151
153
} ) ;
152
154
} ) ,
153
- http . get ( "* /api/v1/workspaces/:name /alerts", ( ) => {
155
+ http . get ( mswEndpoint ( " /api/v1/workspaces/:workspace_name /alerts") , ( ) => {
154
156
return HttpResponse . json (
155
- Array . from ( { length : 10 } , ( ) =>
156
- makeMockAlert ( { type : "malicious" } ) ,
157
- ) ,
157
+ Array . from ( { length : 10 } , ( ) => mockAlert ( { type : "malicious" } ) ) ,
158
158
) ;
159
159
} ) ,
160
160
] ,
@@ -174,7 +174,7 @@ const TEST_CASES: TestCase[] = [
174
174
{
175
175
testDescription : "No alerts, multiple workspaces" ,
176
176
handlers : [
177
- http . get ( "* /api/v1/workspaces", ( ) => {
177
+ http . get ( mswEndpoint ( " /api/v1/workspaces") , ( ) => {
178
178
return HttpResponse . json ( {
179
179
workspaces : [
180
180
{
@@ -188,12 +188,12 @@ const TEST_CASES: TestCase[] = [
188
188
] ,
189
189
} ) ;
190
190
} ) ,
191
- http . get ( "* /api/v1/workspaces/archive", ( ) => {
191
+ http . get ( mswEndpoint ( " /api/v1/workspaces/archive") , ( ) => {
192
192
return HttpResponse . json ( {
193
193
workspaces : [ ] ,
194
194
} ) ;
195
195
} ) ,
196
- http . get ( "* /api/v1/workspaces/:name /alerts", ( ) => {
196
+ http . get ( mswEndpoint ( " /api/v1/workspaces/:workspace_name /alerts") , ( ) => {
197
197
return HttpResponse . json ( [ ] ) ;
198
198
} ) ,
199
199
] ,
@@ -217,7 +217,7 @@ const TEST_CASES: TestCase[] = [
217
217
{
218
218
testDescription : 'Has alerts, view is "malicious"' ,
219
219
handlers : [
220
- http . get ( "* /api/v1/workspaces", ( ) => {
220
+ http . get ( mswEndpoint ( " /api/v1/workspaces") , ( ) => {
221
221
return HttpResponse . json ( {
222
222
workspaces : [
223
223
{
@@ -231,16 +231,14 @@ const TEST_CASES: TestCase[] = [
231
231
] ,
232
232
} ) ;
233
233
} ) ,
234
- http . get ( "* /api/v1/workspaces/archive", ( ) => {
234
+ http . get ( mswEndpoint ( " /api/v1/workspaces/archive") , ( ) => {
235
235
return HttpResponse . json ( {
236
236
workspaces : [ ] ,
237
237
} ) ;
238
238
} ) ,
239
- http . get ( "* /api/v1/workspaces/:name /alerts", ( ) => {
239
+ http . get ( mswEndpoint ( " /api/v1/workspaces/:workspace_name /alerts") , ( ) => {
240
240
return HttpResponse . json (
241
- Array . from ( { length : 10 } ) . map ( ( ) =>
242
- makeMockAlert ( { type : "secret" } ) ,
243
- ) ,
241
+ Array . from ( { length : 10 } ) . map ( ( ) => mockAlert ( { type : "secret" } ) ) ,
244
242
) ;
245
243
} ) ,
246
244
] ,
@@ -258,7 +256,7 @@ const TEST_CASES: TestCase[] = [
258
256
{
259
257
testDescription : 'Has alerts, view is "secret"' ,
260
258
handlers : [
261
- http . get ( "* /api/v1/workspaces", ( ) => {
259
+ http . get ( mswEndpoint ( " /api/v1/workspaces") , ( ) => {
262
260
return HttpResponse . json ( {
263
261
workspaces : [
264
262
{
@@ -272,15 +270,15 @@ const TEST_CASES: TestCase[] = [
272
270
] ,
273
271
} ) ;
274
272
} ) ,
275
- http . get ( "* /api/v1/workspaces/archive", ( ) => {
273
+ http . get ( mswEndpoint ( " /api/v1/workspaces/archive") , ( ) => {
276
274
return HttpResponse . json ( {
277
275
workspaces : [ ] ,
278
276
} ) ;
279
277
} ) ,
280
- http . get ( "* /api/v1/workspaces/:name /alerts", ( ) => {
278
+ http . get ( mswEndpoint ( " /api/v1/workspaces/:workspace_name /alerts") , ( ) => {
281
279
return HttpResponse . json (
282
280
Array . from ( { length : 10 } ) . map ( ( ) =>
283
- makeMockAlert ( { type : "malicious" } ) ,
281
+ mockAlert ( { type : "malicious" } ) ,
284
282
) ,
285
283
) ;
286
284
} ) ,
0 commit comments