@adaptivestone/framework 5.0.0-alpha.10 → 5.0.0-alpha.11

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 5.0.0-alpha.11
2
+
3
+ [UPDATE] update deps
4
+
1
5
  ### 5.0.0-alpha.10
2
6
 
3
7
  [UPDATE] update deps
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaptivestone/framework",
3
- "version": "5.0.0-alpha.10",
3
+ "version": "5.0.0-alpha.11",
4
4
  "description": "Adaptive stone node js framework",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -48,7 +48,7 @@
48
48
  "rate-limiter-flexible": "^5.0.0",
49
49
  "redis": "^4.3.1",
50
50
  "winston": "^3.3.3",
51
- "winston-transport-sentry-node": "^2.0.0",
51
+ "winston-transport-sentry-node": "^3.0.0",
52
52
  "yup": "^1.0.0"
53
53
  },
54
54
  "devDependencies": {
package/.eslintrc.cjs DELETED
@@ -1,41 +0,0 @@
1
- module.exports = {
2
- env: {
3
- es2023: true,
4
- node: true,
5
- },
6
- extends: ['airbnb-base', 'prettier'],
7
- plugins: ['prettier'],
8
- parserOptions: {
9
- ecmaVersion: 2023,
10
- },
11
- rules: {
12
- 'no-restricted-syntax': [
13
- 'error',
14
- {
15
- selector: 'ForInStatement',
16
- message:
17
- 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
18
- },
19
- {
20
- selector: 'LabeledStatement',
21
- message:
22
- 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
23
- },
24
- {
25
- selector: 'WithStatement',
26
- message:
27
- '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
28
- },
29
- ],
30
- 'prettier/prettier': 'error',
31
- 'import/extensions': 'off', // it have a problem with dynamic imports
32
- 'import/prefer-default-export': 'off', // we want to have signgke default export too
33
- },
34
- overrides: [
35
- {
36
- files: ['**/*.test.js'],
37
- extends: ['plugin:vitest/all', 'plugin:vitest/recommended'],
38
- plugins: ['vitest'],
39
- },
40
- ],
41
- };
@@ -1,451 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
-
3
- const userEmail = 'testing@test.com';
4
- const userPassword = 'SuperNiceSecret123$';
5
-
6
- const userEmail2 = 'testing2@test.com';
7
-
8
- describe('auth', () => {
9
- describe('registration', () => {
10
- it('code NOT able to create user with wrong email', async () => {
11
- expect.assertions(1);
12
- const { status } = await fetch(
13
- global.server.testingGetUrl('/auth/register'),
14
- {
15
- method: 'POST',
16
- headers: {
17
- 'Content-type': 'application/json',
18
- },
19
- body: JSON.stringify({
20
- email: 'bad email',
21
- password: userPassword,
22
- nickName: 'test',
23
- }),
24
- },
25
- ).catch(() => {});
26
-
27
- expect(status).toBe(400);
28
- });
29
-
30
- it('can create user', async () => {
31
- expect.assertions(1);
32
- const { status } = await fetch(
33
- global.server.testingGetUrl('/auth/register'),
34
- {
35
- method: 'POST',
36
- headers: {
37
- 'Content-type': 'application/json',
38
- },
39
- body: JSON.stringify({
40
- email: userEmail,
41
- password: userPassword,
42
- nickName: 'test',
43
- }),
44
- },
45
- );
46
- expect(status).toBe(201);
47
- });
48
-
49
- it('can not create user with the same nickname', async () => {
50
- expect.assertions(1);
51
- await fetch(global.server.testingGetUrl('/auth/register'), {
52
- method: 'POST',
53
- headers: {
54
- 'Content-type': 'application/json',
55
- },
56
- body: JSON.stringify({
57
- email: userEmail,
58
- password: userPassword,
59
- nickName: 'test',
60
- }),
61
- });
62
-
63
- const { status } = await fetch(
64
- global.server.testingGetUrl('/auth/register'),
65
- {
66
- method: 'POST',
67
- headers: {
68
- 'Content-type': 'application/json',
69
- },
70
- body: JSON.stringify({
71
- email: userEmail2,
72
- password: '123',
73
- nickName: 'test',
74
- }),
75
- },
76
- ).catch(() => {});
77
-
78
- expect(status).toBe(400);
79
- });
80
-
81
- it('can NOT create SAME user', async () => {
82
- expect.assertions(1);
83
-
84
- const { status } = await fetch(
85
- global.server.testingGetUrl('/auth/register'),
86
- {
87
- method: 'POST',
88
- headers: {
89
- 'Content-type': 'application/json',
90
- },
91
- body: JSON.stringify({
92
- email: userEmail,
93
- password: userPassword,
94
- nickName: 'test',
95
- }),
96
- },
97
- );
98
-
99
- expect(status).toBe(400);
100
- });
101
- });
102
-
103
- describe('login', () => {
104
- it('can NOT login with normal creds and not verified email', async () => {
105
- expect.assertions(1);
106
- const { status } = await fetch(
107
- global.server.testingGetUrl('/auth/login'),
108
- {
109
- method: 'POST',
110
- headers: {
111
- 'Content-type': 'application/json',
112
- },
113
- body: JSON.stringify({
114
- email: userEmail,
115
- password: userPassword,
116
- }),
117
- },
118
- ).catch(() => {});
119
-
120
- expect(status).toBe(400);
121
- });
122
-
123
- it('can NOT login with WRONG creds', async () => {
124
- expect.assertions(1);
125
- const { status } = await fetch(
126
- global.server.testingGetUrl('/auth/login'),
127
- {
128
- method: 'POST',
129
- headers: {
130
- 'Content-type': 'application/json',
131
- },
132
- body: JSON.stringify({
133
- email: 'test@test.by',
134
- password: 'noPassword$',
135
- }),
136
- },
137
- ).catch(() => {});
138
- expect(status).toBe(400);
139
- });
140
-
141
- it('can login with normal creds and verified email', async () => {
142
- expect.assertions(2);
143
-
144
- const user = await global.server.app
145
- .getModel('User')
146
- .findOne({ email: userEmail });
147
- user.isVerified = true;
148
- await user.save();
149
-
150
- const response = await fetch(global.server.testingGetUrl('/auth/login'), {
151
- method: 'POST',
152
- headers: {
153
- 'Content-type': 'application/json',
154
- },
155
- body: JSON.stringify({
156
- email: userEmail,
157
- password: userPassword,
158
- }),
159
- });
160
-
161
- const responseBody = await response.json();
162
-
163
- expect(response.status).toBe(200);
164
- expect(responseBody.token).toBeDefined();
165
- });
166
- });
167
-
168
- describe('isAuthWithVefificationFlow auth option', () => {
169
- it('can verify user', async () => {
170
- expect.assertions(2);
171
- const user = await global.server.app.getModel('User').create({
172
- email: 'Test@gmail.com',
173
- password: 'userPassword',
174
- name: {
175
- nick: 'nickname',
176
- },
177
- });
178
-
179
- user.verificationTokens.push({
180
- token: 'testToken',
181
- });
182
-
183
- await user.save();
184
-
185
- const { status } = await fetch(
186
- `${global.server.testingGetUrl(
187
- '/auth/verify',
188
- )}?verification_token=testToken`,
189
- {
190
- method: 'POST',
191
- },
192
- );
193
-
194
- const { isVerified } = await global.server.app.getModel('User').findOne({
195
- email: 'Test@gmail.com',
196
- });
197
-
198
- expect(status).toBe(200);
199
- expect(isVerified).toBeTruthy();
200
- });
201
-
202
- it('can not verify user with wrong token', async () => {
203
- expect.assertions(2);
204
- const user = await global.server.app.getModel('User').create({
205
- email: 'Test423@gmail.com',
206
- password: 'userPassword',
207
- name: {
208
- nick: 'nicknameee',
209
- },
210
- });
211
-
212
- user.verificationTokens.push({
213
- token: 'testToken',
214
- });
215
-
216
- await user.save();
217
-
218
- const { status } = await fetch(
219
- `${global.server.testingGetUrl(
220
- '/auth/verify',
221
- )}?verification_token=testToken123wrong`,
222
- {
223
- method: 'POST',
224
- },
225
- );
226
-
227
- const { isVerified } = await global.server.app.getModel('User').findOne({
228
- email: 'Test423@gmail.com',
229
- });
230
-
231
- expect(status).toBe(400);
232
- expect(isVerified).toBeFalsy();
233
- });
234
-
235
- it('can NOT send recovery to not exist email', async () => {
236
- expect.assertions(1);
237
- const { status } = await fetch(
238
- global.server.testingGetUrl('/auth/send-recovery-email'),
239
- {
240
- method: 'POST',
241
- headers: {
242
- 'Content-type': 'application/json',
243
- },
244
- body: JSON.stringify({
245
- email: 'notExists@gmail.com',
246
- }),
247
- },
248
- );
249
-
250
- expect(status).toBe(400);
251
- });
252
-
253
- it('can send recovery to exist email', async () => {
254
- expect.assertions(1);
255
- const { status } = await fetch(
256
- global.server.testingGetUrl('/auth/send-recovery-email'),
257
- {
258
- method: 'POST',
259
- headers: {
260
- 'Content-type': 'application/json',
261
- },
262
- body: JSON.stringify({
263
- email: userEmail,
264
- }),
265
- },
266
- );
267
-
268
- expect(status).toBe(200);
269
- });
270
-
271
- it('can recover password', async () => {
272
- expect.assertions(1);
273
-
274
- const user = await global.server.app.getModel('User').create({
275
- email: 'Test1@gmail.com',
276
- password: 'userPassword',
277
- name: {
278
- nick: 'nickname1',
279
- },
280
- });
281
-
282
- user.passwordRecoveryTokens.push({
283
- token: 'superPassword',
284
- });
285
-
286
- await user.save();
287
-
288
- const { status } = await fetch(
289
- global.server.testingGetUrl('/auth/recover-password'),
290
- {
291
- method: 'POST',
292
- headers: {
293
- 'Content-type': 'application/json',
294
- },
295
- body: JSON.stringify({
296
- password: 'newPass',
297
- passwordRecoveryToken: 'superPassword',
298
- }),
299
- },
300
- );
301
-
302
- expect(status).toBe(200);
303
- });
304
-
305
- it('can not recover password with wrong token', async () => {
306
- expect.assertions(1);
307
-
308
- const user = await global.server.app.getModel('User').create({
309
- email: 'Test2@gmail.com',
310
- password: 'userPassword',
311
- name: {
312
- nick: 'nickname2',
313
- },
314
- });
315
-
316
- user.passwordRecoveryTokens.push({
317
- token: 'superPassword',
318
- });
319
-
320
- await user.save();
321
-
322
- const { status } = await fetch(
323
- global.server.testingGetUrl('/auth/recover-password'),
324
- {
325
- method: 'POST',
326
- headers: {
327
- 'Content-type': 'application/json',
328
- },
329
- body: JSON.stringify({
330
- password: 'newPass',
331
- passwordRecoveryToken: '13123',
332
- }),
333
- },
334
- );
335
-
336
- expect(status).toBe(400);
337
- });
338
-
339
- it('can login with normal creds and NOT verifyed email if option isAuthWithVefificationFlow is set', async () => {
340
- expect.assertions(4);
341
-
342
- const { status } = await fetch(
343
- global.server.testingGetUrl('/auth/register'),
344
- {
345
- method: 'POST',
346
- headers: {
347
- 'Content-type': 'application/json',
348
- },
349
- body: JSON.stringify({
350
- email: userEmail2,
351
- password: userPassword,
352
- }),
353
- },
354
- );
355
-
356
- const { status: status2 } = await fetch(
357
- global.server.testingGetUrl('/auth/login'),
358
- {
359
- method: 'POST',
360
- headers: {
361
- 'Content-type': 'application/json',
362
- },
363
- body: JSON.stringify({
364
- email: userEmail2,
365
- password: userPassword,
366
- }),
367
- },
368
- );
369
-
370
- global.server.app.updateConfig('auth', {
371
- isAuthWithVefificationFlow: false,
372
- });
373
-
374
- const response3 = await fetch(
375
- global.server.testingGetUrl('/auth/login'),
376
- {
377
- method: 'POST',
378
- headers: {
379
- 'Content-type': 'application/json',
380
- },
381
- body: JSON.stringify({
382
- email: userEmail2,
383
- password: userPassword,
384
- }),
385
- },
386
- );
387
-
388
- const responseBody3 = await response3.json();
389
-
390
- expect(status).toBe(201);
391
- expect(status2).toBe(400);
392
- expect(response3.status).toBe(200);
393
- expect(responseBody3.token).toBeDefined();
394
- });
395
- });
396
-
397
- it('can user send verification', async () => {
398
- expect.assertions(1);
399
-
400
- const { status } = await fetch(
401
- global.server.testingGetUrl('/auth/send-verification'),
402
- {
403
- method: 'POST',
404
- headers: {
405
- 'Content-type': 'application/json',
406
- },
407
- body: JSON.stringify({
408
- email: userEmail2,
409
- }),
410
- },
411
- );
412
-
413
- expect(status).toBe(200);
414
- });
415
-
416
- it('can not user send verification to wrong email', async () => {
417
- expect.assertions(1);
418
-
419
- const { status } = await fetch(
420
- global.server.testingGetUrl('/auth/send-verification'),
421
- {
422
- method: 'POST',
423
- headers: {
424
- 'Content-type': 'application/json',
425
- },
426
- body: JSON.stringify({
427
- email: 'wrong@gmail.com',
428
- }),
429
- },
430
- );
431
-
432
- expect(status).toBe(400);
433
- });
434
-
435
- describe('rate limiter', () => {
436
- it('should receive 429 on rate limit exceeded', async () => {
437
- expect.assertions(1);
438
-
439
- const requests = Array.from({ length: 11 }, () =>
440
- fetch(global.server.testingGetUrl('/auth/logout'), {
441
- method: 'POST',
442
- }),
443
- );
444
-
445
- const responses = await Promise.all(requests);
446
- const statusCodes = responses.map((response) => response.status);
447
-
448
- expect(statusCodes).toContain(429);
449
- });
450
- });
451
- });
@@ -1,12 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
-
3
- describe('home', () => {
4
- it('can open home have', async () => {
5
- expect.assertions(1);
6
- const { status } = await fetch(global.server.testingGetUrl('/')).catch(
7
- () => {},
8
- );
9
-
10
- expect(status).toBe(200);
11
- });
12
- });
@@ -1,20 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
-
3
- describe('migration model', () => {
4
- it('migrationFile should be uniqe', async () => {
5
- expect.assertions(1);
6
- let errorCode;
7
- const MigrationModel = global.server.app.getModel('Migration');
8
- await MigrationModel.syncIndexes();
9
- await MigrationModel.create({
10
- migrationFile: 'a',
11
- });
12
- await MigrationModel.create({
13
- migrationFile: 'a',
14
- }).catch((e) => {
15
- errorCode = e.code;
16
- });
17
-
18
- expect(errorCode).toBe(11000);
19
- });
20
- });
@@ -1,43 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
-
3
- describe('sequence model', () => {
4
- it('should produce sequence', async () => {
5
- expect.assertions(1);
6
- const SequenceModel = global.server.app.getModel('Sequence');
7
-
8
- const number1 = await SequenceModel.getSequence('typeOne');
9
-
10
- expect(number1).toBe(1);
11
- });
12
-
13
- it('should produce sequence different for different types', async () => {
14
- expect.assertions(3);
15
- const SequenceModel = global.server.app.getModel('Sequence');
16
-
17
- const number1 = await SequenceModel.getSequence('typeOneAgain');
18
- const number2 = await SequenceModel.getSequence('typeTwo');
19
- const number3 = await SequenceModel.getSequence('typeThree');
20
-
21
- expect(number1).toBe(1);
22
- expect(number2).toBe(1);
23
- expect(number3).toBe(1);
24
- });
25
-
26
- it('should works on async env', async () => {
27
- expect.assertions(1);
28
- const SequenceModel = global.server.app.getModel('Sequence');
29
-
30
- const promises = [];
31
- const upTo = 100;
32
- for (let i = 0; i < upTo; i += 1) {
33
- promises.push(SequenceModel.getSequence('asyncTypeOne'));
34
- }
35
-
36
- const data = await Promise.all(promises);
37
- const summ = ((1 + upTo) / 2) * upTo; // Arithmetic progression
38
-
39
- const summ2 = data.reduce((a, b) => a + b, 0);
40
-
41
- expect(summ2).toBe(summ);
42
- });
43
- });