1
- import 'mocha'
2
- import { assert } from 'chai'
1
+ import 'jest'
3
2
import { nanoid } from 'nanoid'
4
3
import { sign } from 'jsonwebtoken'
5
- import { ContentType } from 'allure2 -js-commons'
4
+ import { ContentType } from 'allure -js-commons'
6
5
7
6
import { FunctionsClient } from '../../src/index'
8
7
9
8
import { Relay , runRelay } from '../relay/container'
10
- import { attach , log } from '../utils/allure '
9
+ import { attach , log } from '../utils/jest-custom-reporter '
11
10
import { getCustomFetch } from '../utils/fetch'
12
11
13
12
describe ( 'basic tests (hello function)' , ( ) => {
14
13
let relay : Relay
15
14
const jwtSecret = nanoid ( 10 )
16
15
const apiKey = sign ( { name : 'anon' } , jwtSecret )
17
16
18
- before ( async ( ) => {
17
+ beforeAll ( async ( ) => {
19
18
relay = await runRelay ( 'hello' , jwtSecret )
20
19
} )
21
20
22
- after ( async ( ) => {
21
+ afterAll ( async ( ) => {
23
22
relay && relay . container && ( await relay . container . stop ( ) )
24
23
} )
25
24
26
- it ( 'invoke hello with auth header' , async ( ) => {
25
+ test ( 'invoke hello with auth header' , async ( ) => {
26
+ /**
27
+ * @feature auth
28
+ */
27
29
log ( 'create FunctionsClient' )
28
30
const fclient = new FunctionsClient ( `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` , {
29
31
Authorization : `Bearer ${ apiKey } ` ,
@@ -33,12 +35,15 @@ describe('basic tests (hello function)', () => {
33
35
const { data, error } = await fclient . invoke < string > ( 'hello' , { responseType : 'text' } )
34
36
35
37
log ( 'assert no error' )
36
- assert . isNull ( error )
38
+ expect ( error ) . toBeNull ( )
37
39
log ( `assert ${ data } is equal to 'Hello World'` )
38
- assert . equal ( data , 'Hello World' )
40
+ expect ( data ) . toEqual ( 'Hello World' )
39
41
} )
40
42
41
- it ( 'invoke hello with setAuth' , async ( ) => {
43
+ test ( 'invoke hello with setAuth' , async ( ) => {
44
+ /**
45
+ * @feature auth
46
+ */
42
47
log ( 'create FunctionsClient' )
43
48
const fclient = new FunctionsClient ( `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` )
44
49
attach ( 'setAuth' , apiKey , ContentType . TEXT )
@@ -48,12 +53,15 @@ describe('basic tests (hello function)', () => {
48
53
const { data, error } = await fclient . invoke < string > ( 'hello' , { responseType : 'text' } )
49
54
50
55
log ( 'assert no error' )
51
- assert . isNull ( error )
56
+ expect ( error ) . toBeNull ( )
52
57
log ( `assert ${ data } is equal to 'Hello World'` )
53
- assert . equal ( data , 'Hello World' )
58
+ expect ( data ) . toEqual ( 'Hello World' )
54
59
} )
55
60
56
- it ( 'invoke hello with setAuth wrong key' , async ( ) => {
61
+ test ( 'invoke hello with setAuth wrong key' , async ( ) => {
62
+ /**
63
+ * @feature errors
64
+ */
57
65
log ( 'create FunctionsClient' )
58
66
const fclient = new FunctionsClient ( `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` )
59
67
const wrongKey = sign ( { name : 'anon' } , 'wrong_jwt' )
@@ -64,12 +72,15 @@ describe('basic tests (hello function)', () => {
64
72
const { data, error } = await fclient . invoke < string > ( 'hello' , { responseType : 'text' } )
65
73
66
74
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 ( )
70
78
} )
71
79
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
+ */
73
84
log ( 'create FunctionsClient' )
74
85
const fclient = new FunctionsClient ( `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` , {
75
86
Authorization : `Bearer ${ apiKey } ` ,
@@ -82,12 +93,15 @@ describe('basic tests (hello function)', () => {
82
93
const { data, error } = await fclient . invoke < string > ( 'hello' , { responseType : 'text' } )
83
94
84
95
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 ( )
88
99
} )
89
100
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
+ */
91
105
const wrongKey = sign ( { name : 'anon' } , 'wrong_jwt' )
92
106
93
107
log ( 'create FunctionsClient with wrong jwt' )
@@ -102,12 +116,15 @@ describe('basic tests (hello function)', () => {
102
116
const { data, error } = await fclient . invoke < string > ( 'hello' , { responseType : 'text' } )
103
117
104
118
log ( 'assert no error' )
105
- assert . isNull ( error )
119
+ expect ( error ) . toBeNull ( )
106
120
log ( `assert ${ data } is equal to 'Hello World'` )
107
- assert . equal ( data , 'Hello World' )
121
+ expect ( data ) . toEqual ( 'Hello World' )
108
122
} )
109
123
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
+ */
111
128
log ( 'create FunctionsClient' )
112
129
const fclient = new FunctionsClient ( `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` )
113
130
@@ -120,12 +137,15 @@ describe('basic tests (hello function)', () => {
120
137
} )
121
138
122
139
log ( 'assert no error' )
123
- assert . isNull ( error )
140
+ expect ( error ) . toBeNull ( )
124
141
log ( `assert ${ data } is equal to 'Hello World'` )
125
- assert . equal ( data , 'Hello World' )
142
+ expect ( data ) . toEqual ( 'Hello World' )
126
143
} )
127
144
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
+ */
129
149
log ( 'create FunctionsClient with wrong jwt' )
130
150
const fclient = new FunctionsClient ( `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` )
131
151
@@ -142,12 +162,15 @@ describe('basic tests (hello function)', () => {
142
162
} )
143
163
144
164
log ( 'assert no error' )
145
- assert . isNull ( error )
165
+ expect ( error ) . toBeNull ( )
146
166
log ( `assert ${ data } is equal to 'Hello World'` )
147
- assert . equal ( data , 'Hello World' )
167
+ expect ( data ) . toEqual ( 'Hello World' )
148
168
} )
149
169
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
+ */
151
174
log ( 'create FunctionsClient with wrong jwt' )
152
175
const fclient = new FunctionsClient ( `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` , {
153
176
Authorization : `Bearer ${ apiKey } ` ,
@@ -163,12 +186,15 @@ describe('basic tests (hello function)', () => {
163
186
} )
164
187
165
188
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 ( )
169
192
} )
170
193
171
194
it . skip ( 'invoke missing function' , async ( ) => {
195
+ /**
196
+ * @feature errors
197
+ */
172
198
log ( 'create FunctionsClient' )
173
199
const fclient = new FunctionsClient ( `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` , {
174
200
Authorization : `Bearer ${ apiKey } ` ,
@@ -178,12 +204,15 @@ describe('basic tests (hello function)', () => {
178
204
const { data, error } = await fclient . invoke < string > ( 'missing' , { responseType : 'text' } )
179
205
180
206
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 ( )
184
210
} )
185
211
186
- it ( 'invoke with custom fetch' , async ( ) => {
212
+ test ( 'invoke with custom fetch' , async ( ) => {
213
+ /**
214
+ * @feature fetch
215
+ */
187
216
log ( 'create FunctionsClient' )
188
217
const fclient = new FunctionsClient (
189
218
`http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` ,
@@ -200,12 +229,15 @@ describe('basic tests (hello function)', () => {
200
229
const { data, error } = await fclient . invoke < string > ( '' , { responseType : 'text' } )
201
230
202
231
log ( 'assert no error' )
203
- assert . isNull ( error )
232
+ expect ( error ) . toBeNull ( )
204
233
log ( `assert ${ data } is equal to 'Hello World'` )
205
- assert . equal ( data , 'Hello World' )
234
+ expect ( data ) . toEqual ( 'Hello World' )
206
235
} )
207
236
208
- it ( 'invoke with custom fetch wrong method' , async ( ) => {
237
+ test ( 'invoke with custom fetch wrong method' , async ( ) => {
238
+ /**
239
+ * @feature fetch
240
+ */
209
241
log ( 'create FunctionsClient' )
210
242
const fclient = new FunctionsClient (
211
243
`http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` ,
@@ -222,13 +254,16 @@ describe('basic tests (hello function)', () => {
222
254
const { data, error } = await fclient . invoke < string > ( '' , { responseType : 'text' } )
223
255
224
256
log ( 'check error' )
225
- assert . isNotNull ( error )
257
+ expect ( error ) . not . toBeNull ( )
226
258
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 ( )
229
261
} )
230
262
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
+ */
232
267
const wrongKey = sign ( { name : 'anon' } , 'wrong_jwt' )
233
268
log ( 'create FunctionsClient' )
234
269
const fclient = new FunctionsClient (
@@ -250,8 +285,8 @@ describe('basic tests (hello function)', () => {
250
285
} )
251
286
252
287
log ( 'assert no error' )
253
- assert . isNull ( error )
288
+ expect ( error ) . toBeNull ( )
254
289
log ( `assert ${ data } is equal to 'Hello World'` )
255
- assert . equal ( data , 'Hello World' )
290
+ expect ( data ) . toEqual ( 'Hello World' )
256
291
} )
257
292
} )
0 commit comments