backend-test-tools 1.0.0

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 (187) hide show
  1. package/.env.example +51 -0
  2. package/.mocharc.js +9 -0
  3. package/.prettierrc +7 -0
  4. package/README.md +271 -0
  5. package/babel.config.json +33 -0
  6. package/dist/factory/factory.d.ts +11 -0
  7. package/dist/factory/factory.js +39 -0
  8. package/dist/factory/factory.js.map +1 -0
  9. package/dist/factory/factory.types.d.ts +38 -0
  10. package/dist/factory/factory.types.js +2 -0
  11. package/dist/factory/factory.types.js.map +1 -0
  12. package/dist/factory/index.d.ts +2 -0
  13. package/dist/factory/index.js +28 -0
  14. package/dist/factory/index.js.map +1 -0
  15. package/dist/factory/workers/connection.d.ts +3 -0
  16. package/dist/factory/workers/connection.js +25 -0
  17. package/dist/factory/workers/connection.js.map +1 -0
  18. package/dist/factory/workers/connection.types.d.ts +28 -0
  19. package/dist/factory/workers/connection.types.js +2 -0
  20. package/dist/factory/workers/connection.types.js.map +1 -0
  21. package/dist/factory/workers/index.d.ts +6 -0
  22. package/dist/factory/workers/index.js +72 -0
  23. package/dist/factory/workers/index.js.map +1 -0
  24. package/dist/factory/workers/organization.d.ts +3 -0
  25. package/dist/factory/workers/organization.js +36 -0
  26. package/dist/factory/workers/organization.js.map +1 -0
  27. package/dist/factory/workers/organization.types.d.ts +51 -0
  28. package/dist/factory/workers/organization.types.js +2 -0
  29. package/dist/factory/workers/organization.types.js.map +1 -0
  30. package/dist/factory/workers/user.d.ts +5 -0
  31. package/dist/factory/workers/user.js +60 -0
  32. package/dist/factory/workers/user.js.map +1 -0
  33. package/dist/factory/workers/user.types.d.ts +76 -0
  34. package/dist/factory/workers/user.types.js +2 -0
  35. package/dist/factory/workers/user.types.js.map +1 -0
  36. package/dist/generators/generateAccessToken.d.ts +3 -0
  37. package/dist/generators/generateAccessToken.js +27 -0
  38. package/dist/generators/generateAccessToken.js.map +1 -0
  39. package/dist/generators/generateChatId.d.ts +2 -0
  40. package/dist/generators/generateChatId.js +13 -0
  41. package/dist/generators/generateChatId.js.map +1 -0
  42. package/dist/generators/generateEcdsaKeyPair.d.ts +2 -0
  43. package/dist/generators/generateEcdsaKeyPair.js +31 -0
  44. package/dist/generators/generateEcdsaKeyPair.js.map +1 -0
  45. package/dist/generators/generateImageBuffer.d.ts +3 -0
  46. package/dist/generators/generateImageBuffer.js +23 -0
  47. package/dist/generators/generateImageBuffer.js.map +1 -0
  48. package/dist/generators/generateImageBuffer.types.d.ts +7 -0
  49. package/dist/generators/generateImageBuffer.types.js +2 -0
  50. package/dist/generators/generateImageBuffer.types.js.map +1 -0
  51. package/dist/generators/generateKeyPair.d.ts +6 -0
  52. package/dist/generators/generateKeyPair.js +36 -0
  53. package/dist/generators/generateKeyPair.js.map +1 -0
  54. package/dist/generators/generateKeyPair.types.d.ts +9 -0
  55. package/dist/generators/generateKeyPair.types.js +2 -0
  56. package/dist/generators/generateKeyPair.types.js.map +1 -0
  57. package/dist/generators/generateLocale.d.ts +5 -0
  58. package/dist/generators/generateLocale.js +16 -0
  59. package/dist/generators/generateLocale.js.map +1 -0
  60. package/dist/generators/generateRegId.d.ts +4 -0
  61. package/dist/generators/generateRegId.js +14 -0
  62. package/dist/generators/generateRegId.js.map +1 -0
  63. package/dist/generators/generateRsaKeyPair.d.ts +2 -0
  64. package/dist/generators/generateRsaKeyPair.js +22 -0
  65. package/dist/generators/generateRsaKeyPair.js.map +1 -0
  66. package/dist/generators/generateUserCrypto.d.ts +15 -0
  67. package/dist/generators/generateUserCrypto.js +33 -0
  68. package/dist/generators/generateUserCrypto.js.map +1 -0
  69. package/dist/generators/index.d.ts +9 -0
  70. package/dist/generators/index.js +105 -0
  71. package/dist/generators/index.js.map +1 -0
  72. package/dist/index.d.ts +4 -0
  73. package/dist/index.js +50 -0
  74. package/dist/index.js.map +1 -0
  75. package/dist/stubs/index.d.ts +1 -0
  76. package/dist/stubs/index.js +17 -0
  77. package/dist/stubs/index.js.map +1 -0
  78. package/dist/stubs/server-engine/Leader.types.d.ts +8 -0
  79. package/dist/stubs/server-engine/Leader.types.js +2 -0
  80. package/dist/stubs/server-engine/Leader.types.js.map +1 -0
  81. package/dist/stubs/server-engine/Localizator.d.ts +3 -0
  82. package/dist/stubs/server-engine/Localizator.js +34 -0
  83. package/dist/stubs/server-engine/Localizator.js.map +1 -0
  84. package/dist/stubs/server-engine/Localizator.types.d.ts +22 -0
  85. package/dist/stubs/server-engine/Localizator.types.js +2 -0
  86. package/dist/stubs/server-engine/Localizator.types.js.map +1 -0
  87. package/dist/stubs/server-engine/PubSub.d.ts +3 -0
  88. package/dist/stubs/server-engine/PubSub.js +24 -0
  89. package/dist/stubs/server-engine/PubSub.js.map +1 -0
  90. package/dist/stubs/server-engine/PubSub.types.d.ts +14 -0
  91. package/dist/stubs/server-engine/PubSub.types.js +2 -0
  92. package/dist/stubs/server-engine/PubSub.types.js.map +1 -0
  93. package/dist/stubs/server-engine/PushNotification.d.ts +3 -0
  94. package/dist/stubs/server-engine/PushNotification.js +18 -0
  95. package/dist/stubs/server-engine/PushNotification.js.map +1 -0
  96. package/dist/stubs/server-engine/PushNotification.types.d.ts +8 -0
  97. package/dist/stubs/server-engine/PushNotification.types.js +2 -0
  98. package/dist/stubs/server-engine/PushNotification.types.js.map +1 -0
  99. package/dist/stubs/server-engine/index.d.ts +4 -0
  100. package/dist/stubs/server-engine/index.js +50 -0
  101. package/dist/stubs/server-engine/index.js.map +1 -0
  102. package/dist/stubs/server-engine/sendPush.d.ts +3 -0
  103. package/dist/stubs/server-engine/sendPush.js +15 -0
  104. package/dist/stubs/server-engine/sendPush.js.map +1 -0
  105. package/dist/utils/generateCerts/generateCerts.const.d.ts +5 -0
  106. package/dist/utils/generateCerts/generateCerts.const.js +35 -0
  107. package/dist/utils/generateCerts/generateCerts.const.js.map +1 -0
  108. package/dist/utils/generateCerts/generateCerts.d.ts +9 -0
  109. package/dist/utils/generateCerts/generateCerts.js +108 -0
  110. package/dist/utils/generateCerts/generateCerts.js.map +1 -0
  111. package/dist/utils/generateCerts/generateCerts.types.d.ts +19 -0
  112. package/dist/utils/generateCerts/generateCerts.types.js +2 -0
  113. package/dist/utils/generateCerts/generateCerts.types.js.map +1 -0
  114. package/dist/utils/generateCerts/index.d.ts +1 -0
  115. package/dist/utils/generateCerts/index.js +17 -0
  116. package/dist/utils/generateCerts/index.js.map +1 -0
  117. package/dist/utils/getAdminApiBearer.d.ts +2 -0
  118. package/dist/utils/getAdminApiBearer.js +19 -0
  119. package/dist/utils/getAdminApiBearer.js.map +1 -0
  120. package/dist/utils/getBearer.d.ts +3 -0
  121. package/dist/utils/getBearer.js +12 -0
  122. package/dist/utils/getBearer.js.map +1 -0
  123. package/dist/utils/index.d.ts +6 -0
  124. package/dist/utils/index.js +72 -0
  125. package/dist/utils/index.js.map +1 -0
  126. package/dist/utils/jwtRequest.d.ts +9 -0
  127. package/dist/utils/jwtRequest.js +29 -0
  128. package/dist/utils/jwtRequest.js.map +1 -0
  129. package/dist/utils/staticRequest.d.ts +10 -0
  130. package/dist/utils/staticRequest.js +24 -0
  131. package/dist/utils/staticRequest.js.map +1 -0
  132. package/dist/utils/tlsRequest.d.ts +6 -0
  133. package/dist/utils/tlsRequest.js +44 -0
  134. package/dist/utils/tlsRequest.js.map +1 -0
  135. package/dist/utils/tlsRequest.types.d.ts +9 -0
  136. package/dist/utils/tlsRequest.types.js +2 -0
  137. package/dist/utils/tlsRequest.types.js.map +1 -0
  138. package/eslint.config.mjs +11 -0
  139. package/jsconfig.json +14 -0
  140. package/package.json +83 -0
  141. package/src/factory/factory.ts +51 -0
  142. package/src/factory/factory.types.ts +50 -0
  143. package/src/factory/index.ts +2 -0
  144. package/src/factory/workers/connection.ts +22 -0
  145. package/src/factory/workers/connection.types.ts +29 -0
  146. package/src/factory/workers/index.ts +6 -0
  147. package/src/factory/workers/organization.ts +35 -0
  148. package/src/factory/workers/organization.types.ts +53 -0
  149. package/src/factory/workers/user.ts +57 -0
  150. package/src/factory/workers/user.types.ts +77 -0
  151. package/src/generators/generateAccessToken.ts +24 -0
  152. package/src/generators/generateChatId.ts +6 -0
  153. package/src/generators/generateEcdsaKeyPair.ts +16 -0
  154. package/src/generators/generateImageBuffer.ts +19 -0
  155. package/src/generators/generateImageBuffer.types.ts +7 -0
  156. package/src/generators/generateKeyPair.ts +24 -0
  157. package/src/generators/generateKeyPair.types.ts +9 -0
  158. package/src/generators/generateLocale.ts +28 -0
  159. package/src/generators/generateRegId.ts +9 -0
  160. package/src/generators/generateRsaKeyPair.ts +12 -0
  161. package/src/generators/generateUserCrypto.ts +24 -0
  162. package/src/generators/index.ts +9 -0
  163. package/src/index.ts +4 -0
  164. package/src/stubs/index.ts +1 -0
  165. package/src/stubs/server-engine/Leader.types.ts +9 -0
  166. package/src/stubs/server-engine/Localizator.ts +25 -0
  167. package/src/stubs/server-engine/Localizator.types.ts +24 -0
  168. package/src/stubs/server-engine/PubSub.ts +13 -0
  169. package/src/stubs/server-engine/PubSub.types.ts +15 -0
  170. package/src/stubs/server-engine/PushNotification.ts +11 -0
  171. package/src/stubs/server-engine/PushNotification.types.ts +9 -0
  172. package/src/stubs/server-engine/index.ts +4 -0
  173. package/src/stubs/server-engine/sendPush.ts +7 -0
  174. package/src/utils/generateCerts/generateCerts.const.ts +48 -0
  175. package/src/utils/generateCerts/generateCerts.ts +108 -0
  176. package/src/utils/generateCerts/generateCerts.types.ts +21 -0
  177. package/src/utils/generateCerts/index.ts +1 -0
  178. package/src/utils/getAdminApiBearer.ts +17 -0
  179. package/src/utils/getBearer.ts +11 -0
  180. package/src/utils/index.ts +6 -0
  181. package/src/utils/jwtRequest.ts +25 -0
  182. package/src/utils/staticRequest.ts +22 -0
  183. package/src/utils/tlsRequest.ts +41 -0
  184. package/src/utils/tlsRequest.types.ts +9 -0
  185. package/test/env.ts +10 -0
  186. package/tsconfig.build.json +4 -0
  187. package/tsconfig.json +30 -0
