1- import 'mocha'
2- import { assert } from 'chai'
1+ import 'jest'
32import { nanoid } from 'nanoid'
43import { sign } from 'jsonwebtoken'
5- import { ContentType } from 'allure2 -js-commons'
4+ import { ContentType } from 'allure -js-commons'
65
76import { FunctionsClient } from '../../src/index'
87
98import { Relay , runRelay } from '../relay/container'
10- import { attach , log } from '../utils/allure '
9+ import { attach , log } from '../utils/jest-custom-reporter '
1110import { getCustomFetch } from '../utils/fetch'
1211
1312describe ( 'basic tests (hello function)' , ( ) => {
1413 let relay : Relay
1514 const jwtSecret = nanoid ( 10 )
1615 const apiKey = sign ( { name : 'anon' } , jwtSecret )
1716
18- before ( async ( ) => {
17+ beforeAll ( async ( ) => {
1918 relay = await runRelay ( 'hello' , jwtSecret )
2019 } )
2120
22- after ( async ( ) => {
21+ afterAll ( async ( ) => {
2322 relay && relay . container && ( await relay . container . stop ( ) )
2423 } )
2524
26- it ( 'invoke hello with auth header' , async ( ) => {
25+ test ( 'invoke hello with auth header' , async ( ) => {
26+ /**
27+ * @feature auth
28+ */
2729 log ( 'create FunctionsClient' )
2830 const fclient = new FunctionsClient ( `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` , {
2931 Authorization : `Bearer ${ apiKey } ` ,
@@ -33,12 +35,15 @@ describe('basic tests (hello function)', () => {
3335 const { data, error } = await fclient . invoke < string > ( 'hello' , { responseType : 'text' } )
3436
3537 log ( 'assert no error' )
36- assert . isNull ( error )
38+ expect ( error ) . toBeNull ( )
3739 log ( `assert ${ data } is equal to 'Hello World'` )
38- assert . equal ( data , 'Hello World' )
40+ expect ( data ) . toEqual ( 'Hello World' )
3941 } )
4042
41- it ( 'invoke hello with setAuth' , async ( ) => {
43+ test ( 'invoke hello with setAuth' , async ( ) => {
44+ /**
45+ * @feature auth
46+ */
4247 log ( 'create FunctionsClient' )
4348 const fclient = new FunctionsClient ( `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` )
4449 attach ( 'setAuth' , apiKey , ContentType . TEXT )
@@ -48,12 +53,15 @@ describe('basic tests (hello function)', () => {
4853 const { data, error } = await fclient . invoke < string > ( 'hello' , { responseType : 'text' } )
4954
5055 log ( 'assert no error' )
51- assert . isNull ( error )
56+ expect ( error ) . toBeNull ( )
5257 log ( `assert ${ data } is equal to 'Hello World'` )
53- assert . equal ( data , 'Hello World' )
58+ expect ( data ) . toEqual ( 'Hello World' )
5459 } )
5560
56- it ( 'invoke hello with setAuth wrong key' , async ( ) => {
61+ test ( 'invoke hello with setAuth wrong key' , async ( ) => {
62+ /**
63+ * @feature errors
64+ */
5765 log ( 'create FunctionsClient' )
5866 const fclient = new FunctionsClient ( `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` )
5967 const wrongKey = sign ( { name : 'anon' } , 'wrong_jwt' )
@@ -64,12 +72,15 @@ describe('basic tests (hello function)', () => {
6472 const { data, error } = await fclient . invoke < string > ( 'hello' , { responseType : 'text' } )
6573
6674 log ( 'check error' )
67- assert . isNotNull ( error )
68- assert . equal ( error ?. message , 'Invalid JWT' )
69- assert . isNull ( data )
75+ expect ( error ) . not . toBeNull ( )
76+ expect ( error ?. message ) . toEqual ( 'Invalid JWT' )
77+ expect ( data ) . toBeNull ( )
7078 } )
7179
72- it ( 'invoke hello: auth override by setAuth wrong key' , async ( ) => {
80+ test ( 'invoke hello: auth override by setAuth wrong key' , async ( ) => {
81+ /**
82+ * @feature auth
83+ */
7384 log ( 'create FunctionsClient' )
7485 const fclient = new FunctionsClient ( `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` , {
7586 Authorization : `Bearer ${ apiKey } ` ,
@@ -82,12 +93,15 @@ describe('basic tests (hello function)', () => {
8293 const { data, error } = await fclient . invoke < string > ( 'hello' , { responseType : 'text' } )
8394
8495 log ( 'check error' )
85- assert . isNotNull ( error )
86- assert . equal ( error ?. message , 'Invalid JWT' )
87- assert . isNull ( data )
96+ expect ( error ) . not . toBeNull ( )
97+ expect ( error ?. message ) . toEqual ( 'Invalid JWT' )
98+ expect ( data ) . toBeNull ( )
8899 } )
89100
90- it ( 'invoke hello: auth override by setAuth right key' , async ( ) => {
101+ test ( 'invoke hello: auth override by setAuth right key' , async ( ) => {
102+ /**
103+ * @feature auth
104+ */
91105 const wrongKey = sign ( { name : 'anon' } , 'wrong_jwt' )
92106
93107 log ( 'create FunctionsClient with wrong jwt' )
@@ -102,12 +116,15 @@ describe('basic tests (hello function)', () => {
102116 const { data, error } = await fclient . invoke < string > ( 'hello' , { responseType : 'text' } )
103117
104118 log ( 'assert no error' )
105- assert . isNull ( error )
119+ expect ( error ) . toBeNull ( )
106120 log ( `assert ${ data } is equal to 'Hello World'` )
107- assert . equal ( data , 'Hello World' )
121+ expect ( data ) . toEqual ( 'Hello World' )
108122 } )
109123
110- it ( 'invoke hello with auth header in invoke' , async ( ) => {
124+ test ( 'invoke hello with auth header in invoke' , async ( ) => {
125+ /**
126+ * @feature auth
127+ */
111128 log ( 'create FunctionsClient' )
112129 const fclient = new FunctionsClient ( `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` )
113130
@@ -120,12 +137,15 @@ describe('basic tests (hello function)', () => {
120137 } )
121138
122139 log ( 'assert no error' )
123- assert . isNull ( error )
140+ expect ( error ) . toBeNull ( )
124141 log ( `assert ${ data } is equal to 'Hello World'` )
125- assert . equal ( data , 'Hello World' )
142+ expect ( data ) . toEqual ( 'Hello World' )
126143 } )
127144
128- it ( 'invoke hello with auth header override in invoke' , async ( ) => {
145+ test ( 'invoke hello with auth header override in invoke' , async ( ) => {
146+ /**
147+ * @feature auth
148+ */
129149 log ( 'create FunctionsClient with wrong jwt' )
130150 const fclient = new FunctionsClient ( `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` )
131151
@@ -142,12 +162,15 @@ describe('basic tests (hello function)', () => {
142162 } )
143163
144164 log ( 'assert no error' )
145- assert . isNull ( error )
165+ expect ( error ) . toBeNull ( )
146166 log ( `assert ${ data } is equal to 'Hello World'` )
147- assert . equal ( data , 'Hello World' )
167+ expect ( data ) . toEqual ( 'Hello World' )
148168 } )
149169
150- it ( 'invoke hello with wrong auth header overridden in invoke' , async ( ) => {
170+ test ( 'invoke hello with wrong auth header overridden in invoke' , async ( ) => {
171+ /**
172+ * @feature auth
173+ */
151174 log ( 'create FunctionsClient with wrong jwt' )
152175 const fclient = new FunctionsClient ( `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` , {
153176 Authorization : `Bearer ${ apiKey } ` ,
@@ -163,12 +186,15 @@ describe('basic tests (hello function)', () => {
163186 } )
164187
165188 log ( 'check error' )
166- assert . isNotNull ( error )
167- assert . equal ( error ?. message , 'Invalid JWT' )
168- assert . isNull ( data )
189+ expect ( error ) . not . toBeNull ( )
190+ expect ( error ?. message ) . toEqual ( 'Invalid JWT' )
191+ expect ( data ) . toBeNull ( )
169192 } )
170193
171194 it . skip ( 'invoke missing function' , async ( ) => {
195+ /**
196+ * @feature errors
197+ */
172198 log ( 'create FunctionsClient' )
173199 const fclient = new FunctionsClient ( `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` , {
174200 Authorization : `Bearer ${ apiKey } ` ,
@@ -178,12 +204,15 @@ describe('basic tests (hello function)', () => {
178204 const { data, error } = await fclient . invoke < string > ( 'missing' , { responseType : 'text' } )
179205
180206 log ( 'check error' )
181- assert . isNotNull ( error )
182- assert . equal ( error ?. message , 'Invalid JWT' )
183- assert . isNull ( data )
207+ expect ( error ) . not . toBeNull ( )
208+ expect ( error ?. message ) . toEqual ( 'Invalid JWT' )
209+ expect ( data ) . toBeNull ( )
184210 } )
185211
186- it ( 'invoke with custom fetch' , async ( ) => {
212+ test ( 'invoke with custom fetch' , async ( ) => {
213+ /**
214+ * @feature fetch
215+ */
187216 log ( 'create FunctionsClient' )
188217 const fclient = new FunctionsClient (
189218 `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` ,
@@ -200,12 +229,15 @@ describe('basic tests (hello function)', () => {
200229 const { data, error } = await fclient . invoke < string > ( '' , { responseType : 'text' } )
201230
202231 log ( 'assert no error' )
203- assert . isNull ( error )
232+ expect ( error ) . toBeNull ( )
204233 log ( `assert ${ data } is equal to 'Hello World'` )
205- assert . equal ( data , 'Hello World' )
234+ expect ( data ) . toEqual ( 'Hello World' )
206235 } )
207236
208- it ( 'invoke with custom fetch wrong method' , async ( ) => {
237+ test ( 'invoke with custom fetch wrong method' , async ( ) => {
238+ /**
239+ * @feature fetch
240+ */
209241 log ( 'create FunctionsClient' )
210242 const fclient = new FunctionsClient (
211243 `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` ,
@@ -222,13 +254,16 @@ describe('basic tests (hello function)', () => {
222254 const { data, error } = await fclient . invoke < string > ( '' , { responseType : 'text' } )
223255
224256 log ( 'check error' )
225- assert . isNotNull ( error )
257+ expect ( error ) . not . toBeNull ( )
226258 log ( `assert ${ error ?. message } is equal to 'Only POST and OPTIONS requests are supported'` )
227- assert . equal ( error ?. message , 'Only POST and OPTIONS requests are supported' )
228- assert . isNull ( data )
259+ expect ( error ?. message ) . toEqual ( 'Only POST and OPTIONS requests are supported' )
260+ expect ( data ) . toBeNull ( )
229261 } )
230262
231- it ( 'invoke hello with custom fetch override header' , async ( ) => {
263+ test ( 'invoke hello with custom fetch override header' , async ( ) => {
264+ /**
265+ * @feature fetch
266+ */
232267 const wrongKey = sign ( { name : 'anon' } , 'wrong_jwt' )
233268 log ( 'create FunctionsClient' )
234269 const fclient = new FunctionsClient (
@@ -250,8 +285,8 @@ describe('basic tests (hello function)', () => {
250285 } )
251286
252287 log ( 'assert no error' )
253- assert . isNull ( error )
288+ expect ( error ) . toBeNull ( )
254289 log ( `assert ${ data } is equal to 'Hello World'` )
255- assert . equal ( data , 'Hello World' )
290+ expect ( data ) . toEqual ( 'Hello World' )
256291 } )
257292} )
0 commit comments