itrm-tools 1.3.5-beta.1 → 1.3.5-beta.3

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.
Files changed (158) hide show
  1. package/README.md +2 -2
  2. package/dist/api/APIService.js +6 -2
  3. package/dist/api/APIService.js.map +1 -1
  4. package/dist/api/express/ExpressStandardConfiguration.d.ts +1 -1
  5. package/dist/api/express/ExpressStandardConfiguration.js +9 -1
  6. package/dist/api/express/ExpressStandardConfiguration.js.map +1 -1
  7. package/dist/api/external/ExternalApiConnection.d.ts +13 -0
  8. package/dist/api/external/ExternalApiConnection.js +24 -0
  9. package/dist/api/external/ExternalApiConnection.js.map +1 -0
  10. package/dist/api/external/cetus/CetusStrategyApiManager.d.ts +4 -3
  11. package/dist/api/external/cetus/CetusStrategyApiManager.js +4 -4
  12. package/dist/api/external/cetus/CetusStrategyApiManager.js.map +1 -1
  13. package/dist/api/request/RequestAxiosCall.d.ts +4 -4
  14. package/dist/api/request/RequestAxiosCall.js.map +1 -1
  15. package/dist/api/request/crud/CrudManager.d.ts +2 -2
  16. package/dist/api/request/crud/CrudServiceManager.d.ts +5 -5
  17. package/dist/api/request/crud/CrudServiceManager.js.map +1 -1
  18. package/dist/api/request/crud/common/ActivityHistoryManager.d.ts +40 -0
  19. package/dist/api/request/crud/common/ActivityHistoryManager.js +69 -0
  20. package/dist/api/request/crud/common/ActivityHistoryManager.js.map +1 -0
  21. package/dist/api/request/crud/common/ApplicationManager.d.ts +39 -0
  22. package/dist/api/request/crud/common/ApplicationManager.js +57 -0
  23. package/dist/api/request/crud/common/ApplicationManager.js.map +1 -0
  24. package/dist/api/request/crud/common/AvailablePlatformManager.d.ts +39 -0
  25. package/dist/api/request/crud/common/AvailablePlatformManager.js +69 -0
  26. package/dist/api/request/crud/common/AvailablePlatformManager.js.map +1 -0
  27. package/dist/api/request/crud/common/ComponentManager.d.ts +56 -0
  28. package/dist/api/request/crud/common/ComponentManager.js +63 -0
  29. package/dist/api/request/crud/common/ComponentManager.js.map +1 -0
  30. package/dist/api/request/crud/common/KeyManager.d.ts +42 -0
  31. package/dist/api/request/crud/common/KeyManager.js +70 -0
  32. package/dist/api/request/crud/common/KeyManager.js.map +1 -0
  33. package/dist/api/request/crud/common/PlatformManager.d.ts +44 -0
  34. package/dist/api/request/crud/common/PlatformManager.js +60 -0
  35. package/dist/api/request/crud/common/PlatformManager.js.map +1 -0
  36. package/dist/api/request/crud/common/RoleManager.d.ts +51 -0
  37. package/dist/api/request/crud/common/RoleManager.js +57 -0
  38. package/dist/api/request/crud/common/RoleManager.js.map +1 -0
  39. package/dist/api/request/crud/common/StatusManager.d.ts +34 -0
  40. package/dist/api/request/crud/common/StatusManager.js +57 -0
  41. package/dist/api/request/crud/common/StatusManager.js.map +1 -0
  42. package/dist/api/request/crud/common/TypeManager.d.ts +33 -0
  43. package/dist/api/request/crud/common/TypeManager.js +57 -0
  44. package/dist/api/request/crud/common/TypeManager.js.map +1 -0
  45. package/dist/api/request/crud/common/UserCredentialsManager.d.ts +39 -0
  46. package/dist/api/request/crud/common/UserCredentialsManager.js +67 -0
  47. package/dist/api/request/crud/common/UserCredentialsManager.js.map +1 -0
  48. package/dist/api/request/crud/common/UserManager.d.ts +35 -0
  49. package/dist/api/request/crud/common/UserManager.js +63 -0
  50. package/dist/api/request/crud/common/UserManager.js.map +1 -0
  51. package/dist/api/request/docs/DocumentationModels.d.ts +4 -4
  52. package/dist/api/request/docs/DocumentationModels.js.map +1 -1
  53. package/dist/cryptography/CipheringAlgorithm.d.ts +4 -0
  54. package/dist/cryptography/CipheringAlgorithm.js +3 -0
  55. package/dist/cryptography/CipheringAlgorithm.js.map +1 -0
  56. package/dist/cryptography/EncryptionAlgorithm.js.map +1 -0
  57. package/dist/cryptography/KeyGenerator.d.ts +3 -0
  58. package/dist/cryptography/KeyGenerator.js +3 -0
  59. package/dist/cryptography/KeyGenerator.js.map +1 -0
  60. package/dist/cryptography/Signer.d.ts +4 -0
  61. package/dist/cryptography/Signer.js +3 -0
  62. package/dist/cryptography/Signer.js.map +1 -0
  63. package/dist/cryptography/algorithm/AesCipheringAlgorithm.d.ts +6 -0
  64. package/dist/cryptography/algorithm/AesCipheringAlgorithm.js +28 -0
  65. package/dist/cryptography/algorithm/AesCipheringAlgorithm.js.map +1 -0
  66. package/dist/cryptography/generate/StandardApiKeyGenerator.d.ts +9 -0
  67. package/dist/cryptography/generate/StandardApiKeyGenerator.js +18 -0
  68. package/dist/cryptography/generate/StandardApiKeyGenerator.js.map +1 -0
  69. package/dist/cryptography/sign/ApiKeySigner.d.ts +14 -0
  70. package/dist/cryptography/sign/ApiKeySigner.js +35 -0
  71. package/dist/cryptography/sign/ApiKeySigner.js.map +1 -0
  72. package/dist/database/mongoose/MongooseModelManager.d.ts +40 -8
  73. package/dist/index.d.ts +17 -2
  74. package/dist/index.js +32 -3
  75. package/dist/index.js.map +1 -1
  76. package/package.json +75 -68
  77. package/.github/workflows/node.js.yml +0 -30
  78. package/dist/algorithm/encryption/EncryptionAlgorithm.js.map +0 -1
  79. package/dist/api/external/ExternalApiSigner.d.ts +0 -15
  80. package/dist/api/external/ExternalApiSigner.js +0 -25
  81. package/dist/api/external/ExternalApiSigner.js.map +0 -1
  82. package/jest.config.js +0 -7
  83. package/sequelize.sqlite +0 -0
  84. package/src/algorithm/encryption/EncryptionAlgorithm.ts +0 -4
  85. package/src/api/APIRequest.ts +0 -176
  86. package/src/api/APIRequestBuilder.ts +0 -28
  87. package/src/api/APIRouter.ts +0 -26
  88. package/src/api/APIService.ts +0 -117
  89. package/src/api/ExpressConfiguration.ts +0 -5
  90. package/src/api/HttpsAPIService.ts +0 -35
  91. package/src/api/alegra/AlegraConnectionManager.ts +0 -54
  92. package/src/api/alegra/AlegraTypes.ts +0 -150
  93. package/src/api/builder/StandardGetRequestBuilder.ts +0 -34
  94. package/src/api/channel/ServerSentEventsManager.ts +0 -28
  95. package/src/api/check/APIChecker.ts +0 -50
  96. package/src/api/check/CheckableAPIRequest.ts +0 -33
  97. package/src/api/check/CheckableAPIRouter.ts +0 -39
  98. package/src/api/check/request/CheckableDeleteRequest.ts +0 -17
  99. package/src/api/check/request/CheckableFileUploadingPostRequest.ts +0 -26
  100. package/src/api/check/request/CheckableGetRequest.ts +0 -17
  101. package/src/api/check/request/CheckablePostRequest.ts +0 -17
  102. package/src/api/check/request/CheckablePutRequest.ts +0 -17
  103. package/src/api/check/route/CorsCheckApiRouter.ts +0 -22
  104. package/src/api/check/route/SimpleCheckableAPIRouter.ts +0 -14
  105. package/src/api/express/ExpressFileUploadingConfiguration.ts +0 -22
  106. package/src/api/express/ExpressLogableConfig.ts +0 -11
  107. package/src/api/express/ExpressStandardConfiguration.ts +0 -25
  108. package/src/api/external/ExternalApiSigner.ts +0 -29
  109. package/src/api/external/cetus/CetusStrategyApiManager.ts +0 -48
  110. package/src/api/request/DeleteRequest.ts +0 -16
  111. package/src/api/request/GetRequest.ts +0 -16
  112. package/src/api/request/PostRequest.ts +0 -16
  113. package/src/api/request/PutRequest.ts +0 -16
  114. package/src/api/request/RequestAxiosCall.ts +0 -38
  115. package/src/api/request/crud/CrudManager.ts +0 -11
  116. package/src/api/request/crud/CrudServiceManager.ts +0 -117
  117. package/src/api/request/docs/DocumentationModels.ts +0 -121
  118. package/src/api/request/docs/DocumentationRequest.ts +0 -132
  119. package/src/api/route/SimpleAPIRouter.ts +0 -12
  120. package/src/database/mongoose/MongooseModelManager.ts +0 -65
  121. package/src/database/redis/RedisConnection.ts +0 -18
  122. package/src/database/redis/RedisModelManager.ts +0 -23
  123. package/src/database/sequelize/SequelizeConnection.ts +0 -45
  124. package/src/database/sequelize/SequelizeModelManager.ts +0 -71
  125. package/src/index.ts +0 -51
  126. package/src/log/Logger.ts +0 -27
  127. package/src/log/LoggerManager.ts +0 -50
  128. package/src/log/LoggerWebSocket.ts +0 -13
  129. package/src/math/Utils.ts +0 -4
  130. package/src/types/payments.ts +0 -811
  131. package/src/web3/Coin.ts +0 -18
  132. package/src/web3/coingecko/CoingeckoPriceFinder.ts +0 -75
  133. package/test/api/APIRouter.test.ts +0 -78
  134. package/test/api/APIService.test.ts +0 -50
  135. package/test/api/APITestDefinitions.ts +0 -7
  136. package/test/api/CORS.test.ts +0 -56
  137. package/test/api/alegra/AlegraConnectionManager.test.ts +0 -32
  138. package/test/api/check/CheckDefinitions.ts +0 -47
  139. package/test/api/check/CheckableAPIRouter.test.ts +0 -67
  140. package/test/api/check/CheckableDeleteRequest.test.ts +0 -92
  141. package/test/api/check/CheckableGetRequest.test.ts +0 -99
  142. package/test/api/check/CheckablePostRequest.test.ts +0 -108
  143. package/test/api/check/CheckablePutRequest.test.ts +0 -99
  144. package/test/api/docs/DocumentationRequest.test.ts +0 -192
  145. package/test/api/request/DeleteRequest.test.ts +0 -117
  146. package/test/api/request/GetRequest.test.ts +0 -140
  147. package/test/api/request/PostRequest.test.ts +0 -237
  148. package/test/api/request/PutRequest.test.ts +0 -166
  149. package/test/database/mongoose/MongooseModelManager.test.ts +0 -139
  150. package/test/database/redis/RedisConnection.test.ts +0 -7
  151. package/test/database/sequelize/SequealizeDefinitions.ts +0 -6
  152. package/test/database/sequelize/SequelizeConnection.test.ts +0 -30
  153. package/test/database/sequelize/SequelizeModelManager.test.ts +0 -206
  154. package/test/log/Logger.test.ts +0 -44
  155. package/test/web3/coingecko/CoingeckoPriceFinder.test.ts +0 -72
  156. package/tsconfig.json +0 -23
  157. /package/dist/{algorithm/encryption → cryptography}/EncryptionAlgorithm.d.ts +0 -0
  158. /package/dist/{algorithm/encryption → cryptography}/EncryptionAlgorithm.js +0 -0