package/.env.example ADDED
@@ -0,0 +1,51 @@
1
+ ##########
2
+ # Server #
3
+ ##########
4
+
5
+ # General server settings
6
+
7
+ # Port on which the server is served
8
+ PORT=
9
+
10
+ ######################
11
+ # JWT Authentication #
12
+ ######################
13
+
14
+ # Settings for the Json Web Token generator
15
+
16
+ # URL of the main API (token audience)
17
+ API_URL=
18
+
19
+ # Auth0 domain (token issuer)
20
+ AUTH0_DOMAIN=
21
+
22
+ # Secret used to sign tokens symmetrically
23
+ JWT_SECRET=
24
+
25
+ ######################
26
+ # TLS Authentication #
27
+ ######################
28
+
29
+ # Settings for the TLS public key infrastructure
30
+ # /!\ The tool to make tls requests does not support encrypted private keys
31
+
32
+ # Private key of the server
33
+ TLS_SERVER_KEY=
34
+
35
+ # Certificate of the server
36
+ TLS_SERVER_CERT=
37
+
38
+ # Certificate of the certifying authority
39
+ TLS_CA=
40
+
41
+ # Private key used to make a TLS request
42
+ # Defaults to the server key if not specified
43
+ TLS_REQUEST_KEY=
44
+
45
+ # Certificate used to make a TLS request
46
+ # Defaults to the server certificate if not specified
47
+ TLS_REQUEST_CERT=
48
+
49
+ # Certificate of the certifying authority used to make a TLS request
50
+ # Defaults to the server certificate of the certifying authority if not specified
51
+ TLS_REQUEST_CA=
package/.mocharc.js ADDED
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ require: ['tsconfig-paths/register', 'ts-node/register', `${process.cwd()}/test/env`],
5
+ ui: 'bdd',
6
+ reporter: 'nyan',
7
+ exit: true,
8
+ extension: ['ts'],
9
+ };
package/.prettierrc ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "semi": true,
3
+ "singleQuote": true,
4
+ "tabWidth": 2,
5
+ "printWidth": 100,
6
+ "trailingComma": "none"
7
+ }
package/README.md ADDED
@@ -0,0 +1,271 @@
1
+ # Node test tools
2
+
3
+ Tools to be used by the Node backend services for testing purpose.
4
+
5
+ ## Table of contents
6
+
7
+ - [Node test tools](#backend-test-tools)
8
+ - [Table of contents](#table-of-contents)
9
+ - [Generators](#generators)
10
+ - [Access token](#access-token)
11
+ - [Social provider](#social-provider)
12
+ - [Auth0 ID](#auth0-id)
13
+ - [Chat ID](#chat-id)
14
+ - [Locale](#locale)
15
+ - [RegId](#regid)
16
+ - [RSA Key Pair](#rsa-key-pair)
17
+ - [User public key](#user-public-key)
18
+ - [User encrypted private key](#user-encrypted-private-key)
19
+ - [User encrypted blackberry passcode](#user-encrypted-blackberry-passcode)
20
+ - [Factory](#factory)
21
+ - [Build](#build)
22
+ - [Models](#models)
23
+ - [Connection](#connection)
24
+ - [Identity](#identity)
25
+ - [Organization](#organization)
26
+ - [User](#user)
27
+ - [Utilities](#utilities)
28
+ - [TLS](#tls)
29
+ - [Certificate generation](#certificate-generation)
30
+ - [Secured request](#secured-request)
31
+ - [Json Web token](#json-web-token)
32
+ - [Bearer token](#bearer-token)
33
+ - [Token authenticated request](#token-authenticated-request)
34
+
35
+ ## Generators
36
+
37
+ Generators generate some commonly used fake data.
38
+
39
+ ### Access token
40
+
41
+ Generate an mock access token like Auth0 would do.
42
+ The payload and options can be customized if needed. Please refer to the [jsonwebtoken package](https://github.com/auth0/node-jsonwebtoken#jwtsignpayload-secretorprivatekey-options-callback "jsonwebtoken package") for documentation.
43
+ This is a self signed token that is only valid in test environment.
44
+
45
+ ```javascript
46
+ import {generateAccessToken} from 'backend-test-tools'
47
+ const accessToken = generateAccessToken(payload, options)
48
+ ```
49
+
50
+ ### Social provider
51
+
52
+ Get a random third party identity provider name.
53
+
54
+ ```javascript
55
+ import {generateAuth0Provider} from 'backend-test-tools'
56
+ const provider = generateAuth0Provider(options)
57
+ ```
58
+
59
+ Options
60
+
61
+ - **includeLocal** (Boolean): Include the provider name for users authenticating with an email/password combination. (default: false)
62
+
63
+ ### Auth0 ID
64
+
65
+ Generate a fake auth0 ID.
66
+
67
+ ```javascript
68
+ import {generateAuth0UserId} from 'backend-test-tools'
69
+ const auth0Id = generateAuth0UserId(full)
70
+ ```
71
+
72
+ - **full** (Boolean): prefix the provider name to the ID to create a full auth0 ID also known as externalID. (default: false)
73
+
74
+ ### Chat ID
75
+
76
+ Get a random BlackBerry Spark chat ID
77
+
78
+ ```javascript
79
+ import {generateChatId} from 'backend-test-tools'
80
+ const chatId = generateChatId()
81
+ ```
82
+
83
+ ### Locale
84
+
85
+ Get a random locale from the ones available.
86
+
87
+ ```javascript
88
+ import {generateLocale} from 'backend-test-tools'
89
+ const locale = generateLocale()
90
+ ```
91
+
92
+ ### RegId
93
+
94
+ Get a random Blackberry Spark regId.
95
+
96
+ ```javascript
97
+ import {generateRegId} from 'backend-test-tools'
98
+ const regId = generateRegId()
99
+ ```
100
+
101
+ ### RSA Key Pair
102
+
103
+ Get RSA key pair and save to certs folder.
104
+
105
+ Note. use on test/env.js
106
+
107
+ ```javascript
108
+ import {generateRsaKeyPair} from 'backend-test-tools'
109
+ generateRsaKeyPair()
110
+ ```
111
+
112
+ ### User public key
113
+
114
+ Get a fake base64 string that looks like a user public key.
115
+ /!\ This is not a valid crypto key
116
+
117
+ ```javascript
118
+ import {generateSignKeyPub} from 'backend-test-tools'
119
+ const signKeyPub = generateSignKeyPub()
120
+ ```
121
+
122
+ ### User encrypted private key
123
+
124
+ Get a fake base64 string that looks like a user encrypted private key.
125
+ /!\ This is not a valid crypto key
126
+
127
+ ```javascript
128
+ import {generateSignKeyEncrypted} from 'backend-test-tools'
129
+ const signKeyEncrypted = generateSignKeyEncrypted()
130
+ ```
131
+
132
+ ### User encrypted blackberry passcode
133
+
134
+ Get a fake base64 string that looks like a user encrypted Blackberry passcode.
135
+ /!\ This is not a valid crypto key
136
+
137
+ ```javascript
138
+ import {generateBbEncrypted} from 'backend-test-tools'
139
+ const bbEncrypted = generateBbEncrypted()
140
+ ```
141
+
142
+ ## Factory
143
+
144
+ Factory functions generate commonly used entities.
145
+ They are heavily inspired by [factory-girl](https://github.com/simonexmachina/factory-girl#readme "factory-girl") and the worker functions are fully compatible with it.
146
+
147
+ ### Build
148
+
149
+ Build an object according to a model.
150
+
151
+ ```javascript
152
+ import {factory} from 'backend-test-tools'
153
+ const model = factory.build(name, attributes, buildOptions)
154
+ const models = factory.buildMany(name, count, attributes, buildOptions)
155
+ ```
156
+
157
+ - **name**: Name of the model to user.
158
+ - **count**: Number of objects to generate.
159
+ - **attributes**: Override the value of some of the object's attributes.
160
+ - **buildOptions**: Options passed to the workers.
161
+
162
+ ### Models
163
+
164
+ #### Connection
165
+
166
+ ```javascript
167
+ import {factory} from 'backend-test-tools'
168
+ const buildOptions = {
169
+ accepted: true,
170
+ blocked: false
171
+ }
172
+ const model = factory.build('connection', undefined, buildOptions)
173
+ ```
174
+
175
+ - **accepted**: Will set the connection as accepted, and set the acceptedAt accordingly.
176
+ - **blocked**: Will set the connection as blocked, and set the blockedAt accordingly.
177
+
178
+ #### Identity
179
+
180
+ ```javascript
181
+ import {factory} from 'backend-test-tools'
182
+ const model = factory.build('identity')
183
+ ```
184
+
185
+ #### Organization
186
+
187
+ ```javascript
188
+ import {factory} from 'backend-test-tools'
189
+ const model = factory.build('organization')
190
+ ```
191
+
192
+ #### User
193
+
194
+ ```javascript
195
+ import {factory} from 'backend-test-tools'
196
+ const buildOptions = {
197
+ firstName: John,
198
+ lastName: Doe,
199
+ organizationId: '51f0ac7a-4b79-485f-9a0f-a0eb7a5d8aa8',
200
+ admin: false,
201
+ member: false,
202
+ moreRandom: false
203
+ }
204
+ const model = factory.build('user', undefined, buildOptions)
205
+ ```
206
+
207
+ - **firstName**: First name of the user, will also define all the variations of name.
208
+ - **lastName**: Last name of the user, will also define all the variations of name.
209
+ - **organizationId**: Id of the organization to which the user is related. Will define the date at which he joined.
210
+ - **admin**: User is admin of the organization.
211
+ - **member**: User is a member of the organization.
212
+ - **moreRandom**: Adds randomness to unique fields to avoid collisions when building a large number of objects.
213
+
214
+ ## Utilities
215
+
216
+ Utility functions that bring some convenience when writing tests.
217
+
218
+ ### TLS
219
+
220
+ #### Certificate generation
221
+
222
+ To replicate a PKI (Public Key Infrastructure), a CA certificate is needed as well as client and server cert2ificates and private keys.
223
+
224
+ ```javascript
225
+ import {generatePkiEnvironment} from 'backend-test-tools'
226
+ generatePkiEnvironment()
227
+ ```
228
+
229
+ This will right all the required certificates and keys at the root of the project in a directory called `certs`.
230
+
231
+ #### Secured request
232
+
233
+ The function `tlsRequest` is a wrapper around the [supertest](https://github.com/visionmedia/supertest "supertest") library that adds the required parameters for performing a tls request.
234
+
235
+ ```javascript
236
+ import {tlsRequest} from 'backend-test-tools'
237
+ tlsRequest(options)
238
+ .get('/test')
239
+ .expect(200);
240
+ ```
241
+
242
+ options
243
+
244
+ - **ca**: Override the default CA
245
+ - **key**: Override the default private key
246
+ - **cert**: Override the default certificate
247
+
248
+ ### Json Web token
249
+
250
+ #### Bearer token
251
+
252
+ This function generates a bearer token for a given user, it can therefore conveniently be added as authorization during tests.
253
+
254
+ ```javascript
255
+ import {getBearer} from 'backend-test-tools'
256
+ const authorization = getBearer(user, payload);
257
+ ```
258
+
259
+ - **user**: The user making the request
260
+ - **payload**: Data to include in the JWT payload
261
+
262
+ #### Token authenticated request
263
+
264
+ The function `jwtRequest` is a wrapper around the [supertest](https://github.com/visionmedia/supertest "supertest") library that adds the required parameters for performing a request authenticated by the bearer JWT of a specified user.
265
+
266
+ ```javascript
267
+ import {jwtRequest} from 'backend-test-tools'
268
+ jwtRequest(app, user)
269
+ .get('/test')
270
+ .expect(200);
271
+ ```
@@ -0,0 +1,33 @@
1
+ {
2
+ "presets": [
3
+ "@babel/preset-typescript",
4
+ [
5
+ "@babel/preset-env",
6
+ {
7
+ "targets": { "node": 20 },
8
+ "useBuiltIns": "entry",
9
+ "corejs": 3
10
+ }
11
+ ]
12
+ ],
13
+ "plugins": [
14
+ [
15
+ "module-resolver",
16
+ {
17
+ "root": "src",
18
+ "alias": {
19
+ "test": "test"
20
+ },
21
+ "extensions": [".js", ".ts"]
22
+ }
23
+ ],
24
+ "@babel/plugin-transform-class-properties",
25
+ "@babel/plugin-transform-classes",
26
+ "@babel/plugin-transform-runtime"
27
+ ],
28
+ "env": {
29
+ "test": {
30
+ "plugins": ["istanbul"]
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,11 @@
1
+ import { FactoryModel, FactoryBuildOptions, FactoryModelOverride, FactoryReturnType } from './factory.types';
2
+ export declare const factory: {
3
+ /**
4
+ * Build an object according to a defined model
5
+ */
6
+ build: <T extends FactoryModel>(name: T, attributes?: FactoryModelOverride<T>, buildOptions?: FactoryBuildOptions<T>) => FactoryReturnType<T>;
7
+ /**
8
+ * Build multiple objects according to a defined model
9
+ */
10
+ buildMany: <T extends FactoryModel>(name: T, count: number, attributes?: FactoryModelOverride<T>, buildOptions?: FactoryBuildOptions<T>) => Array<FactoryReturnType<T>>;
11
+ };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.factory = void 0;
7
+ var _crypto = require("crypto");
8
+ var _workers = require("./workers");
9
+ const modelsMap = {
10
+ connection: _workers.connectionFactoryWorker,
11
+ organization: _workers.organizationFactoryWorker,
12
+ user: _workers.userFactoryWorker
13
+ };
14
+ const factory = exports.factory = {
15
+ /**
16
+ * Build an object according to a defined model
17
+ */
18
+ build: function (name, attributes = {}, buildOptions = {}) {
19
+ if (!Object.keys(modelsMap).includes(name)) throw new Error(`Factory: unknown model "${name}"`);
20
+ const worker = modelsMap[name];
21
+ const instance = worker(buildOptions);
22
+ return {
23
+ id: (0, _crypto.randomUUID)(),
24
+ ...instance,
25
+ ...attributes
26
+ };
27
+ },
28
+ /**
29
+ * Build multiple objects according to a defined model
30
+ */
31
+ buildMany: function (name, count, attributes = {}, buildOptions = {}) {
32
+ const instances = [];
33
+ for (let i = 0; i < count; i++) {
34
+ instances.push(this.build(name, attributes, buildOptions));
35
+ }
36
+ return instances;
37
+ }
38
+ };
39
+ //# sourceMappingURL=factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.js","names":["_crypto","require","_workers","modelsMap","connection","connectionFactoryWorker","organization","organizationFactoryWorker","user","userFactoryWorker","factory","exports","build","name","attributes","buildOptions","Object","keys","includes","Error","worker","instance","id","randomUUID","buildMany","count","instances","i","push"],"sources":["../../src/factory/factory.ts"],"sourcesContent":["import {randomUUID} from 'crypto';\nimport {\n FactoryModel,\n FactoryBuildOptions,\n FactoryModelOverride,\n FactoryReturnType,\n ModelsMap,\n} from './factory.types';\nimport {connectionFactoryWorker, organizationFactoryWorker, userFactoryWorker} from './workers';\n\nconst modelsMap: ModelsMap = {\n connection: connectionFactoryWorker,\n organization: organizationFactoryWorker,\n user: userFactoryWorker,\n};\n\nexport const factory = {\n /**\n * Build an object according to a defined model\n */\n build: function <T extends FactoryModel>(\n name: T,\n attributes: FactoryModelOverride<T> = {},\n buildOptions: FactoryBuildOptions<T> = {},\n ): FactoryReturnType<T> {\n if (!Object.keys(modelsMap).includes(name)) throw new Error(`Factory: unknown model \"${name}\"`);\n const worker = modelsMap[name];\n const instance = worker(buildOptions);\n return {\n id: randomUUID(),\n ...instance,\n ...attributes,\n };\n },\n\n /**\n * Build multiple objects according to a defined model\n */\n buildMany: function <T extends FactoryModel>(\n name: T,\n count: number,\n attributes: FactoryModelOverride<T> = {},\n buildOptions: FactoryBuildOptions<T> = {},\n ): Array<FactoryReturnType<T>> {\n const instances: Array<FactoryReturnType<T>> = [];\n for (let i = 0; i < count; i++) {\n instances.push(this.build(name, attributes, buildOptions));\n }\n return instances;\n },\n};\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAQA,IAAAC,QAAA,GAAAD,OAAA;AAEA,MAAME,SAAoB,GAAG;EAC3BC,UAAU,EAAEC,gCAAuB;EACnCC,YAAY,EAAEC,kCAAyB;EACvCC,IAAI,EAAEC;AACR,CAAC;AAEM,MAAMC,OAAO,GAAAC,OAAA,CAAAD,OAAA,GAAG;EACrB;AACF;AACA;EACEE,KAAK,EAAE,SAAAA,CACLC,IAAO,EACPC,UAAmC,GAAG,CAAC,CAAC,EACxCC,YAAoC,GAAG,CAAC,CAAC,EACnB;IACtB,IAAI,CAACC,MAAM,CAACC,IAAI,CAACd,SAAS,CAAC,CAACe,QAAQ,CAACL,IAAI,CAAC,EAAE,MAAM,IAAIM,KAAK,CAAC,2BAA2BN,IAAI,GAAG,CAAC;IAC/F,MAAMO,MAAM,GAAGjB,SAAS,CAACU,IAAI,CAAC;IAC9B,MAAMQ,QAAQ,GAAGD,MAAM,CAACL,YAAY,CAAC;IACrC,OAAO;MACLO,EAAE,EAAE,IAAAC,kBAAU,EAAC,CAAC;MAChB,GAAGF,QAAQ;MACX,GAAGP;IACL,CAAC;EACH,CAAC;EAED;AACF;AACA;EACEU,SAAS,EAAE,SAAAA,CACTX,IAAO,EACPY,KAAa,EACbX,UAAmC,GAAG,CAAC,CAAC,EACxCC,YAAoC,GAAG,CAAC,CAAC,EACZ;IAC7B,MAAMW,SAAsC,GAAG,EAAE;IACjD,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,KAAK,EAAEE,CAAC,EAAE,EAAE;MAC9BD,SAAS,CAACE,IAAI,CAAC,IAAI,CAAChB,KAAK,CAACC,IAAI,EAAEC,UAAU,EAAEC,YAAY,CAAC,CAAC;IAC5D;IACA,OAAOW,SAAS;EAClB;AACF,CAAC","ignoreList":[]}
@@ -0,0 +1,38 @@
1
+ import { ConnectionModel, ConnectionBuildOptions, OrganizationModel, UserModel, UserBuildOptions } from './workers';
2
+ type FactoryTyping = {
3
+ /** Mapping for the connection model */
4
+ connection: {
5
+ /** Options for the connection model */
6
+ options: ConnectionBuildOptions;
7
+ /** Return type for the connection model */
8
+ return: ConnectionModel;
9
+ };
10
+ /** Mapping for the organization model */
11
+ organization: {
12
+ /** Options for the organization model */
13
+ options: any;
14
+ /** Return type for the organization model */
15
+ return: OrganizationModel;
16
+ };
17
+ /** Mapping for the user model */
18
+ user: {
19
+ /** Options for the user model */
20
+ options: UserBuildOptions;
21
+ /** Return type for the user model */
22
+ return: UserModel;
23
+ };
24
+ };
25
+ export type FactoryModel = keyof FactoryTyping;
26
+ export type FactoryModelOverride<T extends FactoryModel> = Partial<FactoryTyping[T]['return']> & {
27
+ /** Id of the model */
28
+ id?: string;
29
+ };
30
+ export type FactoryBuildOptions<T extends FactoryModel> = FactoryTyping[T]['options'];
31
+ export type FactoryReturnType<T extends FactoryModel> = FactoryTyping[T]['return'] & {
32
+ /** Id of the model */
33
+ id: string;
34
+ };
35
+ export type ModelsMap = {
36
+ [T in FactoryModel]: (buildOptions: FactoryTyping[T]['options']) => FactoryTyping[T]['return'];
37
+ };
38
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=factory.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.types.js","names":[],"sources":["../../src/factory/factory.types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n ConnectionModel,\n ConnectionBuildOptions,\n OrganizationModel,\n UserModel,\n UserBuildOptions,\n} from './workers';\n\ntype FactoryTyping = {\n /** Mapping for the connection model */\n connection: {\n /** Options for the connection model */\n options: ConnectionBuildOptions;\n /** Return type for the connection model */\n return: ConnectionModel;\n };\n /** Mapping for the organization model */\n organization: {\n /** Options for the organization model */\n options: any;\n /** Return type for the organization model */\n return: OrganizationModel;\n };\n /** Mapping for the user model */\n user: {\n /** Options for the user model */\n options: UserBuildOptions;\n /** Return type for the user model */\n return: UserModel;\n };\n};\n\nexport type FactoryModel = keyof FactoryTyping;\n\nexport type FactoryModelOverride<T extends FactoryModel> = Partial<FactoryTyping[T]['return']> & {\n /** Id of the model */\n id?: string;\n};\n\nexport type FactoryBuildOptions<T extends FactoryModel> = FactoryTyping[T]['options'];\n\nexport type FactoryReturnType<T extends FactoryModel> = FactoryTyping[T]['return'] & {\n /** Id of the model */\n id: string;\n};\n\nexport type ModelsMap = {\n [T in FactoryModel]: (buildOptions: FactoryTyping[T]['options']) => FactoryTyping[T]['return'];\n};\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export * from './workers';
2
+ export * from './factory';
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _workers = require("./workers");
7
+ Object.keys(_workers).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _workers[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _workers[key];
14
+ }
15
+ });
16
+ });
17
+ var _factory = require("./factory");
18
+ Object.keys(_factory).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _factory[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _factory[key];
25
+ }
26
+ });
27
+ });
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_workers","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_factory"],"sources":["../../src/factory/index.ts"],"sourcesContent":["export * from './workers';\nexport * from './factory';\n"],"mappings":";;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,QAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,QAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,QAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,QAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,QAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,QAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,QAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ import { ConnectionBuildOptions, ConnectionModel } from './connection.types';
2
+ /** Create a random connection */
3
+ export declare function connectionFactoryWorker(buildOptions?: ConnectionBuildOptions): ConnectionModel;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.connectionFactoryWorker = connectionFactoryWorker;
7
+ var _crypto = require("crypto");
8
+ var _faker = require("@faker-js/faker");
9
+ /** Create a random connection */
10
+ function connectionFactoryWorker(buildOptions = {}) {
11
+ const accepted = buildOptions.accepted ?? true;
12
+ const blocked = buildOptions.blocked ?? false;
13
+ return {
14
+ ownerId: (0, _crypto.randomUUID)(),
15
+ otherUserId: (0, _crypto.randomUUID)(),
16
+ accepted,
17
+ acceptedAt: accepted ? _faker.faker.date.recent() : undefined,
18
+ blocked,
19
+ blockedAt: blocked ? _faker.faker.date.recent() : undefined,
20
+ initiator: true,
21
+ message: _faker.faker.lorem.sentence(),
22
+ note: _faker.faker.lorem.sentence()
23
+ };
24
+ }
25
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.js","names":["_crypto","require","_faker","connectionFactoryWorker","buildOptions","accepted","blocked","ownerId","randomUUID","otherUserId","acceptedAt","faker","date","recent","undefined","blockedAt","initiator","message","lorem","sentence","note"],"sources":["../../../src/factory/workers/connection.ts"],"sourcesContent":["import {randomUUID} from 'crypto';\nimport { faker } from '@faker-js/faker';\nimport {ConnectionBuildOptions, ConnectionModel} from './connection.types';\n\n/** Create a random connection */\nexport function connectionFactoryWorker(\n buildOptions: ConnectionBuildOptions = {},\n): ConnectionModel {\n const accepted = buildOptions.accepted ?? true;\n const blocked = buildOptions.blocked ?? false;\n return {\n ownerId: randomUUID(),\n otherUserId: randomUUID(),\n accepted,\n acceptedAt: accepted ? faker.date.recent() : undefined,\n blocked,\n blockedAt: blocked ? faker.date.recent() : undefined,\n initiator: true,\n message: faker.lorem.sentence(),\n note: faker.lorem.sentence(),\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAGA;AACO,SAASE,uBAAuBA,CACrCC,YAAoC,GAAG,CAAC,CAAC,EACxB;EACjB,MAAMC,QAAQ,GAAGD,YAAY,CAACC,QAAQ,IAAI,IAAI;EAC9C,MAAMC,OAAO,GAAGF,YAAY,CAACE,OAAO,IAAI,KAAK;EAC7C,OAAO;IACLC,OAAO,EAAE,IAAAC,kBAAU,EAAC,CAAC;IACrBC,WAAW,EAAE,IAAAD,kBAAU,EAAC,CAAC;IACzBH,QAAQ;IACRK,UAAU,EAAEL,QAAQ,GAAGM,YAAK,CAACC,IAAI,CAACC,MAAM,CAAC,CAAC,GAAGC,SAAS;IACtDR,OAAO;IACPS,SAAS,EAAET,OAAO,GAAGK,YAAK,CAACC,IAAI,CAACC,MAAM,CAAC,CAAC,GAAGC,SAAS;IACpDE,SAAS,EAAE,IAAI;IACfC,OAAO,EAAEN,YAAK,CAACO,KAAK,CAACC,QAAQ,CAAC,CAAC;IAC/BC,IAAI,EAAET,YAAK,CAACO,KAAK,CAACC,QAAQ,CAAC;EAC7B,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,28 @@
1
+ /** Connection base model */
2
+ export interface ConnectionModel {
3
+ /** Owner of the connection */
4
+ ownerId: string;
5
+ /** USer with which the owner is connected */
6
+ otherUserId: string;
7
+ /** Wether the connection is accepted or not */
8
+ accepted: boolean;
9
+ /** Date at which the connection was accepted */
10
+ acceptedAt?: Date;
11
+ /** Wether the owner did block the other user */
12
+ blocked: boolean;
13
+ /** Date at which the connection was blocked */
14
+ blockedAt?: Date;
15
+ /** Did the owner initiate the connection */
16
+ initiator: boolean;
17
+ /** Message sent to the other user with the connection */
18
+ message: string;
19
+ /** Private note the user has on the connection */
20
+ note: string;
21
+ }
22
+ /** Build options for connections */
23
+ export interface ConnectionBuildOptions {
24
+ /** Wether the connection is accepted or not */
25
+ accepted?: boolean;
26
+ /** Wether the owner did block the other user */
27
+ blocked?: boolean;
28
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=connection.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.types.js","names":[],"sources":["../../../src/factory/workers/connection.types.ts"],"sourcesContent":["/** Connection base model */\nexport interface ConnectionModel {\n /** Owner of the connection */\n ownerId: string;\n /** USer with which the owner is connected */\n otherUserId: string;\n /** Wether the connection is accepted or not */\n accepted: boolean;\n /** Date at which the connection was accepted */\n acceptedAt?: Date;\n /** Wether the owner did block the other user */\n blocked: boolean;\n /** Date at which the connection was blocked */\n blockedAt?: Date;\n /** Did the owner initiate the connection */\n initiator: boolean;\n /** Message sent to the other user with the connection */\n message: string;\n /** Private note the user has on the connection */\n note: string;\n}\n\n/** Build options for connections */\nexport interface ConnectionBuildOptions {\n /** Wether the connection is accepted or not */\n accepted?: boolean;\n /** Wether the owner did block the other user */\n blocked?: boolean;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ export * from './user';
2
+ export * from './user.types';
3
+ export * from './connection';
4
+ export * from './connection.types';
5
+ export * from './organization';
6
+ export * from './organization.types';
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _user = require("./user");
7
+ Object.keys(_user).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _user[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _user[key];
14
+ }
15
+ });
16
+ });
17
+ var _user2 = require("./user.types");
18
+ Object.keys(_user2).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _user2[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _user2[key];
25
+ }
26
+ });
27
+ });
28
+ var _connection = require("./connection");
29
+ Object.keys(_connection).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _connection[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _connection[key];
36
+ }
37
+ });
38
+ });
39
+ var _connection2 = require("./connection.types");
40
+ Object.keys(_connection2).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _connection2[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _connection2[key];
47
+ }
48
+ });
49
+ });
50
+ var _organization = require("./organization");
51
+ Object.keys(_organization).forEach(function (key) {
52
+ if (key === "default" || key === "__esModule") return;
53
+ if (key in exports && exports[key] === _organization[key]) return;
54
+ Object.defineProperty(exports, key, {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _organization[key];
58
+ }
59
+ });
60
+ });
61
+ var _organization2 = require("./organization.types");
62
+ Object.keys(_organization2).forEach(function (key) {
63
+ if (key === "default" || key === "__esModule") return;
64
+ if (key in exports && exports[key] === _organization2[key]) return;
65
+ Object.defineProperty(exports, key, {
66
+ enumerable: true,
67
+ get: function () {
68
+ return _organization2[key];
69
+ }
70
+ });
71
+ });
72
+ //# sourceMappingURL=index.js.map