@drax/identity-back 1.0.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,6 +15,17 @@ UserLoginFailMongoSchema.set('toJSON', { getters: true, virtuals: true });
15
15
  UserLoginFailMongoSchema.set('toObject', { getters: true, virtuals: true });
16
16
  const MODEL_NAME = 'UserLoginFail';
17
17
  const COLLECTION_NAME = 'UserLoginFail';
18
- const UserLoginFailModel = mongoose.model(MODEL_NAME, UserLoginFailMongoSchema, COLLECTION_NAME);
18
+ let UserLoginFailModel;
19
+ try {
20
+ UserLoginFailModel = mongoose.model(MODEL_NAME, UserLoginFailMongoSchema, COLLECTION_NAME);
21
+ }
22
+ catch (e) {
23
+ if (e.name === 'OverwriteModelError') {
24
+ UserLoginFailModel = mongoose.model(MODEL_NAME);
25
+ }
26
+ else {
27
+ throw e;
28
+ }
29
+ }
19
30
  export { UserLoginFailMongoSchema, UserLoginFailModel };
20
31
  export default UserLoginFailModel;
@@ -16,6 +16,17 @@ UserSessionMongoSchema.set('toJSON', { getters: true, virtuals: true });
16
16
  UserSessionMongoSchema.set('toObject', { getters: true, virtuals: true });
17
17
  const MODEL_NAME = 'UserSession';
18
18
  const COLLECTION_NAME = 'UserSession';
19
- const UserSessionModel = mongoose.model(MODEL_NAME, UserSessionMongoSchema, COLLECTION_NAME);
19
+ let UserSessionModel;
20
+ try {
21
+ UserSessionModel = mongoose.model(MODEL_NAME, UserSessionMongoSchema, COLLECTION_NAME);
22
+ }
23
+ catch (e) {
24
+ if (e.name === 'OverwriteModelError') {
25
+ UserSessionModel = mongoose.model(MODEL_NAME);
26
+ }
27
+ else {
28
+ throw e;
29
+ }
30
+ }
20
31
  export { UserSessionMongoSchema, UserSessionModel };
21
32
  export default UserSessionModel;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.0.0",
6
+ "version": "1.1.1",
7
7
  "description": "Identity module for user management, authentication and authorization.",
8
8
  "main": "dist/index.js",
9
9
  "types": "types/index.d.ts",
@@ -21,15 +21,15 @@
21
21
  "testMongoRepositoryUserApiKey": "node --import tsx --test test/repository/mongo/user-apikey-mongo*",
22
22
  "testSqliteRepositoryUser": "node --import tsx --test test/repository/sqlite/user*",
23
23
  "testSqliteRepositoryRole": "node --import tsx --test test/repository/sqlite/role*",
24
- "testServiceRole": "node --import tsx --test test/service/role*",
25
- "testServiceUser": "node --import tsx --test test/service/user*",
26
- "testcoverage": "node --import tsx --experimental-test-coverage test/service/*"
24
+ "testServiceRole": "node --import tsx --test test/services/role*",
25
+ "testServiceUser": "node --import tsx --test test/services/user*",
26
+ "testcoverage": "node --import tsx --experimental-test-coverage test/services/*"
27
27
  },
28
28
  "author": "Cristian Incarnato & Drax Team",
29
29
  "license": "ISC",
30
30
  "dependencies": {
31
- "@drax/common-back": "^1.0.0",
32
- "@drax/crud-back": "^1.0.0",
31
+ "@drax/common-back": "^1.1.1",
32
+ "@drax/crud-back": "^1.1.1",
33
33
  "@drax/crud-share": "^1.0.0",
34
34
  "@drax/email-back": "^1.0.0",
35
35
  "@drax/identity-share": "^1.0.0",
@@ -63,5 +63,5 @@
63
63
  "debug": "0"
64
64
  }
65
65
  },
66
- "gitHead": "8e60f7548448f339e7e9bb665ceacd3e051ef32e"
66
+ "gitHead": "cb36d1f5654d6d8f7d10498037f9b87e72a11e42"
67
67
  }
@@ -24,7 +24,20 @@ UserLoginFailMongoSchema.set('toObject', {getters: true, virtuals: true});
24
24
 
25
25
  const MODEL_NAME = 'UserLoginFail';
26
26
  const COLLECTION_NAME = 'UserLoginFail';