@@ -1,108 +0,0 @@
1
- import { Request, Response } from "express";
2
- import { APIService, CheckablePostRequest, RequestContext, RequestAxiosCall, RequestParameterType } from "../../../dist";
3
- import { config } from "../APITestDefinitions";
4
- import { check, unexpectedErrorCheck } from "./CheckDefinitions";
5
-
6
- const service = new APIService(config);
7
- service.init();
8
-
9
- export class TestRequest extends CheckablePostRequest {
10
- constructor() {
11
- super({
12
- path: "/check",
13
- params: [{
14
- context: RequestContext.QUERY,
15
- properties: [{ name: "key", type: RequestParameterType.STRING }]
16
- }]
17
- });
18
- }
19
-
20
- public getCheckConfiguration() {
21
- return {
22
- key: 'valid'
23
- };
24
- }
25
-
26
- public async apply(req: Request, res: Response): Promise<any> {
27
- return res.status(200).json({ message: 'Success' });
28
- }
29
- }
30
-
31
- export class InvalidCheckConfigurationTestRequest extends CheckablePostRequest {
32
- constructor() {
33
- super({
34
- path: "/invalid-check",
35
- params: [{
36
- context: RequestContext.QUERY,
37
- properties: [{ name: "key", type: RequestParameterType.STRING }]
38
- }]
39
- });
40
- }
41
-
42
- public getCheckConfiguration() { // invalid configuration
43
- return {
44
- password: 'valid'
45
- };
46
- }
47
-
48
- public async apply(req: Request, res: Response): Promise<any> {
49
- return res.status(200).json({ message: 'Success' });
50
- }
51
- }
52
-
53
- const validKeyUrl = `http://localhost:${config.port}/check?key=valid`;
54
- const invalidKeyUrl = `http://localhost:${config.port}/check?key=invalid`;
55
- const invalidUnknownKeyUrl = `http://localhost:${config.port}/check?key=unknown`;
56
-
57
- describe('testing Checkable POST Request', () => {
58
- let request = new TestRequest();
59
- beforeAll(async () => {
60
- await service.run(() => { });
61
- });
62
- afterAll(async () => {
63
- await service.close(() => { })
64
- });
65
- test('Refuse request when API Request does not exist', async () => {
66
- try {
67
- await RequestAxiosCall.post(validKeyUrl, {});
68
- } catch (err: any) {
69
- //console.log("> Refuse request when API Request does not exist:", err);
70
- expect(err.code).toMatch("ERR_BAD_REQUEST");
71
- expect(err.response.status).toBe(404);
72
- expect(err.response.statusText).toMatch("Not Found");
73
- }
74
- });
75
- test('Checking valid', async () => {
76
- try {
77
- request.addCheck(check);
78
- service.addRequest(request);
79
- let response: any = await RequestAxiosCall.post(validKeyUrl, {});
80
- console.log("> Checking valid, response:", response);
81
- expect(response.message).toMatch("Success");
82
- } catch(err: any) {
83
- console.log("> Checking valid, test error:", err);
84
- }
85
- });
86
- test('Checking invalid', async () => {
87
- try {
88
- await RequestAxiosCall.post(invalidKeyUrl, {});
89
- } catch(err: any) {
90
- //console.log("> Checking invalid, test error:", err);
91
- expect(err.code).toMatch("ERR_BAD_REQUEST");
92
- expect(err.response.status).toBe(401);
93
- expect(err.response.statusText).toMatch("Unauthorized");
94
- expect(err.response.data.message).toMatch("key does not match");
95
- }
96
- });
97
- test('Checking invalid with no unauthorization reason', async () => {
98
- try {
99
- await RequestAxiosCall.post(invalidUnknownKeyUrl, {})
100
- } catch(err: any) {
101
- //console.log("> Checking invalid with no unauthorization reason, test error:", err);
102
- expect(err.code).toMatch("ERR_BAD_REQUEST");
103
- expect(err.response.status).toBe(401);
104
- expect(err.response.statusText).toMatch("Unauthorized");
105
- expect(err.response.data.message).toMatch("Unknown reason");
106
- }
107
- });
108
- });
@@ -1,99 +0,0 @@
1
- import { Request, Response } from "express";
2
- import { APIService, CheckablePutRequest, RequestContext, RequestAxiosCall, RequestParameterType } from "../../../dist";
3
- import { config } from "../APITestDefinitions";
4
- import { check, unexpectedErrorCheck } from "./CheckDefinitions";
5
-
6
- const service = new APIService(config);
7
- service.init();
8
-
9
- export class TestRequest extends CheckablePutRequest {
10
- constructor() {
11
- super({
12
- path: "/check",
13
- params: [{
14
- context: RequestContext.QUERY,
15
- properties: [{ name: "key", type: RequestParameterType.STRING }]
16
- }]
17
- });
18
- }
19
-
20
- public getCheckConfiguration() {
21
- return {
22
- key: 'valid'
23
- };
24
- }
25
-
26
- public async apply(req: Request, res: Response): Promise<any> {
27
- return res.status(200).json({ message: 'Success' });
28
- }
29
- }
30
-
31
- export class InvalidCheckConfigurationTestRequest extends CheckablePutRequest {
32
- constructor() {
33
- super({
34
- path: "/invalid-check",
35
- params: [{
36
- context: RequestContext.QUERY,
37
- properties: [{ name: "key", type: RequestParameterType.STRING }]
38
- }]
39
- });
40
- }
41
-
42
- public getCheckConfiguration() { // invalid configuration
43
- return {
44
- password: 'valid'
45
- };
46
- }
47
-
48
- public async apply(req: Request, res: Response): Promise<any> {
49
- return res.status(200).json({ message: 'Success' });
50
- }
51
- }
52
-
53
- const validKeyUrl = `http://localhost:${config.port}/check?key=valid`;
54
- const invalidKeyUrl = `http://localhost:${config.port}/check?key=invalid`;
55
- const invalidUnknownKeyUrl = `http://localhost:${config.port}/check?key=unknown`;
56
-
57
- describe('testing Checkable PUT Request', () => {
58
- let request = new TestRequest();
59
- beforeAll(async () => {
60
- await service.run(() => { });
61
- });
62
- afterAll(async () => {
63
- await service.close(() => { })
64
- });
65
- test('Refuse request when API Request does not exist', async () => {
66
- expect.assertions(3);
67
- return RequestAxiosCall.put(validKeyUrl, {}).catch(err => {
68
- expect(err.code).toMatch("ERR_BAD_REQUEST");
69
- expect(err.response.status).toBe(404);
70
- expect(err.response.statusText).toMatch("Not Found");
71
- });
72
- });
73
- test('Checking valid', async () => {
74
- expect.assertions(1);
75
- request.addCheck(check);
76
- await service.addRequest(request);
77
- return RequestAxiosCall.put(validKeyUrl, {}).then(async (response: any) => {
78
- expect(response.message).toMatch("Success");
79
- });
80
- });
81
- test('Checking invalid', async () => {
82
- expect.assertions(4);
83
- return RequestAxiosCall.put(invalidKeyUrl, {}).catch(err => {
84
- expect(err.code).toMatch("ERR_BAD_REQUEST");
85
- expect(err.response.status).toBe(401);
86
- expect(err.response.statusText).toMatch("Unauthorized");
87
- expect(err.response.data.message).toMatch("key does not match");
88
- });
89
- });
90
- test('Checking invalid with no unauthorization reason', async () => {
91
- expect.assertions(4);
92
- return RequestAxiosCall.put(invalidUnknownKeyUrl, {}).catch(err => {
93
- expect(err.code).toMatch("ERR_BAD_REQUEST");
94
- expect(err.response.status).toBe(401);
95
- expect(err.response.statusText).toMatch("Unauthorized");
96
- expect(err.response.data.message).toMatch("Unknown reason");
97
- });
98
- });
99
- });
@@ -1,192 +0,0 @@
1
- import { APIRequestBuilder, APIService, GetRequest, PostRequest, PutRequest, RequestAxiosCall, RequestContext, RequestParameterType, SimpleCheckableAPIRouter } from "../../../dist";
2
- import { Request, Response } from "express";
3
- import { config } from "../APITestDefinitions";
4
- import puppeteer from 'puppeteer';
5
-
6
- jest.useFakeTimers();
7
-
8
- const service = new APIService(config);
9
- service.init();
10
-
11
- class TestRequest extends GetRequest {
12
- constructor(builder: APIRequestBuilder) {
13
- super(builder.buildApiRequestConfig("/test/:method/type"));
14
- }
15
-
16
- async apply(req: Request, res: Response): Promise<any> {
17
- const { method } = req.params;
18
- const { value, option, x, y } = req.query;
19
- return res.status(200).json({ message: "Success", method: method, type: value, option: option, x: x, y: y });
20
- }
21
- }
22
-
23
- export class TestRequestBuilder extends APIRequestBuilder {
24
- constructor() {
25
- super();
26
- }
27
-
28
- public buildParams() {
29
- return [{
30
- context: RequestContext.QUERY,
31
- properties: [{ name: "value", type: RequestParameterType.STRING }]
32
- }, {
33
- context: RequestContext.QUERY,
34
- properties: [{ name: "option", type: RequestParameterType.STRING }]
35
- }, {
36
- context: RequestContext.QUERY,
37
- properties: [
38
- { name: "x", type: RequestParameterType.STRING },
39
- { name: "y", type: RequestParameterType.STRING }
40
- ]
41
- }, {
42
- context: RequestContext.PARAMS,
43
- properties: [{ name: "method", type: RequestParameterType.STRING }]
44
- }, {
45
- context: RequestContext.HEADERS,
46
- properties: [{ name: "x-header", type: RequestParameterType.STRING }]
47
- }
48
- ];
49
- }
50
-
51
- public buildDocDetails() {
52
- return {
53
- description: "Get Request",
54
- samples: [{
55
- status: 200,
56
- input: { x: 5, y: 2 },
57
- output: {
58
- message: "hola cómo estás"
59
- }
60
- }, {
61
- status: 400,
62
- input: { x: 5 },
63
- output: {
64
- message: "Falta la y",
65
- error: "Missing parameters",
66
- }
67
- }]
68
- }
69
- }
70
-
71
- public buildApiRequestConfig(path: string) {
72
- return {
73
- path: path,
74
- params: this.buildParams(),
75
- details: this.buildDocDetails()
76
- }
77
- }
78
- }
79
-
80
- class TestPostRequest extends PostRequest {
81
- constructor() {
82
- super({
83
- path: '/test/:method/type',
84
- params: [{
85
- context: RequestContext.BODY,
86
- properties: [{ name: "value", type: RequestParameterType.OBJECT }]
87
- }, {
88
- context: RequestContext.QUERY,
89
- properties: [{ name: "option", type: RequestParameterType.STRING }]
90
- }, {
91
- context: RequestContext.QUERY,
92
- properties: [
93
- { name: "x", type: RequestParameterType.STRING },
94
- { name: "y", type: RequestParameterType.STRING }
95
- ]
96
- }, {
97
- context: RequestContext.PARAMS,
98
- properties: [{ name: "method", type: RequestParameterType.STRING }]
99
- }, {
100
- context: RequestContext.BODY,
101
- properties: [{ name: "date", type: RequestParameterType.STRING }]
102
- }, {
103
- context: RequestContext.BODY,
104
- properties: [
105
- { name: "time", type: RequestParameterType.STRING },
106
- { name: "timestamp", type: RequestParameterType.NUMBER }
107
- ]
108
- }]
109
- });
110
- }
111
-
112
- async apply(req: Request, res: Response): Promise<any> {
113
- const { method } = req.params;
114
- const { value, option, x, y } = req.query;
115
- const { date, time, timestamp, values } = req.body;
116
- return res.status(200).json({ message: "Success", method: method, type: value, option: option, date: date, time: time, x: x, y: y, timestamp: timestamp, values: values });
117
- }
118
- }
119
-
120
- class TestPutRequest extends PutRequest {
121
- constructor() {
122
- super({
123
- path: '/test/:method',
124
- params: [{
125
- context: RequestContext.QUERY,
126
- properties: [{ name: "value", type: RequestParameterType.STRING }]
127
- }, {
128
- context: RequestContext.QUERY,
129
- properties: [{ name: "option", type: RequestParameterType.STRING }]
130
- }, {
131
- context: RequestContext.QUERY,
132
- properties: [
133
- { name: "x", type: RequestParameterType.STRING },
134
- { name: "y", type: RequestParameterType.STRING }
135
- ]
136
- }, {
137
- context: RequestContext.PARAMS,
138
- properties: [{ name: "method", type: RequestParameterType.STRING }]
139
- }, {
140
- context: RequestContext.BODY,
141
- properties: [{ name: "date", type: RequestParameterType.STRING }]
142
- }],
143
- });
144
- }
145
-
146
- async apply(req: Request, res: Response): Promise<any> {
147
- const { method } = req.params;
148
- const { value, option, x, y } = req.query;
149
- const { date, time, timestamp, values } = req.body;
150
- return res.status(200).json({ message: "Success", method: method, type: value, option: option, date: date, time: time, x: x, y: y, timestamp: timestamp, values: values });
151
- }
152
- }
153
-
154
- const router = new SimpleCheckableAPIRouter("/route");
155
-
156
- router.init();
157
- router.addRequest(new TestRequest(new TestRequestBuilder()));
158
- router.addRequest(new TestPostRequest());
159
- router.addRequest(new TestPutRequest());
160
-
161
- service.addRouter(router);
162
-
163
- service.enableDocumentation();
164
-
165
- const swaggerUrl = `http://localhost:${config.port}/api-docs`;
166
-
167
- describe('Testing Documentation', () => {
168
- beforeAll(async () => {
169
- await service.run(() => { });
170
- });
171
- afterAll(async () => {
172
- await service.close(() => { })
173
- });
174
- test('Testing JSON', async () => {
175
- // expect.assertions(1);
176
- return RequestAxiosCall.get(swaggerUrl).then((response: any) => {
177
- console.log("get");
178
- });
179
- });
180
- // jest.setTimeout(300000);
181
- // test('Testing Swagger UI', async () => {
182
- // const browser = await puppeteer.launch({ headless: false });
183
- // const page = await browser.newPage();
184
- // await page.goto(`http://localhost:${config.port}/api-docs`);
185
- // // await browser.close();
186
- // await new Promise(r => setTimeout(r, 300000));
187
- // return RequestAxiosCall.get(swaggerUrl).then((response: any) => {
188
- // console.log(response);
189
- // });
190
- // });
191
- });
192
-
@@ -1,117 +0,0 @@
1
- import { Request, Response } from "express";
2
- import { RequestContext, DeleteRequest, APIService, RequestAxiosCall, RequestParameterType } from "../../../dist";
3
- import { config } from "../APITestDefinitions";
4
-
5
- const service = new APIService(config);
6
- service.init();
7
-
8
- class TestRequest extends DeleteRequest {
9
- constructor() {
10
- super({
11
- path: '/test/:method/type',
12
- params: [{
13
- context: RequestContext.QUERY,
14
- properties: [{ name: "value", type: RequestParameterType.STRING }]
15
- }, {
16
- context: RequestContext.QUERY,
17
- properties: [{ name: "option", type: RequestParameterType.STRING }]
18
- }, {
19
- context: RequestContext.QUERY,
20
- properties: [
21
- { name: "x", type: RequestParameterType.STRING },
22
- { name: "y", type: RequestParameterType.STRING }
23
- ]
24
- }, {
25
- context: RequestContext.PARAMS,
26
- properties: [{ name: "method", type: RequestParameterType.STRING }]
27
- }]
28
- });
29
- }
30
-
31
- async apply(req: Request, res: Response): Promise<any> {
32
- const { method } = req.params;
33
- const { value, option, x, y } = req.query;
34
- return res.status(200).json({ message: "Success", method: method, type: value, option: option, x: x, y: y });
35
- }
36
- }
37
-
38
- class UnexpectedErrorTestRequest extends DeleteRequest {
39
- constructor() {
40
- super({
41
- path: '/test/error',
42
- params: []
43
- });
44
- }
45
-
46
- async apply(req: Request, res: Response): Promise<any> {
47
- throw 'Unexpected error';
48
- }
49
- }
50
-
51
- const testUrl = `http://localhost:${config.port}/test/testing/type?value=get`;
52
- const testUrl2 = `http://localhost:${config.port}/test/testing/type?option=1`;
53
- const testUrl3 = `http://localhost:${config.port}/test/testing/type?x=10&y=20`;
54
- const testUrlMissingQuery = `http://localhost:${config.port}/test/testing/type`;
55
- const testUrlUnexpectedError = `http://localhost:${config.port}/test/error`;
56
-
57
- describe('testing GET Request', () => {
58
- beforeAll(async () => {
59
- await service.run(() => { });
60
- });
61
- afterAll(async () => {
62
- await service.close(() => { })
63
- });
64
- test('Refuse request when API Request does not exist', async () => {
65
- expect.assertions(3);
66
- return RequestAxiosCall.delete(testUrl).catch(err => {
67
- expect(err.code).toMatch("ERR_BAD_REQUEST");
68
- expect(err.response.status).toBe(404);
69
- expect(err.response.statusText).toMatch("Not Found");
70
- });
71
- });
72
- test('Request Query Ok parameter group 1', async () => {
73
- await service.addRequest(new TestRequest());
74
- let response: any = await RequestAxiosCall.delete(testUrl);
75
- expect(response.message).toMatch("Success");
76
- expect(response.method).toMatch("testing");
77
- expect(response.type).toMatch("get");
78
- expect(response.option).toBeUndefined();
79
- expect(response.x).toBeUndefined();
80
- expect(response.y).toBeUndefined();
81
- });
82
- test('Request Query Ok parameter group 2', async () => {
83
- expect.assertions(6);
84
- await service.addRequest(new TestRequest());
85
- return RequestAxiosCall.delete(testUrl2).then(async (response: any) => {
86
- expect(response.message).toMatch("Success");
87
- expect(response.method).toMatch("testing");
88
- expect(response.type).toBeUndefined();
89
- expect(response.option).toMatch("1");
90
- expect(response.x).toBeUndefined();
91
- expect(response.y).toBeUndefined();
92
- });
93
- });
94
- test('Request Query Ok parameter group 3', async () => {
95
- expect.assertions(6);
96
- await service.addRequest(new TestRequest());
97
- return RequestAxiosCall.delete(testUrl3).then(async (response: any) => {
98
- expect(response.message).toMatch("Success");
99
- expect(response.method).toMatch("testing");
100
- expect(response.type).toBeUndefined();
101
- expect(response.option).toBeUndefined();
102
- expect(response.x).toMatch("10");
103
- expect(response.y).toMatch("20");
104
- });
105
- });
106
- test('Request Error: missing parameter in query', async () => {
107
- expect.assertions(5);
108
- service.addRequest(new TestRequest());
109
- return RequestAxiosCall.delete(testUrlMissingQuery).catch(async err => {
110
- expect(err.code).toMatch("ERR_BAD_REQUEST");
111
- expect(err.response.status).toBe(400);
112
- expect(err.response.statusText).toMatch("Bad Request");
113
- expect(err.response.data.status).toMatch("Error");
114
- expect(err.response.data.message).toMatch("Parameters 'x', 'y' were not found in query");
115
- });
116
- });
117
- });
@@ -1,140 +0,0 @@
1
- import { APIService, GetRequest, RequestContext, RequestAxiosCall, RequestParameterType } from "../../../dist";
2
- import { APIRequestBuilder } from "../../../dist/api/APIRequestBuilder";
3
- import { Request, Response } from "express";
4
- import { config } from "../APITestDefinitions";
5
-
6
- const service = new APIService(config);
7
- service.init();
8
-
9
- class TestRequest extends GetRequest {
10
- constructor(builder: APIRequestBuilder) {
11
- super(builder.buildApiRequestConfig("/test/:method/type"));
12
- }
13
-
14
- async apply(req: Request, res: Response): Promise<any> {
15
- const { method } = req.params;
16
- const { value, option, x, y } = req.query;
17
- return res.status(200).json({ message: "Success", method: method, type: value, option: option, x: x, y: y });
18
- }
19
- }
20
-
21
- export class TestRequestBuilder extends APIRequestBuilder {
22
- constructor() {
23
- super();
24
- }
25
-
26
- public buildParams() {
27
- return [{
28
- context: RequestContext.QUERY,
29
- properties: [{ name: "value", type: RequestParameterType.STRING }]
30
- }, {
31
- context: RequestContext.QUERY,
32
- properties: [{ name: "option", type: RequestParameterType.STRING }]
33
- }, {
34
- context: RequestContext.QUERY,
35
- properties: [
36
- { name: "x", type: RequestParameterType.STRING },
37
- { name: "y", type: RequestParameterType.STRING }
38
- ]
39
- }, {
40
- context: RequestContext.PARAMS,
41
- properties: [{ name: "method", type: RequestParameterType.STRING }]
42
- }, {
43
- context: RequestContext.PARAMS,
44
- properties: [{ name: "success", type: RequestParameterType.BOOLEAN }]
45
- }];
46
- }
47
-
48
- public buildDocDetails() {
49
- return {
50
- description: "Get Request",
51
- samples: [{
52
- status: 200,
53
- input: { x: 5, y: 2 },
54
- output: {
55
- message: "hola cómo estás"
56
- }
57
- }]
58
- }
59
- }
60
-
61
- public buildApiRequestConfig(path: string) {
62
- return {
63
- path: path,
64
- params: this.buildParams(),
65
- details: this.buildDocDetails()
66
- }
67
- }
68
- }
69
-
70
- const testRequest = new TestRequest(new TestRequestBuilder());
71
-
72
- const testUrl = `http://localhost:${config.port}/test/testing/type?value=get`;
73
- const testUrl2 = `http://localhost:${config.port}/test/testing/type?option=1`;
74
- const testUrl3 = `http://localhost:${config.port}/test/testing/type?x=10&y=20`;
75
- const testUrlMissingQuery = `http://localhost:${config.port}/test/testing/type`;
76
- const testUrlUnexpectedError = `http://localhost:${config.port}/test/error`;
77
-
78
- describe('testing GET Request', () => {
79
- beforeAll(async () => {
80
- await service.run(() => { });
81
- });
82
- afterAll(async () => {
83
- await service.close(() => { })
84
- });
85
- test('Refuse request when API Request does not exist', async () => {
86
- expect.assertions(3);
87
- return RequestAxiosCall.get(testUrl).catch(err => {
88
- expect(err.code).toMatch("ERR_BAD_REQUEST");
89
- expect(err.response.status).toBe(404);
90
- expect(err.response.statusText).toMatch("Not Found");
91
- });
92
- });
93
- test('Request Query Ok parameter group 1', async () => {
94
- expect.assertions(6);
95
- await service.addRequest(testRequest);
96
- return RequestAxiosCall.get(testUrl).then(async (response: any) => {
97
- expect(response.message).toMatch("Success");
98
- expect(response.method).toMatch("testing");
99
- expect(response.type).toMatch("get");
100
- expect(response.option).toBeUndefined();
101
- expect(response.x).toBeUndefined();
102
- expect(response.y).toBeUndefined();
103
- });
104
- });
105
- test('Request Query Ok parameter group 2', async () => {
106
- expect.assertions(6);
107
- await service.addRequest(testRequest);
108
- return RequestAxiosCall.get(testUrl2).then(async (response: any) => {
109
- expect(response.message).toMatch("Success");
110
- expect(response.method).toMatch("testing");
111
- expect(response.type).toBeUndefined();
112
- expect(response.option).toMatch("1");
113
- expect(response.x).toBeUndefined();
114
- expect(response.y).toBeUndefined();
115
- });
116
- });
117
- test('Request Query Ok parameter group 3', async () => {
118
- expect.assertions(6);
119
- await service.addRequest(testRequest);
120
- return RequestAxiosCall.get(testUrl3).then(async (response: any) => {
121
- expect(response.message).toMatch("Success");
122
- expect(response.method).toMatch("testing");
123
- expect(response.type).toBeUndefined();
124
- expect(response.option).toBeUndefined();
125
- expect(response.x).toMatch("10");
126
- expect(response.y).toMatch("20");
127
- });
128
- });
129
- test('Request Error: missing parameter in query', async () => {
130
- expect.assertions(5);
131
- service.addRequest(testRequest);
132
- return RequestAxiosCall.get(testUrlMissingQuery).catch(async err => {
133
- expect(err.code).toMatch("ERR_BAD_REQUEST");
134
- expect(err.response.status).toBe(400);
135
- expect(err.response.statusText).toMatch("Bad Request");
136
- expect(err.response.data.status).toMatch("Error");
137
- expect(err.response.data.message).toMatch("Parameters 'x', 'y' were not found in query");
138
- });
139
- });
140
- });