@@ -5,7 +5,7 @@ import { copyAsset } from './scripts/copyAsset';
55import { generateClient } from './scripts/generateClient' ;
66import server from './scripts/server' ;
77
8- describe ( 'v3 .babel' , ( ) => {
8+ describe ( 'client .babel' , ( ) => {
99 beforeAll ( async ( ) => {
1010 cleanup ( 'client/babel' ) ;
1111 await generateClient ( 'client/babel' , 'v3' , 'fetch' , true , true , 'AppClient' ) ;
@@ -53,13 +53,123 @@ describe('v3.babel', () => {
5353 const { AppClient } = ( window as any ) . api ;
5454 const client = new AppClient ( ) ;
5555 return await client . complex . complexTypes ( {
56- first : {
57- second : {
58- third : 'Hello World!' ,
56+ parameterObject : {
57+ first : {
58+ second : {
59+ third : 'Hello World!' ,
60+ } ,
5961 } ,
6062 } ,
6163 } ) ;
6264 } ) ;
6365 expect ( result ) . toBeDefined ( ) ;
6466 } ) ;
67+
68+ it ( 'support form data' , async ( ) => {
69+ const result = await browser . evaluate ( async ( ) => {
70+ const { AppClient } = ( window as any ) . api ;
71+ const client = new AppClient ( ) ;
72+ return await client . parameters . callWithParameters ( {
73+ parameterHeader : 'valueHeader' ,
74+ parameterQuery : 'valueQuery' ,
75+ parameterForm : 'valueForm' ,
76+ parameterCookie : 'valueCookie' ,
77+ parameterPath : 'valuePath' ,
78+ requestBody : {
79+ prop : 'valueBody' ,
80+ } ,
81+ } ) ;
82+ } ) ;
83+ expect ( result ) . toBeDefined ( ) ;
84+ } ) ;
85+
86+ it ( 'can abort the request' , async ( ) => {
87+ let error ;
88+ try {
89+ await browser . evaluate ( async ( ) => {
90+ const { AppClient } = ( window as any ) . api ;
91+ const client = new AppClient ( ) ;
92+ const promise = client . simple . getCallWithoutParametersAndResponse ( ) ;
93+ setTimeout ( ( ) => {
94+ promise . cancel ( ) ;
95+ } , 10 ) ;
96+ await promise ;
97+ } ) ;
98+ } catch ( e ) {
99+ error = ( e as Error ) . message ;
100+ }
101+ expect ( error ) . toContain ( 'CancelError: Request aborted' ) ;
102+ } ) ;
103+
104+ it ( 'should throw known error (500)' , async ( ) => {
105+ const error = await browser . evaluate ( async ( ) => {
106+ try {
107+ const { AppClient } = ( window as any ) . api ;
108+ const client = new AppClient ( ) ;
109+ await client . error . testErrorCode ( {
110+ status : 500 ,
111+ } ) ;
112+ } catch ( e ) {
113+ const error = e as any ;
114+ return JSON . stringify ( {
115+ name : error . name ,
116+ message : error . message ,
117+ url : error . url ,
118+ status : error . status ,
119+ statusText : error . statusText ,
120+ body : error . body ,
121+ } ) ;
122+ }
123+ return ;
124+ } ) ;
125+ expect ( error ) . toBe (
126+ JSON . stringify ( {
127+ name : 'ApiError' ,
128+ message : 'Custom message: Internal Server Error' ,
129+ url : 'http://localhost:3000/base/api/v1.0/error?status=500' ,
130+ status : 500 ,
131+ statusText : 'Internal Server Error' ,
132+ body : {
133+ status : 500 ,
134+ message : 'hello world' ,
135+ } ,
136+ } )
137+ ) ;
138+ } ) ;
139+
140+ it ( 'should throw unknown error (409)' , async ( ) => {
141+ const error = await browser . evaluate ( async ( ) => {
142+ try {
143+ const { AppClient } = ( window as any ) . api ;
144+ const client = new AppClient ( ) ;
145+ await client . error . testErrorCode ( {
146+ status : 409 ,
147+ } ) ;
148+ } catch ( e ) {
149+ const error = e as any ;
150+ return JSON . stringify ( {
151+ name : error . name ,
152+ message : error . message ,
153+ url : error . url ,
154+ status : error . status ,
155+ statusText : error . statusText ,
156+ body : error . body ,
157+ } ) ;
158+ }
159+ return ;
160+ } ) ;
161+ expect ( error ) . toBe (
162+ JSON . stringify ( {
163+ name : 'ApiError' ,
164+ message : 'Generic Error' ,
165+ url : 'http://localhost:3000/base/api/v1.0/error?status=409' ,
166+ status : 409 ,
167+ statusText : 'Conflict' ,
168+ body : {
169+ status : 409 ,
170+ message : 'hello world' ,
171+ } ,
172+ } )
173+ ) ;
174+ } ) ;
65175} ) ;
0 commit comments