@wrcb/cb-common 1.0.57 → 1.0.58

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/build/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './types';
2
+ export * from './test/authHelper';
2
3
  export * from './errors/badRequestError';
3
4
  export * from './errors/customError';
4
5
  export * from './errors/databaseConnectionError';
package/build/index.js CHANGED
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./types"), exports);
18
+ __exportStar(require("./test/authHelper"), exports);
18
19
  __exportStar(require("./errors/badRequestError"), exports);
19
20
  __exportStar(require("./errors/customError"), exports);
20
21
  __exportStar(require("./errors/databaseConnectionError"), exports);
@@ -0,0 +1,6 @@
1
+ import { Express } from 'express';
2
+ export declare function signUp(app: Express): Promise<{
3
+ cookie: string[] | undefined;
4
+ userData: any;
5
+ }>;
6
+ export declare function signUpAdmin(id?: string): string[];
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.signUp = signUp;
16
+ exports.signUpAdmin = signUpAdmin;
17
+ const supertest_1 = __importDefault(require("supertest"));
18
+ const mongoose_1 = __importDefault(require("mongoose"));
19
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
20
+ const country_1 = require("../events/types/country");
21
+ const userRole_1 = require("../events/types/userRole");
22
+ function signUp(app) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const response = yield (0, supertest_1.default)(app)
25
+ .post('/api/auth/signup')
26
+ .send({
27
+ email: 'test@test.com.br',
28
+ nickName: 'ap',
29
+ country: country_1.Country.Brazil,
30
+ cpf: '05854744600',
31
+ phoneNumber: '(37)988083717',
32
+ password: 'password',
33
+ passwordConfirmation: 'password',
34
+ })
35
+ .expect(201);
36
+ const cookie = response.get('Set-Cookie');
37
+ const userData = response.body;
38
+ return { cookie, userData };
39
+ });
40
+ }
41
+ function signUpAdmin(id) {
42
+ // Build a JWT payload
43
+ const payload = {
44
+ id: id !== null && id !== void 0 ? id : new mongoose_1.default.Types.ObjectId().toHexString(),
45
+ email: 'test@test.com',
46
+ role: userRole_1.UserRole.Admin,
47
+ };
48
+ // Create the JWT
49
+ const token = jsonwebtoken_1.default.sign(payload, process.env.JWT_KEY);
50
+ // Build session object {jwt: MY_JWT}
51
+ const session = { jwt: token };
52
+ // Turn that session into JSON
53
+ const sessionJSON = JSON.stringify(session);
54
+ // Take JSON and encode it as base64
55
+ const base64 = Buffer.from(sessionJSON).toString('base64');
56
+ // return a string that the cookie wieht the encoded data
57
+ return [`session=${base64}`];
58
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wrcb/cb-common",
3
- "version": "1.0.57",
3
+ "version": "1.0.58",
4
4
  "description": "Common resources between services",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -22,10 +22,13 @@
22
22
  "@types/cookie-session": "^2.0.49",
23
23
  "@types/express": "^4.17.21",
24
24
  "@types/jsonwebtoken": "^9.0.6",
25
+ "@types/supertest": "^6.0.2",
25
26
  "cookie-session": "^2.1.0",
26
- "express": "^4.19.2",
27
+ "express": "^4.21.0",
27
28
  "express-validator": "^7.1.0",
28
29
  "jsonwebtoken": "^9.0.2",
29
- "node-nats-streaming": "^0.3.2"
30
+ "mongoose": "^8.6.3",
31
+ "node-nats-streaming": "^0.3.2",
32
+ "supertest": "^7.0.0"
30
33
  }
31
34
  }