@@ -11,7 +11,7 @@ describe('OpenAPI server tests', () => {
11
11
12
12
let r = await handleRequest ( {
13
13
method : 'get' ,
14
- path : '/api/ post/findMany' ,
14
+ path : '/post/findMany' ,
15
15
prisma,
16
16
zodSchemas,
17
17
} ) ;
@@ -20,7 +20,7 @@ describe('OpenAPI server tests', () => {
20
20
21
21
r = await handleRequest ( {
22
22
method : 'post' ,
23
- path : '/api/ user/create' ,
23
+ path : '/user/create' ,
24
24
query : { } ,
25
25
requestBody : {
26
26
include : { posts : true } ,
@@ -56,7 +56,7 @@ describe('OpenAPI server tests', () => {
56
56
57
57
r = await handleRequest ( {
58
58
method : 'get' ,
59
- path : '/api/ post/findMany' ,
59
+ path : '/post/findMany' ,
60
60
prisma,
61
61
zodSchemas,
62
62
} ) ;
@@ -65,7 +65,7 @@ describe('OpenAPI server tests', () => {
65
65
66
66
r = await handleRequest ( {
67
67
method : 'get' ,
68
- path : '/api/ post/findMany' ,
68
+ path : '/post/findMany' ,
69
69
query : { q : JSON . stringify ( { where : { viewCount : { gt : 1 } } } ) } ,
70
70
prisma,
71
71
zodSchemas,
@@ -75,7 +75,7 @@ describe('OpenAPI server tests', () => {
75
75
76
76
r = await handleRequest ( {
77
77
method : 'put' ,
78
- path : '/api/ user/update' ,
78
+ path : '/user/update' ,
79
79
requestBody : { where : { id : 'user1' } , data : { email : 'user1@def.com' } } ,
80
80
prisma,
81
81
zodSchemas,
@@ -85,7 +85,7 @@ describe('OpenAPI server tests', () => {
85
85
86
86
r = await handleRequest ( {
87
87
method : 'get' ,
88
- path : '/api/ post/count' ,
88
+ path : '/post/count' ,
89
89
query : { q : JSON . stringify ( { where : { viewCount : { gt : 1 } } } ) } ,
90
90
prisma,
91
91
zodSchemas,
@@ -95,7 +95,7 @@ describe('OpenAPI server tests', () => {
95
95
96
96
r = await handleRequest ( {
97
97
method : 'get' ,
98
- path : '/api/ post/aggregate' ,
98
+ path : '/post/aggregate' ,
99
99
query : { q : JSON . stringify ( { _sum : { viewCount : true } } ) } ,
100
100
prisma,
101
101
zodSchemas,
@@ -105,7 +105,7 @@ describe('OpenAPI server tests', () => {
105
105
106
106
r = await handleRequest ( {
107
107
method : 'get' ,
108
- path : '/api/ post/groupBy' ,
108
+ path : '/post/groupBy' ,
109
109
query : { q : JSON . stringify ( { by : [ 'published' ] , _sum : { viewCount : true } } ) } ,
110
110
prisma,
111
111
zodSchemas,
@@ -120,7 +120,7 @@ describe('OpenAPI server tests', () => {
120
120
121
121
r = await handleRequest ( {
122
122
method : 'delete' ,
123
- path : '/api/ user/deleteMany' ,
123
+ path : '/user/deleteMany' ,
124
124
query : { q : JSON . stringify ( { where : { id : 'user1' } } ) } ,
125
125
prisma,
126
126
zodSchemas,
@@ -135,14 +135,14 @@ describe('OpenAPI server tests', () => {
135
135
// without validation
136
136
let r = await handleRequest ( {
137
137
method : 'get' ,
138
- path : '/api/ post/findUnique' ,
138
+ path : '/post/findUnique' ,
139
139
prisma,
140
140
} ) ;
141
141
expect ( r . status ) . toBe ( 400 ) ;
142
142
143
143
r = await handleRequest ( {
144
144
method : 'get' ,
145
- path : '/api/ post/findUnique' ,
145
+ path : '/post/findUnique' ,
146
146
prisma,
147
147
zodSchemas,
148
148
} ) ;
@@ -152,7 +152,7 @@ describe('OpenAPI server tests', () => {
152
152
153
153
r = await handleRequest ( {
154
154
method : 'post' ,
155
- path : '/api/ post/create' ,
155
+ path : '/post/create' ,
156
156
requestBody : { data : { } } ,
157
157
prisma,
158
158
zodSchemas,
@@ -161,4 +161,42 @@ describe('OpenAPI server tests', () => {
161
161
expect ( ( r . body as any ) . message ) . toContain ( 'Validation error' ) ;
162
162
expect ( ( r . body as any ) . message ) . toContain ( 'data.title' ) ;
163
163
} ) ;
164
+
165
+ it ( 'invalid path or args' , async ( ) => {
166
+ const { prisma } = await loadSchema ( schema ) ;
167
+
168
+ let r = await handleRequest ( {
169
+ method : 'get' ,
170
+ path : '/post/' ,
171
+ prisma,
172
+ } ) ;
173
+ expect ( r . status ) . toBe ( 400 ) ;
174
+ expect ( ( r . body as any ) . message ) . toContain ( 'invalid request path' ) ;
175
+
176
+ r = await handleRequest ( {
177
+ method : 'get' ,
178
+ path : '/post/findMany/abc' ,
179
+ prisma,
180
+ } ) ;
181
+ expect ( r . status ) . toBe ( 400 ) ;
182
+ expect ( ( r . body as any ) . message ) . toContain ( 'invalid request path' ) ;
183
+
184
+ r = await handleRequest ( {
185
+ method : 'get' ,
186
+ path : '/post/findUnique' ,
187
+ query : { q : 'abc' } ,
188
+ prisma,
189
+ } ) ;
190
+ expect ( r . status ) . toBe ( 400 ) ;
191
+ expect ( ( r . body as any ) . message ) . toContain ( 'query param must contain valid JSON' ) ;
192
+
193
+ r = await handleRequest ( {
194
+ method : 'delete' ,
195
+ path : '/post/deleteMany' ,
196
+ query : { q : 'abc' } ,
197
+ prisma,
198
+ } ) ;
199
+ expect ( r . status ) . toBe ( 400 ) ;
200
+ expect ( ( r . body as any ) . message ) . toContain ( 'query param must contain valid JSON' ) ;
201
+ } ) ;
164
202
} ) ;
0 commit comments