Add MSW infrastructure: handlers, fixtures, request-log, and Vitest setup

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-22 07:38:02 +08:00
parent 0ff03ec0ef
commit 7e052f0d36
30 changed files with 5144 additions and 0 deletions

8
src/mocks/browser.js Normal file
View File

@@ -0,0 +1,8 @@
/**
* MSW worker for browser (Cypress E2E).
* @module mocks/browser
*/
import { setupWorker } from "msw/browser";
import { handlers } from "./handlers/index.js";
export const worker = setupWorker(...handlers);

View File

@@ -0,0 +1,92 @@
{
"time": {
"avg_cycle_time": {
"primary": [
{ "date": "2022-01-15", "value": 500000 },
{ "date": "2022-06-15", "value": 600000 },
{ "date": "2022-12-15", "value": 550000 }
],
"secondary": [
{ "date": "2022-01-15", "value": 480000 },
{ "date": "2022-06-15", "value": 520000 },
{ "date": "2022-12-15", "value": 510000 }
]
},
"avg_cycle_efficiency": {
"primary": [
{ "label": "File A", "value": 0.75 }
],
"secondary": [
{ "label": "File B", "value": 0.68 }
]
},
"avg_process_time": {
"primary": [
{ "date": "2022-01-15", "value": 300000 },
{ "date": "2022-06-15", "value": 350000 },
{ "date": "2022-12-15", "value": 320000 }
],
"secondary": [
{ "date": "2022-01-15", "value": 280000 },
{ "date": "2022-06-15", "value": 310000 },
{ "date": "2022-12-15", "value": 290000 }
]
},
"avg_process_time_by_task": {
"primary": [
{ "label": ["Activity", "A"], "value": 120000 },
{ "label": ["Activity", "B"], "value": 80000 }
],
"secondary": [
{ "label": ["Activity", "A"], "value": 110000 },
{ "label": ["Activity", "B"], "value": 95000 }
]
},
"avg_waiting_time": {
"primary": [
{ "date": "2022-01-15", "value": 200000 },
{ "date": "2022-06-15", "value": 250000 },
{ "date": "2022-12-15", "value": 230000 }
],
"secondary": [
{ "date": "2022-01-15", "value": 200000 },
{ "date": "2022-06-15", "value": 210000 },
{ "date": "2022-12-15", "value": 220000 }
]
},
"avg_waiting_time_by_edge": {
"primary": [
{ "label": ["A", "B"], "value": 150000 },
{ "label": ["B", "C"], "value": 100000 }
],
"secondary": [
{ "label": ["A", "B"], "value": 140000 },
{ "label": ["B", "C"], "value": 110000 }
]
}
},
"freq": {
"cases": {
"primary": [
{ "count": 100 },
{ "count": 120 },
{ "count": 110 }
],
"secondary": [
{ "count": 95 },
{ "count": 105 },
{ "count": 100 }
]
},
"cases_by_task": {
"primary": [
{ "label": ["Activity", "A"], "value": 200 },
{ "label": ["Activity", "B"], "value": 150 }
],
"secondary": [
{ "label": ["Activity", "A"], "value": 180 },
{ "label": ["Activity", "B"], "value": 160 }
]
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,42 @@
[
{
"type": "log",
"id": 1,
"name": "sample-process.xes",
"parent": null,
"owner": { "username": "testadmin", "name": "Test Admin" },
"updated_at": "2025-06-10T14:30:00Z",
"accessed_at": "2025-06-12T09:00:00Z",
"is_deleted": false
},
{
"type": "filter",
"id": 10,
"name": "filtered-sample",
"parent": { "type": "log", "id": 1, "name": "sample-process.xes" },
"owner": { "username": "testadmin", "name": "Test Admin" },
"updated_at": "2025-06-11T08:00:00Z",
"accessed_at": "2025-06-12T10:00:00Z",
"is_deleted": false
},
{
"type": "log",
"id": 2,
"name": "production-log.csv",
"parent": null,
"owner": { "username": "user1", "name": "Alice Wang" },
"updated_at": "2025-06-09T16:00:00Z",
"accessed_at": null,
"is_deleted": false
},
{
"type": "log-check",
"id": 100,
"name": "conformance-check-1",
"parent": { "type": "log", "id": 1, "name": "sample-process.xes" },
"owner": { "username": "testadmin", "name": "Test Admin" },
"updated_at": "2025-06-11T12:00:00Z",
"accessed_at": null,
"is_deleted": false
}
]

View File

@@ -0,0 +1,249 @@
{
"tasks": [
{
"label": "a",
"occurrences": 187,
"occurrence_ratio": 0.10048361096184846,
"cases": 184,
"case_ratio": 0.7301587301587301
},
{
"label": "d",
"occurrences": 241,
"occurrence_ratio": 0.12950026867275657,
"cases": 241,
"case_ratio": 0.9563492063492064
},
{
"label": "e",
"occurrences": 249,
"occurrence_ratio": 0.1337990327780763,
"cases": 249,
"case_ratio": 0.9880952380952381
},
{
"label": "f",
"occurrences": 249,
"occurrence_ratio": 0.1337990327780763,
"cases": 249,
"case_ratio": 0.9880952380952381
},
{
"label": "g",
"occurrences": 253,
"occurrence_ratio": 0.13594841483073616,
"cases": 250,
"case_ratio": 0.9920634920634921
},
{
"label": "h",
"occurrences": 163,
"occurrence_ratio": 0.08758731864588931,
"cases": 163,
"case_ratio": 0.6468253968253969
},
{
"label": "i",
"occurrences": 185,
"occurrence_ratio": 0.09940891993551854,
"cases": 175,
"case_ratio": 0.6944444444444444
},
{
"label": "l",
"occurrences": 182,
"occurrence_ratio": 0.09779688339602365,
"cases": 182,
"case_ratio": 0.7222222222222222
},
{
"label": "c",
"occurrences": 48,
"occurrence_ratio": 0.025792584631918324,
"cases": 48,
"case_ratio": 0.19047619047619047
},
{
"label": "k",
"occurrences": 48,
"occurrence_ratio": 0.025792584631918324,
"cases": 48,
"case_ratio": 0.19047619047619047
},
{
"label": "b",
"occurrences": 34,
"occurrence_ratio": 0.018269747447608814,
"cases": 32,
"case_ratio": 0.12698412698412698
},
{
"label": "j",
"occurrences": 22,
"occurrence_ratio": 0.011821601289629231,
"cases": 22,
"case_ratio": 0.0873015873015873
}
],
"sources": [
{
"label": "a",
"occurrences": 175,
"occurrence_ratio": 0.6944444444444444,
"sinks": [
"k",
"l"
]
},
{
"label": "c",
"occurrences": 45,
"occurrence_ratio": 0.17857142857142858,
"sinks": [
"k"
]
},
{
"label": "b",
"occurrences": 32,
"occurrence_ratio": 0.12698412698412698,
"sinks": [
"k",
"j",
"l"
]
}
],
"sinks": [
{
"label": "l",
"occurrences": 182,
"occurrence_ratio": 0.7222222222222222,
"sources": [
"a",
"b"
]
},
{
"label": "k",
"occurrences": 48,
"occurrence_ratio": 0.19047619047619047,
"sources": [
"a",
"b",
"c"
]
},
{
"label": "j",
"occurrences": 22,
"occurrence_ratio": 0.0873015873015873,
"sources": [
"b"
]
}
],
"timeframe": {
"data": [
{
"x": "2022-01-21T03:21:48",
"y": 347
},
{
"x": "2022-02-26T08:13:24",
"y": 426
},
{
"x": "2022-04-03T13:05:00",
"y": 394
},
{
"x": "2022-05-09T17:56:36",
"y": 375
},
{
"x": "2022-06-14T22:48:12",
"y": 431
},
{
"x": "2022-07-21T03:39:48",
"y": 393
},
{
"x": "2022-08-26T08:31:24",
"y": 284
},
{
"x": "2022-10-01T13:23:00",
"y": 359
},
{
"x": "2022-11-06T18:14:36",
"y": 386
},
{
"x": "2022-12-12T23:06:12",
"y": 327
}
],
"x_axis": {
"min": "2022-01-03T00:56:00",
"max": "2022-12-31T01:32:00"
},
"y_axis": {
"min": 0,
"max": 431
}
},
"traces": [
{
"id": 1,
"count": 95
},
{
"id": 2,
"count": 74
},
{
"id": 3,
"count": 45
},
{
"id": 4,
"count": 22
},
{
"id": 5,
"count": 8
},
{
"id": 6,
"count": 2
},
{
"id": 7,
"count": 1
},
{
"id": 8,
"count": 1
},
{
"id": 9,
"count": 1
},
{
"id": 10,
"count": 1
},
{
"id": 11,
"count": 1
},
{
"id": 12,
"count": 1
}
],
"attrs": []
}

View File

@@ -0,0 +1,9 @@
{
"username": "testadmin",
"name": "Test Admin",
"is_sso": false,
"created_at": "2025-01-15T10:00:00Z",
"roles": [
{ "code": "admin", "name": "Administrator" }
]
}

View File

@@ -0,0 +1,928 @@
{
"time": {
"avg_cycle_time": {
"data": [
{
"x": "2022-01-21T03:21:48",
"y": 980220.0
},
{
"x": "2022-02-26T08:13:24",
"y": 1000376.129032
},
{
"x": "2022-04-03T13:05:00",
"y": 911990.0
},
{
"x": "2022-05-09T17:56:36",
"y": 1041860.0
},
{
"x": "2022-06-14T22:48:12",
"y": 985415.625
},
{
"x": "2022-07-21T03:39:48",
"y": 938079.130435
},
{
"x": "2022-08-26T08:31:24",
"y": 1074680.0
},
{
"x": "2022-10-01T13:23:00",
"y": 1061848.695652
},
{
"x": "2022-11-06T18:14:36",
"y": 970119.230769
},
{
"x": "2022-12-12T23:06:12",
"y": 1060703.076923
}
],
"x_axis": {
"min": "2022-01-03T00:56:00",
"max": "2022-12-31T01:32:00"
},
"y_axis": {
"min": 0.0,
"max": 1074680.0
}
},
"avg_cycle_efficiency": {
"data": [
{
"x": "2022-01-21T03:21:48",
"y": 0.9527980523449506
},
{
"x": "2022-02-26T08:13:24",
"y": 0.9516493513262202
},
{
"x": "2022-04-03T13:05:00",
"y": 0.9475330648076836
},
{
"x": "2022-05-09T17:56:36",
"y": 0.9537265449333607
},
{
"x": "2022-06-14T22:48:12",
"y": 0.9528919667258132
},
{
"x": "2022-07-21T03:39:48",
"y": 0.9489804015433904
},
{
"x": "2022-08-26T08:31:24",
"y": 0.9538748758272698
},
{
"x": "2022-10-01T13:23:00",
"y": 0.9548679615433759
},
{
"x": "2022-11-06T18:14:36",
"y": 0.9469965631092006
},
{
"x": "2022-12-12T23:06:12",
"y": 0.9505469198562757
}
],
"x_axis": {
"min": "2022-01-03T00:56:00",
"max": "2022-12-31T01:32:00"
},
"y_axis": {
"min": 0.0,
"max": 1.0
}
},
"avg_process_time": {
"data": [
{
"x": "2022-01-21T03:21:48",
"y": 937067.368421
},
{
"x": "2022-02-26T08:13:24",
"y": 953767.741935
},
{
"x": "2022-04-03T13:05:00",
"y": 865780.0
},
{
"x": "2022-05-09T17:56:36",
"y": 994600.0
},
{
"x": "2022-06-14T22:48:12",
"y": 939795.0
},
{
"x": "2022-07-21T03:39:48",
"y": 890947.826087
},
{
"x": "2022-08-26T08:31:24",
"y": 1026345.714286
},
{
"x": "2022-10-01T13:23:00",
"y": 1016363.478261
},
{
"x": "2022-11-06T18:14:36",
"y": 923626.153846
},
{
"x": "2022-12-12T23:06:12",
"y": 1011540.0
}
],
"x_axis": {
"min": "2022-01-03T00:56:00",
"max": "2022-12-31T01:32:00"
},
"y_axis": {
"min": 0.0,
"max": 1026345.714286
}
},
"avg_process_time_by_task": {
"data": [
{
"x": "a",
"y": 131147.486631
},
{
"x": "b",
"y": 136627.058824
},
{
"x": "c",
"y": 133261.25
},
{
"x": "d",
"y": 132697.095436
},
{
"x": "e",
"y": 124442.891566
},
{
"x": "f",
"y": 127175.180723
},
{
"x": "g",
"y": 127627.826087
},
{
"x": "h",
"y": 128163.680982
},
{
"x": "i",
"y": 125588.756757
},
{
"x": "j",
"y": 101290.909091
},
{
"x": "k",
"y": 142543.75
},
{
"x": "l",
"y": 138070.879121
}
],
"x_axis": {
"labels": [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l"
]
},
"y_axis": {
"min": 0.0,
"max": 142543.75
}
},
"avg_waiting_time": {
"data": [
{
"x": "2022-01-21T03:21:48",
"y": 43152.631579
},
{
"x": "2022-02-26T08:13:24",
"y": 46608.387097
},
{
"x": "2022-04-03T13:05:00",
"y": 46210.0
},
{
"x": "2022-05-09T17:56:36",
"y": 47260.0
},
{
"x": "2022-06-14T22:48:12",
"y": 45620.625
},
{
"x": "2022-07-21T03:39:48",
"y": 47131.304348
},
{
"x": "2022-08-26T08:31:24",
"y": 48334.285714
},
{
"x": "2022-10-01T13:23:00",
"y": 45485.217391
},
{
"x": "2022-11-06T18:14:36",
"y": 46493.076923
},
{
"x": "2022-12-12T23:06:12",
"y": 49163.076923
}
],
"x_axis": {
"min": "2022-01-03T00:56:00",
"max": "2022-12-31T01:32:00"
},
"y_axis": {
"min": 0.0,
"max": 49163.076923
}
},
"avg_waiting_time_by_edge": {
"data": [
{
"x": [
"a",
"a"
],
"y": 6420.0
},
{
"x": [
"a",
"d"
],
"y": 7506.352941
},
{
"x": [
"a",
"f"
],
"y": 5940.0
},
{
"x": [
"a",
"g"
],
"y": 5175.0
},
{
"x": [
"a",
"i"
],
"y": 6260.0
},
{
"x": [
"b",
"a"
],
"y": 6840.0
},
{
"x": [
"b",
"b"
],
"y": 3540.0
},
{
"x": [
"b",
"g"
],
"y": 7273.636364
},
{
"x": [
"b",
"i"
],
"y": 6288.0
},
{
"x": [
"c",
"g"
],
"y": 11460.0
},
{
"x": [
"c",
"h"
],
"y": 6821.73913
},
{
"x": [
"c",
"k"
],
"y": 13500.0
},
{
"x": [
"d",
"c"
],
"y": 11760.0
},
{
"x": [
"d",
"e"
],
"y": 7166.694915
},
{
"x": [
"d",
"g"
],
"y": 8080.0
},
{
"x": [
"d",
"i"
],
"y": 3600.0
},
{
"x": [
"e",
"a"
],
"y": 7260.0
},
{
"x": [
"e",
"d"
],
"y": 6780.0
},
{
"x": [
"e",
"f"
],
"y": 7288.474576
},
{
"x": [
"e",
"g"
],
"y": 14040.0
},
{
"x": [
"e",
"k"
],
"y": 13620.0
},
{
"x": [
"e",
"l"
],
"y": 3780.0
},
{
"x": [
"f",
"d"
],
"y": 10140.0
},
{
"x": [
"f",
"e"
],
"y": 3940.0
},
{
"x": [
"f",
"g"
],
"y": 6983.271028
},
{
"x": [
"f",
"j"
],
"y": 8170.909091
},
{
"x": [
"f",
"l"
],
"y": 6667.5
},
{
"x": [
"g",
"c"
],
"y": 2400.0
},
{
"x": [
"g",
"e"
],
"y": 11880.0
},
{
"x": [
"g",
"f"
],
"y": 5302.5
},
{
"x": [
"g",
"g"
],
"y": 11400.0
},
{
"x": [
"g",
"h"
],
"y": 7592.820513
},
{
"x": [
"g",
"i"
],
"y": 7140.0
},
{
"x": [
"g",
"k"
],
"y": 8116.0
},
{
"x": [
"g",
"l"
],
"y": 7457.368421
},
{
"x": [
"h",
"i"
],
"y": 7288.888889
},
{
"x": [
"h",
"l"
],
"y": 6960.0
},
{
"x": [
"i",
"a"
],
"y": 8910.0
},
{
"x": [
"i",
"b"
],
"y": 5880.0
},
{
"x": [
"i",
"c"
],
"y": 5460.0
},
{
"x": [
"i",
"d"
],
"y": 7710.447761
},
{
"x": [
"i",
"e"
],
"y": 9153.333333
},
{
"x": [
"i",
"g"
],
"y": 8640.0
},
{
"x": [
"i",
"i"
],
"y": 6324.0
},
{
"x": [
"i",
"k"
],
"y": 3240.0
},
{
"x": [
"i",
"l"
],
"y": 7188.75
}
],
"x_axis": {
"labels": [
[
"a",
"a"
],
[
"a",
"d"
],
[
"a",
"f"
],
[
"a",
"g"
],
[
"a",
"i"
],
[
"b",
"a"
],
[
"b",
"b"
],
[
"b",
"g"
],
[
"b",
"i"
],
[
"c",
"g"
],
[
"c",
"h"
],
[
"c",
"k"
],
[
"d",
"c"
],
[
"d",
"e"
],
[
"d",
"g"
],
[
"d",
"i"
],
[
"e",
"a"
],
[
"e",
"d"
],
[
"e",
"f"
],
[
"e",
"g"
],
[
"e",
"k"
],
[
"e",
"l"
],
[
"f",
"d"
],
[
"f",
"e"
],
[
"f",
"g"
],
[
"f",
"j"
],
[
"f",
"l"
],
[
"g",
"c"
],
[
"g",
"e"
],
[
"g",
"f"
],
[
"g",
"g"
],
[
"g",
"h"
],
[
"g",
"i"
],
[
"g",
"k"
],
[
"g",
"l"
],
[
"h",
"i"
],
[
"h",
"l"
],
[
"i",
"a"
],
[
"i",
"b"
],
[
"i",
"c"
],
[
"i",
"d"
],
[
"i",
"e"
],
[
"i",
"g"
],
[
"i",
"i"
],
[
"i",
"k"
],
[
"i",
"l"
]
]
},
"y_axis": {
"min": 0.0,
"max": 14040.0
}
}
},
"freq": {
"cases": {
"data": [
{
"x": "2022-01-21T03:21:48",
"y": 30
},
{
"x": "2022-02-26T08:13:24",
"y": 25
},
{
"x": "2022-04-03T13:05:00",
"y": 30
},
{
"x": "2022-05-09T17:56:36",
"y": 26
},
{
"x": "2022-06-14T22:48:12",
"y": 28
},
{
"x": "2022-07-21T03:39:48",
"y": 27
},
{
"x": "2022-08-26T08:31:24",
"y": 17
},
{
"x": "2022-10-01T13:23:00",
"y": 24
},
{
"x": "2022-11-06T18:14:36",
"y": 28
},
{
"x": "2022-12-12T23:06:12",
"y": 17
}
],
"x_axis": {
"min": "2022-01-03T00:56:00",
"max": "2022-12-31T01:32:00"
},
"y_axis": {
"min": 0,
"max": 30
}
},
"cases_by_task": {
"data": [
{
"x": "a",
"y": 184
},
{
"x": "b",
"y": 32
},
{
"x": "c",
"y": 48
},
{
"x": "d",
"y": 241
},
{
"x": "e",
"y": 249
},
{
"x": "f",
"y": 249
},
{
"x": "g",
"y": 250
},
{
"x": "h",
"y": 163
},
{
"x": "i",
"y": 175
},
{
"x": "j",
"y": 22
},
{
"x": "k",
"y": 48
},
{
"x": "l",
"y": 182
}
],
"x_axis": {
"labels": [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l"
]
},
"y_axis": {
"min": 0,
"max": 250
}
}
}
}

View File

@@ -0,0 +1,6 @@
{
"access_token": "fake-access-token-for-testing",
"token_type": "bearer",
"expires_in": 3600,
"refresh_token": "fake-refresh-token-for-testing"
}

View File

@@ -0,0 +1,154 @@
{
"task_seq": [
"a",
"d",
"e",
"f",
"g",
"h",
"i",
"l"
],
"cases": [
{
"id": "H00564053",
"started_at": "2022-01-03T00:56:00",
"completed_at": "2022-01-12T02:29:00",
"attributes": [],
"facets": []
},
{
"id": "H00723931",
"started_at": "2022-01-04T17:51:00",
"completed_at": "2022-01-17T10:00:00",
"attributes": [],
"facets": []
},
{
"id": "H00542949",
"started_at": "2022-01-10T19:05:00",
"completed_at": "2022-01-28T09:38:00",
"attributes": [],
"facets": []
},
{
"id": "H00320575",
"started_at": "2022-01-12T21:35:00",
"completed_at": "2022-01-24T19:38:00",
"attributes": [],
"facets": []
},
{
"id": "H00565387",
"started_at": "2022-01-20T20:30:00",
"completed_at": "2022-02-06T10:57:00",
"attributes": [],
"facets": []
},
{
"id": "H00832338",
"started_at": "2022-01-29T15:00:00",
"completed_at": "2022-02-13T17:46:00",
"attributes": [],
"facets": []
},
{
"id": "H00525137",
"started_at": "2022-02-05T23:26:00",
"completed_at": "2022-02-14T19:47:00",
"attributes": [],
"facets": []
},
{
"id": "H00093124",
"started_at": "2022-02-09T16:56:00",
"completed_at": "2022-02-28T17:38:00",
"attributes": [],
"facets": []
},
{
"id": "H00657586",
"started_at": "2022-02-14T20:07:00",
"completed_at": "2022-02-28T15:21:00",
"attributes": [],
"facets": []
},
{
"id": "H00141668",
"started_at": "2022-02-17T13:57:00",
"completed_at": "2022-03-06T00:01:00",
"attributes": [],
"facets": []
},
{
"id": "H00493818",
"started_at": "2022-02-20T19:54:00",
"completed_at": "2022-03-05T05:06:00",
"attributes": [],
"facets": []
},
{
"id": "H00488827",
"started_at": "2022-02-21T00:38:00",
"completed_at": "2022-03-03T16:24:00",
"attributes": [],
"facets": []
},
{
"id": "H00874806",
"started_at": "2022-02-24T15:15:00",
"completed_at": "2022-03-12T01:12:00",
"attributes": [],
"facets": []
},
{
"id": "H00395448",
"started_at": "2022-02-26T03:35:00",
"completed_at": "2022-03-08T23:11:00",
"attributes": [],
"facets": []
},
{
"id": "H00414605",
"started_at": "2022-02-26T17:11:00",
"completed_at": "2022-03-10T08:50:00",
"attributes": [],
"facets": []
},
{
"id": "H00564269",
"started_at": "2022-03-04T01:18:00",
"completed_at": "2022-03-16T08:14:00",
"attributes": [],
"facets": []
},
{
"id": "H00729845",
"started_at": "2022-03-05T09:29:00",
"completed_at": "2022-03-17T15:25:00",
"attributes": [],
"facets": []
},
{
"id": "H00194115",
"started_at": "2022-03-09T18:58:00",
"completed_at": "2022-03-23T09:01:00",
"attributes": [],
"facets": []
},
{
"id": "H00517238",
"started_at": "2022-03-21T06:30:00",
"completed_at": "2022-04-05T05:27:00",
"attributes": [],
"facets": []
},
{
"id": "H00377237",
"started_at": "2022-03-24T12:06:00",
"completed_at": "2022-04-04T15:44:00",
"attributes": [],
"facets": []
}
]
}

View File

@@ -0,0 +1,50 @@
[
{
"id": 1,
"count": 95
},
{
"id": 2,
"count": 74
},
{
"id": 3,
"count": 45
},
{
"id": 4,
"count": 22
},
{
"id": 5,
"count": 8
},
{
"id": 6,
"count": 2
},
{
"id": 7,
"count": 1
},
{
"id": 8,
"count": 1
},
{
"id": 9,
"count": 1
},
{
"id": 10,
"count": 1
},
{
"id": 11,
"count": 1
},
{
"id": 12,
"count": 1
}
]

View File

@@ -0,0 +1,14 @@
{
"username": "testadmin",
"name": "Test Admin",
"is_admin": true,
"is_active": true,
"is_sso": false,
"has_data": true,
"roles": [
{ "code": "admin", "name": "Administrator" }
],
"detail": {
"visits": 42
}
}

View File

@@ -0,0 +1,26 @@
[
{
"username": "testadmin",
"name": "Test Admin",
"is_admin": true,
"is_active": true,
"is_sso": false,
"has_data": true
},
{
"username": "user1",
"name": "Alice Wang",
"is_admin": false,
"is_active": true,
"is_sso": false,
"has_data": true
},
{
"username": "user2",
"name": "Bob Chen",
"is_admin": false,
"is_active": false,
"is_sso": true,
"has_data": false
}
]

View File

@@ -0,0 +1,20 @@
/**
* MSW handlers for current user account endpoints.
* @module mocks/handlers/account
*/
import { http, HttpResponse } from "msw";
import myAccountData from "../fixtures/my-account.json";
import { captureRequest } from "../request-log.js";
export const accountHandlers = [
http.get("/api/my-account", ({ request }) => {
captureRequest("GET", "/api/my-account");
return HttpResponse.json(myAccountData);
}),
http.put("/api/my-account", async ({ request }) => {
const body = await request.json();
captureRequest("PUT", "/api/my-account", body);
return HttpResponse.json({ success: true });
}),
];

View File

@@ -0,0 +1,15 @@
/**
* MSW handlers for authentication endpoints.
* @module mocks/handlers/auth
*/
import { http, HttpResponse } from "msw";
import tokenData from "../fixtures/token.json";
import { captureRequest } from "../request-log.js";
export const authHandlers = [
http.post("/api/oauth/token", async ({ request }) => {
const body = await request.text();
captureRequest("POST", "/api/oauth/token", body);
return HttpResponse.json(tokenData);
}),
];

View File

@@ -0,0 +1,14 @@
/**
* MSW handlers for comparison dashboard endpoints.
* @module mocks/handlers/compare
*/
import { http, HttpResponse } from "msw";
import compareData from "../fixtures/compare.json";
import { captureRequest } from "../request-log.js";
export const compareHandlers = [
http.get("/api/compare", ({ request }) => {
captureRequest("GET", "/api/compare");
return HttpResponse.json(compareData);
}),
];

View File

@@ -0,0 +1,19 @@
/**
* MSW handlers for conformance check parameter endpoints.
* @module mocks/handlers/conformance
*/
import { http, HttpResponse } from "msw";
import filterParamsData from "../fixtures/filter-params.json";
import { captureRequest } from "../request-log.js";
export const conformanceHandlers = [
http.get("/api/log-checks/params*", ({ request }) => {
captureRequest("GET", new URL(request.url).pathname);
return HttpResponse.json(filterParamsData);
}),
http.get("/api/filter-checks/params*", ({ request }) => {
captureRequest("GET", new URL(request.url).pathname);
return HttpResponse.json(filterParamsData);
}),
];

View File

@@ -0,0 +1,24 @@
/**
* MSW handlers for process discovery (map) endpoints.
* @module mocks/handlers/discover
*/
import { http, HttpResponse } from "msw";
import discoverData from "../fixtures/discover.json";
import { captureRequest } from "../request-log.js";
export const discoverHandlers = [
http.get("/api/logs/:id/discover", ({ params }) => {
captureRequest("GET", `/api/logs/${params.id}/discover`);
return HttpResponse.json(discoverData);
}),
http.get("/api/filters/:id/discover", ({ params }) => {
captureRequest("GET", `/api/filters/${params.id}/discover`);
return HttpResponse.json(discoverData);
}),
http.get("/api/temp-filters/:id/discover", ({ params }) => {
captureRequest("GET", `/api/temp-filters/${params.id}/discover`);
return HttpResponse.json(discoverData);
}),
];

View File

@@ -0,0 +1,14 @@
/**
* MSW handlers for file management endpoints.
* @module mocks/handlers/files
*/
import { http, HttpResponse } from "msw";
import filesData from "../fixtures/files.json";
import { captureRequest } from "../request-log.js";
export const filesHandlers = [
http.get("/api/files", ({ request }) => {
captureRequest("GET", "/api/files");
return HttpResponse.json(filesData);
}),
];

View File

@@ -0,0 +1,27 @@
/**
* Combined MSW request handlers for all API endpoints.
* @module mocks/handlers
*/
import { authHandlers } from "./auth.js";
import { accountHandlers } from "./account.js";
import { usersHandlers } from "./users.js";
import { filesHandlers } from "./files.js";
import { discoverHandlers } from "./discover.js";
import { performanceHandlers } from "./performance.js";
import { tracesHandlers } from "./traces.js";
import { conformanceHandlers } from "./conformance.js";
import { compareHandlers } from "./compare.js";
import { operationsHandlers } from "./operations.js";
export const handlers = [
...authHandlers,
...accountHandlers,
...usersHandlers,
...filesHandlers,
...discoverHandlers,
...performanceHandlers,
...tracesHandlers,
...conformanceHandlers,
...compareHandlers,
...operationsHandlers,
];

View File

@@ -0,0 +1,70 @@
/**
* MSW handlers for filter detail, filter params, dependents,
* rename, and deletion endpoints.
* @module mocks/handlers/operations
*/
import { http, HttpResponse } from "msw";
import { captureRequest } from "../request-log.js";
export const operationsHandlers = [
// Filter detail
http.get("/api/filters/:id", ({ params }) => {
captureRequest("GET", `/api/filters/${params.id}`);
return HttpResponse.json({
rules: [],
log: { id: 1 },
name: "filtered-sample",
});
}),
// Filter params and has-result
http.get("/api/filters/params*", ({ request }) => {
captureRequest("GET", new URL(request.url).pathname);
return HttpResponse.json({});
}),
http.get("/api/filters/has-result*", ({ request }) => {
captureRequest("GET", new URL(request.url).pathname);
return HttpResponse.json(false);
}),
// Dependents
http.get("/api/logs/:id/dependents", ({ params }) => {
captureRequest("GET", `/api/logs/${params.id}/dependents`);
return HttpResponse.json([]);
}),
http.get("/api/filters/:id/dependents", ({ params }) => {
captureRequest("GET", `/api/filters/${params.id}/dependents`);
return HttpResponse.json([]);
}),
http.get("/api/log-checks/:id/dependents", ({ params }) => {
captureRequest("GET", `/api/log-checks/${params.id}/dependents`);
return HttpResponse.json([]);
}),
http.get("/api/filter-checks/:id/dependents", ({ params }) => {
captureRequest("GET", `/api/filter-checks/${params.id}/dependents`);
return HttpResponse.json([]);
}),
// Rename
http.put("/api/logs/:id/rename", async ({ request, params }) => {
const body = await request.json();
captureRequest("PUT", `/api/logs/${params.id}/rename`, body);
return HttpResponse.json({ success: true });
}),
http.put("/api/filters/:id/rename", async ({ request, params }) => {
const body = await request.json();
captureRequest("PUT", `/api/filters/${params.id}/rename`, body);
return HttpResponse.json({ success: true });
}),
// Deletion
http.delete("/api/deletion/:id", ({ params }) => {
captureRequest("DELETE", `/api/deletion/${params.id}`);
return HttpResponse.json({ success: true });
}),
];

View File

@@ -0,0 +1,19 @@
/**
* MSW handlers for performance metrics endpoints.
* @module mocks/handlers/performance
*/
import { http, HttpResponse } from "msw";
import performanceData from "../fixtures/performance.json";
import { captureRequest } from "../request-log.js";
export const performanceHandlers = [
http.get("/api/logs/:id/performance", ({ params }) => {
captureRequest("GET", `/api/logs/${params.id}/performance`);
return HttpResponse.json(performanceData);
}),
http.get("/api/filters/:id/performance", ({ params }) => {
captureRequest("GET", `/api/filters/${params.id}/performance`);
return HttpResponse.json(performanceData);
}),
];

View File

@@ -0,0 +1,35 @@
/**
* MSW handlers for trace list and detail endpoints.
* @module mocks/handlers/traces
*/
import { http, HttpResponse } from "msw";
import tracesData from "../fixtures/traces.json";
import traceDetailData from "../fixtures/trace-detail.json";
import { captureRequest } from "../request-log.js";
export const tracesHandlers = [
http.get("/api/logs/:logId/traces/:traceId", ({ params }) => {
captureRequest("GET", `/api/logs/${params.logId}/traces/${params.traceId}`);
return HttpResponse.json(traceDetailData);
}),
http.get("/api/filters/:filterId/traces/:traceId", ({ params }) => {
captureRequest("GET", `/api/filters/${params.filterId}/traces/${params.traceId}`);
return HttpResponse.json(traceDetailData);
}),
http.get("/api/logs/:id/traces", ({ params }) => {
captureRequest("GET", `/api/logs/${params.id}/traces`);
return HttpResponse.json(tracesData);
}),
http.get("/api/filters/:id/traces", ({ params }) => {
captureRequest("GET", `/api/filters/${params.id}/traces`);
return HttpResponse.json(tracesData);
}),
http.get("/api/temp-filters/:id/traces", ({ params }) => {
captureRequest("GET", `/api/temp-filters/${params.id}/traces`);
return HttpResponse.json(tracesData);
}),
];

View File

@@ -0,0 +1,49 @@
/**
* MSW handlers for user management (account admin) endpoints.
* @module mocks/handlers/users
*/
import { http, HttpResponse } from "msw";
import usersData from "../fixtures/users.json";
import userDetailData from "../fixtures/user-detail.json";
import { captureRequest } from "../request-log.js";
export const usersHandlers = [
http.get("/api/users", ({ request }) => {
captureRequest("GET", "/api/users");
return HttpResponse.json(usersData);
}),
http.post("/api/users", async ({ request }) => {
const body = await request.json();
captureRequest("POST", "/api/users", body);
return HttpResponse.json({ success: true });
}),
// User roles (must be before /api/users/:username to match first)
http.put("/api/users/:username/roles/:role", async ({ request, params }) => {
captureRequest("PUT", `/api/users/${params.username}/roles/${params.role}`);
return HttpResponse.json({ success: true });
}),
http.delete("/api/users/:username/roles/:role", ({ request, params }) => {
captureRequest("DELETE", `/api/users/${params.username}/roles/${params.role}`);
return HttpResponse.json({ success: true });
}),
// User CRUD (after roles so roles match first)
http.get("/api/users/:username", ({ request, params }) => {
captureRequest("GET", `/api/users/${params.username}`);
return HttpResponse.json(userDetailData);
}),
http.put("/api/users/:username", async ({ request, params }) => {
const body = await request.json();
captureRequest("PUT", `/api/users/${params.username}`, body);
return HttpResponse.json({ success: true });
}),
http.delete("/api/users/:username", ({ request, params }) => {
captureRequest("DELETE", `/api/users/${params.username}`);
return HttpResponse.json({ success: true });
}),
];

8
src/mocks/node.js Normal file
View File

@@ -0,0 +1,8 @@
/**
* MSW server for Node.js (Vitest).
* @module mocks/node
*/
import { setupServer } from "msw/node";
import { handlers } from "./handlers/index.js";
export const server = setupServer(...handlers);

48
src/mocks/request-log.js Normal file
View File

@@ -0,0 +1,48 @@
/**
* Request logging utility for MSW handlers.
* Captures request details for test assertions,
* replacing vi.fn() call verification.
* @module mocks/request-log
*/
/** @type {Array<{method: string, url: string, body: any}>} */
let log = [];
/**
* Records a request in the log. Called from MSW handlers.
* @param {string} method - HTTP method.
* @param {string} url - Request URL path.
* @param {any} [body] - Parsed request body.
*/
export function captureRequest(method, url, body = undefined) {
log.push({ method, url, body });
}
/**
* Returns a copy of all logged requests.
* @returns {Array<{method: string, url: string, body: any}>}
*/
export function getRequests() {
return [...log];
}
/**
* Clears the request log. Call in afterEach.
*/
export function clearRequests() {
log = [];
}
/**
* Finds logged requests matching the given method and URL pattern.
* @param {string} method - HTTP method to match.
* @param {string|RegExp} urlPattern - URL string or regex to match.
* @returns {Array<{method: string, url: string, body: any}>}
*/
export function findRequest(method, urlPattern) {
return log.filter((r) => {
if (r.method !== method) return false;
if (typeof urlPattern === "string") return r.url === urlPattern;
return urlPattern.test(r.url);
});
}