1
1
'use strict'
2
- import { Registry } from 'prom-client'
3
-
4
- import app from '../admin-app'
5
2
import dotenv from 'dotenv'
6
3
import * as migrate from '../utils/migrate'
7
4
import { knex } from '../utils/multitenant-db'
5
+ import { adminApp } from './common'
8
6
9
7
dotenv . config ( { path : '.env.test' } )
10
8
@@ -30,7 +28,7 @@ beforeAll(async () => {
30
28
} )
31
29
32
30
afterEach ( async ( ) => {
33
- await app ( { } , { register : new Registry ( ) } ) . inject ( {
31
+ await adminApp . inject ( {
34
32
method : 'DELETE' ,
35
33
url : '/tenants/abc' ,
36
34
headers : {
@@ -45,15 +43,15 @@ afterAll(async () => {
45
43
46
44
describe ( 'Tenant configs' , ( ) => {
47
45
test ( 'Get all tenant configs' , async ( ) => {
48
- await app ( { } , { register : new Registry ( ) } ) . inject ( {
46
+ await adminApp . inject ( {
49
47
method : 'POST' ,
50
48
url : `/tenants/abc` ,
51
49
payload,
52
50
headers : {
53
51
apikey : process . env . ADMIN_API_KEYS ,
54
52
} ,
55
53
} )
56
- const response = await app ( { } , { register : new Registry ( ) } ) . inject ( {
54
+ const response = await adminApp . inject ( {
57
55
method : 'GET' ,
58
56
url : `/tenants` ,
59
57
headers : {
@@ -71,7 +69,7 @@ describe('Tenant configs', () => {
71
69
} )
72
70
73
71
test ( 'Get nonexistent tenant config' , async ( ) => {
74
- const response = await app ( { } , { register : new Registry ( ) } ) . inject ( {
72
+ const response = await adminApp . inject ( {
75
73
method : 'GET' ,
76
74
url : `/tenants/abc` ,
77
75
headers : {
@@ -82,15 +80,15 @@ describe('Tenant configs', () => {
82
80
} )
83
81
84
82
test ( 'Get existing tenant config' , async ( ) => {
85
- await app ( { } , { register : new Registry ( ) } ) . inject ( {
83
+ await adminApp . inject ( {
86
84
method : 'POST' ,
87
85
url : `/tenants/abc` ,
88
86
payload,
89
87
headers : {
90
88
apikey : process . env . ADMIN_API_KEYS ,
91
89
} ,
92
90
} )
93
- const response = await app ( { } , { register : new Registry ( ) } ) . inject ( {
91
+ const response = await adminApp . inject ( {
94
92
method : 'GET' ,
95
93
url : `/tenants/abc` ,
96
94
headers : {
@@ -103,7 +101,7 @@ describe('Tenant configs', () => {
103
101
} )
104
102
105
103
test ( 'Insert tenant config without required properties' , async ( ) => {
106
- const response = await app ( { } , { register : new Registry ( ) } ) . inject ( {
104
+ const response = await adminApp . inject ( {
107
105
method : 'POST' ,
108
106
url : `/tenants/abc` ,
109
107
payload : { } ,
@@ -115,7 +113,7 @@ describe('Tenant configs', () => {
115
113
} )
116
114
117
115
test ( 'Insert tenant config twice' , async ( ) => {
118
- const firstInsertResponse = await app ( { } , { register : new Registry ( ) } ) . inject ( {
116
+ const firstInsertResponse = await adminApp . inject ( {
119
117
method : 'POST' ,
120
118
url : `/tenants/abc` ,
121
119
payload,
@@ -124,7 +122,7 @@ describe('Tenant configs', () => {
124
122
} ,
125
123
} )
126
124
expect ( firstInsertResponse . statusCode ) . toBe ( 201 )
127
- const secondInsertResponse = await app ( { } , { register : new Registry ( ) } ) . inject ( {
125
+ const secondInsertResponse = await adminApp . inject ( {
128
126
method : 'POST' ,
129
127
url : `/tenants/abc` ,
130
128
payload,
@@ -136,15 +134,15 @@ describe('Tenant configs', () => {
136
134
} )
137
135
138
136
test ( 'Update tenant config' , async ( ) => {
139
- await app ( { } , { register : new Registry ( ) } ) . inject ( {
137
+ await adminApp . inject ( {
140
138
method : 'POST' ,
141
139
url : `/tenants/abc` ,
142
140
payload,
143
141
headers : {
144
142
apikey : process . env . ADMIN_API_KEYS ,
145
143
} ,
146
144
} )
147
- const patchResponse = await app ( { } , { register : new Registry ( ) } ) . inject ( {
145
+ const patchResponse = await adminApp . inject ( {
148
146
method : 'PATCH' ,
149
147
url : `/tenants/abc` ,
150
148
payload : payload2 ,
@@ -153,7 +151,7 @@ describe('Tenant configs', () => {
153
151
} ,
154
152
} )
155
153
expect ( patchResponse . statusCode ) . toBe ( 204 )
156
- const getResponse = await app ( { } , { register : new Registry ( ) } ) . inject ( {
154
+ const getResponse = await adminApp . inject ( {
157
155
method : 'GET' ,
158
156
url : `/tenants/abc` ,
159
157
headers : {
@@ -165,15 +163,15 @@ describe('Tenant configs', () => {
165
163
} )
166
164
167
165
test ( 'Update tenant config partially' , async ( ) => {
168
- await app ( { } , { register : new Registry ( ) } ) . inject ( {
166
+ await adminApp . inject ( {
169
167
method : 'POST' ,
170
168
url : `/tenants/abc` ,
171
169
payload,
172
170
headers : {
173
171
apikey : process . env . ADMIN_API_KEYS ,
174
172
} ,
175
173
} )
176
- const patchResponse = await app ( { } , { register : new Registry ( ) } ) . inject ( {
174
+ const patchResponse = await adminApp . inject ( {
177
175
method : 'PATCH' ,
178
176
url : `/tenants/abc` ,
179
177
payload : { fileSizeLimit : 2 } ,
@@ -182,7 +180,7 @@ describe('Tenant configs', () => {
182
180
} ,
183
181
} )
184
182
expect ( patchResponse . statusCode ) . toBe ( 204 )
185
- const getResponse = await app ( { } , { register : new Registry ( ) } ) . inject ( {
183
+ const getResponse = await adminApp . inject ( {
186
184
method : 'GET' ,
187
185
url : `/tenants/abc` ,
188
186
headers : {
@@ -194,7 +192,7 @@ describe('Tenant configs', () => {
194
192
} )
195
193
196
194
test ( 'Upsert tenant config' , async ( ) => {
197
- const firstPutResponse = await app ( { } , { register : new Registry ( ) } ) . inject ( {
195
+ const firstPutResponse = await adminApp . inject ( {
198
196
method : 'PUT' ,
199
197
url : `/tenants/abc` ,
200
198
payload,
@@ -203,7 +201,7 @@ describe('Tenant configs', () => {
203
201
} ,
204
202
} )
205
203
expect ( firstPutResponse . statusCode ) . toBe ( 204 )
206
- const firstGetResponse = await app ( { } , { register : new Registry ( ) } ) . inject ( {
204
+ const firstGetResponse = await adminApp . inject ( {
207
205
method : 'GET' ,
208
206
url : `/tenants/abc` ,
209
207
headers : {
@@ -212,7 +210,7 @@ describe('Tenant configs', () => {
212
210
} )
213
211
const firstGetResponseJSON = JSON . parse ( firstGetResponse . body )
214
212
expect ( firstGetResponseJSON ) . toEqual ( payload )
215
- const secondPutResponse = await app ( { } , { register : new Registry ( ) } ) . inject ( {
213
+ const secondPutResponse = await adminApp . inject ( {
216
214
method : 'PUT' ,
217
215
url : `/tenants/abc` ,
218
216
payload : payload2 ,
@@ -221,7 +219,7 @@ describe('Tenant configs', () => {
221
219
} ,
222
220
} )
223
221
expect ( secondPutResponse . statusCode ) . toBe ( 204 )
224
- const secondGetResponse = await app ( { } , { register : new Registry ( ) } ) . inject ( {
222
+ const secondGetResponse = await adminApp . inject ( {
225
223
method : 'GET' ,
226
224
url : `/tenants/abc` ,
227
225
headers : {
@@ -233,23 +231,23 @@ describe('Tenant configs', () => {
233
231
} )
234
232
235
233
test ( 'Delete tenant config' , async ( ) => {
236
- await app ( { } , { register : new Registry ( ) } ) . inject ( {
234
+ await adminApp . inject ( {
237
235
method : 'POST' ,
238
236
url : `/tenants/abc` ,
239
237
payload,
240
238
headers : {
241
239
apikey : process . env . ADMIN_API_KEYS ,
242
240
} ,
243
241
} )
244
- const deleteResponse = await app ( { } , { register : new Registry ( ) } ) . inject ( {
242
+ const deleteResponse = await adminApp . inject ( {
245
243
method : 'DELETE' ,
246
244
url : '/tenants/abc' ,
247
245
headers : {
248
246
apikey : process . env . ADMIN_API_KEYS ,
249
247
} ,
250
248
} )
251
249
expect ( deleteResponse . statusCode ) . toBe ( 204 )
252
- const getResponse = await app ( { } , { register : new Registry ( ) } ) . inject ( {
250
+ const getResponse = await adminApp . inject ( {
253
251
method : 'GET' ,
254
252
url : `/tenants/abc` ,
255
253
headers : {
0 commit comments