-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathvalidator-query.mock.ts
64 lines (63 loc) · 1.34 KB
/
validator-query.mock.ts
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
import { defineMock } from 'vite-plugin-mock-dev-server'
export default defineMock([
// match /api/post?id=1000
{
url: '/api/post',
validator: {
query: { id: '1000' },
},
body: {
code: 200,
message: 'success',
result: {
id: '1000',
title: 'post-1000',
content: 'post-1000 content',
author: 'Mark',
},
},
},
{
url: '/api/post',
validator: {
query: { id: '1001' },
},
body: {
code: 200,
message: 'success',
result: {
id: '1001',
title: 'post-1001',
content: 'post-1001 content',
author: 'John',
},
},
},
{
// match query include field `id` and value is 1003
// like {url: '/api/post', validator: { query: { id: '1003' } }}
url: '/api/post?id=1003',
body: {
code: 200,
message: 'success',
result: {
id: '1003',
title: 'post-1003',
content: 'post-1003 content',
author: 'Joy',
},
},
},
// Fallback, when the validator does not have a matching result, will use the configuration without validators as the response.
{
url: '/api/post',
body: {
code: 200,
message: 'success',
result: {
id: 1000 + Math.floor(Math.random() * 1000),
title: 'random post title',
},
},
},
])