27
- const UserLoginFailModel = mongoose.model<IUserLoginFail, PaginateModel<IUserLoginFail>>(MODEL_NAME, UserLoginFailMongoSchema,COLLECTION_NAME);
27
+
28
+ let UserLoginFailModel;
29
+
30
+ try {
31
+ UserLoginFailModel = mongoose.model<IUserLoginFail, PaginateModel<IUserLoginFail>>(MODEL_NAME, UserLoginFailMongoSchema, COLLECTION_NAME);
32
+ } catch (e) {
33
+ if (e.name === 'OverwriteModelError') {
34
+ UserLoginFailModel = mongoose.model<IUserLoginFail, PaginateModel<IUserLoginFail>>(MODEL_NAME);
35
+ } else {
36
+ throw e;
37
+ }
38
+ }
39
+
40
+
28
41
 
29
42
  export {
30
43
  UserLoginFailMongoSchema,
@@ -26,7 +26,19 @@ UserSessionMongoSchema.set('toObject', {getters: true, virtuals: true});
26
26
 
27
27
  const MODEL_NAME = 'UserSession';
28
28
  const COLLECTION_NAME = 'UserSession';
29
- const UserSessionModel = mongoose.model<IUserSession, PaginateModel<IUserSession>>(MODEL_NAME, UserSessionMongoSchema,COLLECTION_NAME);
29
+
30
+ let UserSessionModel;
31
+
32
+ try {
33
+ UserSessionModel = mongoose.model<IUserSession, PaginateModel<IUserSession>>(MODEL_NAME, UserSessionMongoSchema,COLLECTION_NAME);
34
+ } catch (e) {
35
+ if (e.name === 'OverwriteModelError') {
36
+ UserSessionModel = mongoose.model<IUserSession, PaginateModel<IUserSession>>(MODEL_NAME);
37
+ } else {
38
+ throw e;
39
+ }
40
+ }
41
+
30
42
 
31
43
  export {
32
44
  UserSessionMongoSchema,
@@ -1,32 +1,36 @@
1
1
  import {describe, it, beforeAll, afterAll, expect} from "vitest"
2
- import MongoInMemory from "../db/MongoInMemory";
3
2
  import TenantRoute from "../../src/routes/TenantRoutes";
4
-
5
- process.env.DRAX_DB_ENGINE = "mongo"
6
- import {FastifyTestServerFactory} from './helpers/FastifyTestServerFactory'
3
+ import TestSetup from "../setup/TestSetup";
7
4
 
8
5
 
9
6
  describe("Tenant Route Test", function () {
10
7
 
11
- let FastifyTestServer = FastifyTestServerFactory()
12
- FastifyTestServer.register(TenantRoute)
8
+ let testSetup = new TestSetup()
9
+ let FASTIFY_TEST_SERVER: any;
10
+ let ACCESS_TOKEN: any;
13
11
 
14
12
  beforeAll(async () => {
15
- await MongoInMemory.connect()
16
- console.log("BEFORE MOCK", MongoInMemory.mongooseStatus, MongoInMemory.serverStatus)
17
- // const tenantService = TenantServiceFactory()
18
- // await tenantService.create({name: "TestTenant"})
19
-
20
-
21
- return
13
+ await testSetup.setup()
14
+ FASTIFY_TEST_SERVER = testSetup.fastifyInstance
15
+ const {accessToken} = await testSetup.login()
16
+ ACCESS_TOKEN = accessToken
22
17
  })
23
18
 
24
19
  afterAll(async () => {
25
- await MongoInMemory.DropAndClose()
26
- console.log("AFTER MOCK", MongoInMemory.status, MongoInMemory.serverStatus)
20
+ await testSetup.mongoInMemory.DropAndClose()
27
21
  return
28
22
  })
29
23
 
24
+ it("Me", async () => {
25
+
26
+ const resp = await FASTIFY_TEST_SERVER.inject({
27
+ method: 'get',
28
+ url: '/api/auth/me',
29
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
30
+ });
31
+ let body = resp.json()
32
+ console.log("me", body)
33
+ })
30
34
 
31
35
  it("Should paginate tenant", async () => {
32
36
  // First, create a few tenants
@@ -37,17 +41,18 @@ describe("Tenant Route Test", function () {
37
41
  ];
38
42
 
39
43
  for (const data of tenantData) {
40
- await FastifyTestServer.inject({
44
+ await FASTIFY_TEST_SERVER.inject({
41
45
  method: 'POST',
42
46
  url: '/api/tenants',
43
- payload: data
47
+ payload: data,
48
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
44
49
  });
45
50
  }
46
51
 
47
- const resp = await FastifyTestServer.inject({
52
+ const resp = await FASTIFY_TEST_SERVER.inject({
48
53
  method: 'GET',
49
54
  url: '/api/tenants',
50
-
55
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
51
56
  })
52
57
 
53
58
  const result = await resp.json()
@@ -65,10 +70,11 @@ describe("Tenant Route Test", function () {
65
70
  name: "NewTestTenant"
66
71
  };
67
72
 
68
- const resp = await FastifyTestServer.inject({
73
+ const resp = await FASTIFY_TEST_SERVER.inject({
69
74
  method: 'POST',
70
75
  url: '/api/tenants',
71
- payload: newTenant
76
+ payload: newTenant,
77
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
72
78
  });
73
79
 
74
80
  const result = await resp.json();
@@ -77,9 +83,10 @@ describe("Tenant Route Test", function () {
77
83
  expect(result._id).toBeDefined();
78
84
 
79
85
  // Verify tenant was created by fetching it
80
- const getResp = await FastifyTestServer.inject({
86
+ const getResp = await FASTIFY_TEST_SERVER.inject({
81
87
  method: 'GET',
82
- url: '/api/tenants/' + result.id
88
+ url: '/api/tenants/' + result.id,
89
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
83
90
  });
84
91
 
85
92
  const getTenant = await getResp.json();
@@ -93,16 +100,18 @@ describe("Tenant Route Test", function () {
93
100
  name: "ExistTenant"
94
101
  };
95
102
 
96
- const resp = await FastifyTestServer.inject({
103
+ const resp = await FASTIFY_TEST_SERVER.inject({
97
104
  method: 'POST',
98
105
  url: '/api/tenants',
99
- payload: newTenant
106
+ payload: newTenant,
107
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
100
108
  });
101
109
 
102
110
  // First, get existing tenants to extract the id
103
- const getResp = await FastifyTestServer.inject({
111
+ const getResp = await FASTIFY_TEST_SERVER.inject({
104
112
  method: 'GET',
105
113
  url: '/api/tenants',
114
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
106
115
  })
107
116
 
108
117
  const result = await getResp.json()
@@ -114,10 +123,11 @@ describe("Tenant Route Test", function () {
114
123
  }
115
124
 
116
125
  // Send update request
117
- const updateResp = await FastifyTestServer.inject({
126
+ const updateResp = await FASTIFY_TEST_SERVER.inject({
118
127
  method: 'PUT',
119
128
  url: `/api/tenants/${tenantId}`,
120
- payload: updateData
129
+ payload: updateData,
130
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
121
131
  })
122
132
 
123
133
  // Verify update response
@@ -126,9 +136,10 @@ describe("Tenant Route Test", function () {
126
136
  expect(updatedTenant.name).toBe("UpdatedTenantName")
127
137
 
128
138
  // Verify the tenant was actually updated by fetching it again
129
- const verifyResp = await FastifyTestServer.inject({
139
+ const verifyResp = await FASTIFY_TEST_SERVER.inject({
130
140
  method: 'GET',
131
141
  url: `/api/tenants/${tenantId}`,
142
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
132
143
  })
133
144
 
134
145
  const verifiedTenant = await verifyResp.json()
@@ -136,10 +147,11 @@ describe("Tenant Route Test", function () {
136
147
  expect(verifiedTenant.name).toBe("UpdatedTenantName")
137
148
 
138
149
  // Send update inexistingId should return 404
139
- const updateRespNotFound = await FastifyTestServer.inject({
150
+ const updateRespNotFound = await FASTIFY_TEST_SERVER.inject({
140
151
  method: 'PUT',
141
152
  url: `/api/tenants/66761bed94d57a42c3277bab`,
142
- payload: updateData
153
+ payload: updateData,
154
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
143
155
  })
144
156
 
145
157
  // Verify update response
@@ -153,10 +165,11 @@ describe("Tenant Route Test", function () {
153
165
  name: "TenantToDelete"
154
166
  };
155
167
 
156
- const createResp = await FastifyTestServer.inject({
168
+ const createResp = await FASTIFY_TEST_SERVER.inject({
157
169
  method: 'POST',
158
170
  url: '/api/tenants',
159
- payload: newTenant
171
+ payload: newTenant,
172
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
160
173
  });
161
174
 
162
175
  const createdTenant = await createResp.json();
@@ -164,9 +177,10 @@ describe("Tenant Route Test", function () {
164
177
  const tenantId = createdTenant.id;
165
178
 
166
179
  // Delete the tenant
167
- const deleteResp = await FastifyTestServer.inject({
180
+ const deleteResp = await FASTIFY_TEST_SERVER.inject({
168
181
  method: 'DELETE',
169
- url: `/api/tenants/${tenantId}`
182
+ url: `/api/tenants/${tenantId}`,
183
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
170
184
  });
171
185
 
172
186
  // Verify delete response
@@ -175,9 +189,10 @@ describe("Tenant Route Test", function () {
175
189
  expect(deleteResult.deleted).toBe(true);
176
190
 
177
191
  // Verify the tenant was actually deleted by trying to fetch it
178
- const verifyResp = await FastifyTestServer.inject({
192
+ const verifyResp = await FASTIFY_TEST_SERVER.inject({
179
193
  method: 'GET',
180
- url: `/api/tenants/${tenantId}`
194
+ url: `/api/tenants/${tenantId}`,
195
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
181
196
  });
182
197
 
183
198
  // Should return 404 or empty response
@@ -190,10 +205,11 @@ describe("Tenant Route Test", function () {
190
205
  name: "FindByIdTenant"
191
206
  };
192
207
 
193
- const createResp = await FastifyTestServer.inject({
208
+ const createResp = await FASTIFY_TEST_SERVER.inject({
194
209
  method: 'POST',
195
210
  url: '/api/tenants',
196
- payload: newTenant
211
+ payload: newTenant,
212
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
197
213
  });
198
214
 
199
215
  const createdTenant = await createResp.json();
@@ -201,9 +217,10 @@ describe("Tenant Route Test", function () {
201
217
  const tenantId = createdTenant.id;
202
218
 
203
219
  // Now fetch the tenant by ID
204
- const getResp = await FastifyTestServer.inject({
220
+ const getResp = await FASTIFY_TEST_SERVER.inject({
205
221
  method: 'GET',
206
- url: `/api/tenants/${tenantId}`
222
+ url: `/api/tenants/${tenantId}`,
223
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
207
224
  });
208
225
 
209
226
  // Verify the response
@@ -223,17 +240,19 @@ describe("Tenant Route Test", function () {
223
240
 
224
241
  // Create the test tenants
225
242
  for (const data of tenantData) {
226
- await FastifyTestServer.inject({
243
+ await FASTIFY_TEST_SERVER.inject({
227
244
  method: 'POST',
228
245
  url: '/api/tenants',
229
- payload: data
246
+ payload: data,
247
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
230
248
  });
231
249
  }
232
250
 
233
251
  // Test searching with a matching term
234
- const searchResp = await FastifyTestServer.inject({
252
+ const searchResp = await FASTIFY_TEST_SERVER.inject({
235
253
  method: 'GET',
236
254
  url: '/api/tenants/search?search=Search',
255
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
237
256
  });
238
257
 
239
258
  const searchResult = await searchResp.json();
@@ -256,17 +275,19 @@ describe("Tenant Route Test", function () {
256
275
  ];
257
276
 
258
277
  for (const data of tenantData) {
259
- await FastifyTestServer.inject({
278
+ await FASTIFY_TEST_SERVER.inject({
260
279
  method: 'POST',
261
280
  url: '/api/tenants',
262
- payload: data
281
+ payload: data,
282
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
263
283
  });
264
284
  }
265
285
 
266
286
  // Get all tenants
267
- const resp = await FastifyTestServer.inject({
287
+ const resp = await FASTIFY_TEST_SERVER.inject({
268
288
  method: 'GET',
269
289
  url: '/api/tenants/all',
290
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
270
291
  });
271
292
 
272
293
  const result = await resp.json();
@@ -291,17 +312,19 @@ describe("Tenant Route Test", function () {
291
312
 
292
313
  // Create the test tenants
293
314
  for (const data of tenantData) {
294
- await FastifyTestServer.inject({
315
+ await FASTIFY_TEST_SERVER.inject({
295
316
  method: 'POST',
296
317
  url: '/api/tenants',
297
- payload: data
318
+ payload: data,
319
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
298
320
  });
299
321
  }
300
322
 
301
323
  // Test finding by description field with value "Special"
302
- const findByResp = await FastifyTestServer.inject({
324
+ const findByResp = await FASTIFY_TEST_SERVER.inject({
303
325
  method: 'GET',
304
326
  url: '/api/tenants/find-by/name/FieldTenantA',
327
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
305
328
  });
306
329
 
307
330
  const findByResult = await findByResp.json();
@@ -317,9 +340,10 @@ describe("Tenant Route Test", function () {
317
340
  // Try to fetch a non-existent tenant
318
341
  const nonExistentId = "123456789012345678901234"; // Valid MongoDB ObjectId that doesn't exist
319
342
 
320
- const resp = await FastifyTestServer.inject({
343
+ const resp = await FASTIFY_TEST_SERVER.inject({
321
344
  method: 'GET',
322
- url: `/api/tenants/${nonExistentId}`
345
+ url: `/api/tenants/${nonExistentId}`,
346
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
323
347
  });
324
348
 
325
349
  // Verify response status code should be 404 Not Found
@@ -1,14 +1,9 @@
1
1
  import {describe, it, beforeAll, afterAll, expect} from "vitest"
2
- import MongoInMemory from "../db/MongoInMemory";
3
2
 
4
- process.env.DRAX_DB_ENGINE = "mongo"
5
- process.env.DRAX_JWT_SECRET = "asdasdasd"
3
+ import {TestSetup} from "../setup/TestSetup"
4
+ import {IUserCreate} from "@drax/identity-share";
6
5
 
7
6
 
8
- import {SetupIdentityDrax} from "./helpers/SetupIdentityDrax.js"
9
- import {FastifyTestServerFactory} from './helpers/FastifyTestServerFactory.js'
10
- import {IUserCreate} from "@drax/identity-share";
11
- import {UserRoutes} from "../../src/index.js"
12
7
 
13
8
 
14
9
  const USER1: IUserCreate = {
@@ -41,60 +36,73 @@ const USER3: IUserCreate = {
41
36
 
42
37
  describe("User Route Test", async function () {
43
38
 
44
- let FastifyTestServer;
45
- let adminUser, roleAdmin
46
- let accessToken;
47
-
48
- async function login() {
49
- const resp = await FastifyTestServer.inject({
50
- method: 'POST',
51
- url: '/api/auth/login',
52
- payload: {username: 'root', password: "root.123"}
53
- });
54
- console.log("login", resp.statusCode)
55
- let body = resp.json()
56
- accessToken = body.accessToken;
57
- }
39
+ let testSetup = new TestSetup()
40
+ let FASTIFY_TEST_SERVER: any;
41
+ let ROOT_USER: any;
42
+ let ADMIN_ROLE: any;
43
+ let ACCESS_TOKEN: any;
58
44
 
59
45
  beforeAll(async () => {
60
- await MongoInMemory.connect()
61
- // console.log("BEFORE MOCK", MongoInMemory.mongooseStatus, MongoInMemory.serverStatus)
62
- let {user, role} = await SetupIdentityDrax()
63
- adminUser = user
64
- roleAdmin = role
65
- FastifyTestServer = FastifyTestServerFactory()
66
- FastifyTestServer.register(UserRoutes)
67
- await login()
46
+ await testSetup.setup()
47
+ FASTIFY_TEST_SERVER = testSetup.fastifyInstance
48
+ ROOT_USER = testSetup.rootUser
49
+ ADMIN_ROLE = testSetup.adminRole
50
+ const {accessToken} = await testSetup.login()
51
+ ACCESS_TOKEN = accessToken
68
52
  })
69
53
 
70
54
  afterAll(async () => {
71
- await MongoInMemory.DropAndClose()
72
- // console.log("AFTER MOCK", MongoInMemory.status, MongoInMemory.serverStatus)
55
+ await testSetup.mongoInMemory.DropAndClose()
73
56
  return
74
57
  })
75
58
 
76
- it("Me", async () => {
77
- // console.log("user", adminUser)
78
- // console.log("role", roleAdmin)
79
- // console.log("accessToken", accessToken)
59
+ it("Login & Me (express)", async () => {
60
+ let {accessToken} = await testSetup.login()
61
+ expect(accessToken).toBeTruthy()
62
+ let user = await testSetup.me(accessToken)
63
+ expect(user.username).toBe(testSetup.rootUserData.username)
64
+ })
65
+
66
+ it("Login & Me (detailed)", async () => {
67
+
68
+ const loginResp = await testSetup.fastifyInstance.inject({
69
+ method: 'POST',
70
+ url: '/api/auth/login',
71
+ payload: {
72
+ username: testSetup.rootUserData.username,
73
+ password: testSetup.rootUserData.password
74
+ }
75
+ });
76
+
77
+ expect(loginResp.statusCode).toBe(200)
78
+
79
+ let loginBody = loginResp.json()
80
+
81
+ expect(loginBody.accessToken).toBeTruthy()
82
+
83
+ let accessToken = loginBody.accessToken
80
84
 
81
- const resp = await FastifyTestServer.inject({
85
+ const resp = await testSetup.fastifyInstance.inject({
82
86
  method: 'get',
83
87
  url: '/api/auth/me',
84
88
  headers: {Authorization: `Bearer ${accessToken}`}
85
89
  });
86
90
  let body = resp.json()
87
- console.log("me", body)
91
+
92
+ expect(resp.statusCode).toBe(200)
93
+ expect(body.name).toBe(testSetup.rootUserData.name)
94
+
95
+
88
96
  })
89
97
 
90
98
 
91
99
  it("should create a new user", async () => {
92
100
 
93
- const resp = await FastifyTestServer.inject({
101
+ const resp = await FASTIFY_TEST_SERVER.inject({
94
102
  method: 'POST',
95
103
  url: '/api/users',
96
- payload: {...USER1, ...{role: roleAdmin._id}},
97
- headers: {Authorization: `Bearer ${accessToken}`}
104
+ payload: {...USER1, ...{role: ADMIN_ROLE._id}},
105
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
98
106
  });
99
107
 
100
108
  const result = await resp.json();
@@ -104,10 +112,10 @@ describe("User Route Test", async function () {
104
112
 
105
113
 
106
114
  // Verify tenant was created by fetching it
107
- const getResp = await FastifyTestServer.inject({
115
+ const getResp = await FASTIFY_TEST_SERVER.inject({
108
116
  method: 'GET',
109
117
  url: '/api/users/search?search=' + result._id,
110
- headers: {Authorization: `Bearer ${accessToken}`}
118
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
111
119
  });
112
120
 
113
121
  const items = await getResp.json();
@@ -123,24 +131,24 @@ describe("User Route Test", async function () {
123
131
  ];
124
132
 
125
133
  for (const data of users) {
126
- await FastifyTestServer.inject({
134
+ await FASTIFY_TEST_SERVER.inject({
127
135
  method: 'POST',
128
136
  url: '/api/users',
129
- payload: {...data, ...{role: roleAdmin._id.toString()}},
130
- headers: {Authorization: `Bearer ${accessToken}`}
137
+ payload: {...data, ...{role: ADMIN_ROLE._id.toString()}},
138
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
131
139
  });
132
140
  }
133
141
 
134
- const resp = await FastifyTestServer.inject({
142
+ const resp = await FASTIFY_TEST_SERVER.inject({
135
143
  method: 'GET',
136
144
  url: '/api/users',
137
- headers: {Authorization: `Bearer ${accessToken}`}
145
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
138
146
  })
139
147
 
140
148
  const result = await resp.json()
141
149
  expect(resp.statusCode).toBe(200)
142
150
  expect(result.items.length).toBe(4)
143
- expect(result.items[0].name).toBe(adminUser.name)
151
+ expect(result.items[0].name).toBe(ROOT_USER.name)
144
152
  expect(result.page).toBe(1)
145
153
  expect(result.limit).toBe(10)
146
154
  expect(result.total).toBe(4)
@@ -150,11 +158,11 @@ describe("User Route Test", async function () {
150
158
  it("should change my password", async () => {
151
159
 
152
160
 
153
- const respPassword = await FastifyTestServer.inject({
161
+ const respPassword = await FASTIFY_TEST_SERVER.inject({
154
162
  method: 'POST',
155
163
  url: '/api/users/password/change',
156
164
  payload: {currentPassword: "root.123", newPassword: "newpass"},
157
- headers: {Authorization: `Bearer ${accessToken}`}
165
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
158
166
  });
159
167
 
160
168
  const resultPassword = await respPassword.json();
@@ -167,11 +175,11 @@ describe("User Route Test", async function () {
167
175
  it("should change password", async () => {
168
176
 
169
177
 
170
- const respPassword = await FastifyTestServer.inject({
178
+ const respPassword = await FASTIFY_TEST_SERVER.inject({
171
179
  method: 'POST',
172
- url: '/api/users/password/change/'+adminUser._id,
180
+ url: '/api/users/password/change/'+ROOT_USER._id,
173
181
  payload: {currentPassword: "root.123", newPassword: "newpass"},
174
- headers: {Authorization: `Bearer ${accessToken}`}
182
+ headers: {Authorization: `Bearer ${ACCESS_TOKEN}`}
175
183
  });
176
184
 
177
185
  const resultPassword = await respPassword.json();