@@ -316,5 +316,66 @@ test.describe('API - ValidationRequest', () => {
316
316
expect ( response . statusText ( ) ) . toBe ( 'Unauthorized' ) ;
317
317
expect ( response . status ( ) ) . toBe ( 401 ) ;
318
318
} ) ;
319
+ } ) ;
320
+
321
+ test . describe ( 'API - Browsers vs Clients' , ( ) => {
322
+
323
+ test ( 'Browsers will be redirected to /api/swagger-ui' , async ( { request } ) => {
324
+
325
+ // root of /api
326
+ const response = await request . get ( `${ BASE_URL } /api/` , {
327
+ headers : {
328
+ 'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8'
329
+ } ,
330
+ maxRedirects : 0
331
+ } ) ;
332
+
333
+ // check if the response is correct - 302 Found
334
+ expect ( response . statusText ( ) ) . toBe ( 'Found' ) ;
335
+ expect ( response . status ( ) ) . toBe ( 302 ) ;
336
+ expect ( response . headers ( ) [ 'location' ] ) . toBe ( '/api/swagger-ui/' ) ;
337
+ } ) ;
338
+
339
+ test ( 'Browsers are redirected to /api/swagger-ui' , async ( { request } ) => {
340
+
341
+ // root of /api
342
+ const response = await request . get ( `${ BASE_URL } /api/` , {
343
+ headers : {
344
+ 'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8'
345
+ } ,
346
+ maxRedirects : 5
347
+ } ) ;
348
+
349
+ // check if the response is correct - 200 OK
350
+ expect ( response . statusText ( ) ) . toBe ( 'OK' ) ;
351
+ expect ( response . status ( ) ) . toBe ( 200 ) ;
352
+ expect ( response . url ( ) ) . toBe ( `${ BASE_URL } /api/swagger-ui/` ) ;
353
+ } ) ;
354
+
355
+ test ( 'API clients will be redirected to /api/schema' , async ( { request } ) => {
356
+
357
+ // root of /api
358
+ const response = await request . get ( `${ BASE_URL } /api/` , {
359
+ maxRedirects : 0
360
+ } ) ;
361
+
362
+ // check if the response is correct - 302 Found
363
+ expect ( response . statusText ( ) ) . toBe ( 'Found' ) ;
364
+ expect ( response . status ( ) ) . toBe ( 302 ) ;
365
+ expect ( response . headers ( ) [ 'location' ] ) . toBe ( '/api/schema/' ) ;
366
+ } ) ;
367
+
368
+ test ( 'API clients are redirected to /api/schema' , async ( { request } ) => {
369
+
370
+ // root of /api
371
+ const response = await request . get ( `${ BASE_URL } /api/` , {
372
+ maxRedirects : 5
373
+ } ) ;
374
+
375
+ // check if the response is correct - 200 OK
376
+ expect ( response . statusText ( ) ) . toBe ( 'OK' ) ;
377
+ expect ( response . status ( ) ) . toBe ( 200 ) ;
378
+ expect ( response . url ( ) ) . toBe ( `${ BASE_URL } /api/schema/` ) ;
379
+ } ) ;
319
380
320
381
} ) ;
0 commit comments