@symbo.ls/sdk 2.34.34 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/README.md +13 -315
  2. package/dist/cjs/config/environment.js +50 -124
  3. package/dist/cjs/index.js +22 -169
  4. package/dist/cjs/services/AIService.js +155 -0
  5. package/dist/cjs/services/AuthService.js +277 -751
  6. package/dist/cjs/services/BaseService.js +6 -158
  7. package/dist/cjs/services/BasedService.js +679 -0
  8. package/dist/cjs/services/SocketIOService.js +309 -0
  9. package/dist/cjs/services/SocketService.js +161 -0
  10. package/dist/cjs/services/SymstoryService.js +485 -0
  11. package/dist/cjs/services/index.js +16 -64
  12. package/dist/cjs/utils/basedQuerys.js +61 -0
  13. package/dist/cjs/utils/permission.js +4 -4
  14. package/dist/cjs/utils/services.js +80 -301
  15. package/dist/cjs/utils/symstoryClient.js +228 -0
  16. package/dist/cjs/utils/validation.js +3 -0
  17. package/dist/esm/config/environment.js +50 -124
  18. package/dist/esm/index.js +11282 -49789
  19. package/dist/esm/services/AIService.js +185 -0
  20. package/dist/esm/services/AuthService.js +358 -1506
  21. package/dist/esm/services/BaseService.js +6 -757
  22. package/dist/esm/services/BasedService.js +4651 -0
  23. package/dist/esm/services/SocketIOService.js +467 -0
  24. package/dist/esm/services/SocketService.js +191 -0
  25. package/dist/esm/services/SymstoryService.js +6849 -0
  26. package/dist/esm/services/index.js +11188 -49352
  27. package/dist/esm/utils/basedQuerys.js +43 -0
  28. package/dist/esm/utils/permission.js +4 -4
  29. package/dist/esm/utils/services.js +80 -301
  30. package/dist/esm/utils/symstoryClient.js +334 -0
  31. package/dist/esm/utils/validation.js +26 -93
  32. package/dist/node/config/environment.js +50 -124
  33. package/dist/node/index.js +26 -202
  34. package/dist/node/services/AIService.js +136 -0
  35. package/dist/node/services/AuthService.js +278 -751
  36. package/dist/node/services/BaseService.js +6 -148
  37. package/dist/node/services/BasedService.js +650 -0
  38. package/dist/node/services/SocketIOService.js +280 -0
  39. package/dist/node/services/SocketService.js +142 -0
  40. package/dist/node/services/SymstoryService.js +456 -0
  41. package/dist/node/services/index.js +16 -64
  42. package/dist/node/utils/basedQuerys.js +42 -0
  43. package/dist/node/utils/permission.js +4 -4
  44. package/dist/node/utils/services.js +80 -301
  45. package/dist/node/utils/symstoryClient.js +199 -0
  46. package/dist/node/utils/validation.js +3 -0
  47. package/package.json +21 -43
  48. package/src/config/environment.js +50 -126
  49. package/src/index.js +24 -208
  50. package/src/services/AIService.js +150 -0
  51. package/src/services/AuthService.js +298 -893
  52. package/src/services/BaseService.js +6 -166
  53. package/src/services/BasedService.js +722 -0
  54. package/src/services/SocketIOService.js +356 -0
  55. package/src/services/SocketService.js +168 -0
  56. package/src/services/SymstoryService.js +563 -0
  57. package/src/services/index.js +13 -80
  58. package/src/utils/basedQuerys.js +41 -0
  59. package/src/utils/permission.js +4 -4
  60. package/src/utils/services.js +83 -325
  61. package/src/utils/symstoryClient.js +218 -0
  62. package/src/utils/validation.js +3 -0
  63. package/dist/cjs/services/AdminService.js +0 -351
  64. package/dist/cjs/services/BranchService.js +0 -484
  65. package/dist/cjs/services/CollabService.js +0 -743
  66. package/dist/cjs/services/DnsService.js +0 -340
  67. package/dist/cjs/services/FeatureFlagService.js +0 -175
  68. package/dist/cjs/services/FileService.js +0 -201
  69. package/dist/cjs/services/IntegrationService.js +0 -538
  70. package/dist/cjs/services/MetricsService.js +0 -62
  71. package/dist/cjs/services/PaymentService.js +0 -271
  72. package/dist/cjs/services/PlanService.js +0 -426
  73. package/dist/cjs/services/ProjectService.js +0 -1207
  74. package/dist/cjs/services/PullRequestService.js +0 -503
  75. package/dist/cjs/services/ScreenshotService.js +0 -304
  76. package/dist/cjs/services/SubscriptionService.js +0 -396
  77. package/dist/cjs/services/TrackingService.js +0 -661
  78. package/dist/cjs/services/WaitlistService.js +0 -148
  79. package/dist/cjs/state/RootStateManager.js +0 -65
  80. package/dist/cjs/state/rootEventBus.js +0 -74
  81. package/dist/cjs/utils/CollabClient.js +0 -223
  82. package/dist/cjs/utils/TokenManager.js +0 -422
  83. package/dist/cjs/utils/changePreprocessor.js +0 -199
  84. package/dist/cjs/utils/jsonDiff.js +0 -145
  85. package/dist/cjs/utils/ordering.js +0 -309
  86. package/dist/esm/services/AdminService.js +0 -1132
  87. package/dist/esm/services/BranchService.js +0 -1265
  88. package/dist/esm/services/CollabService.js +0 -26838
  89. package/dist/esm/services/DnsService.js +0 -1121
  90. package/dist/esm/services/FeatureFlagService.js +0 -956
  91. package/dist/esm/services/FileService.js +0 -982
  92. package/dist/esm/services/IntegrationService.js +0 -1319
  93. package/dist/esm/services/MetricsService.js +0 -843
  94. package/dist/esm/services/PaymentService.js +0 -1052
  95. package/dist/esm/services/PlanService.js +0 -1207
  96. package/dist/esm/services/ProjectService.js +0 -2526
  97. package/dist/esm/services/PullRequestService.js +0 -1284
  98. package/dist/esm/services/ScreenshotService.js +0 -1085
  99. package/dist/esm/services/SubscriptionService.js +0 -1177
  100. package/dist/esm/services/TrackingService.js +0 -18343
  101. package/dist/esm/services/WaitlistService.js +0 -929
  102. package/dist/esm/state/RootStateManager.js +0 -90
  103. package/dist/esm/state/rootEventBus.js +0 -56
  104. package/dist/esm/utils/CollabClient.js +0 -18901
  105. package/dist/esm/utils/TokenManager.js +0 -408
  106. package/dist/esm/utils/changePreprocessor.js +0 -542
  107. package/dist/esm/utils/jsonDiff.js +0 -7011
  108. package/dist/esm/utils/ordering.js +0 -291
  109. package/dist/node/services/AdminService.js +0 -332
  110. package/dist/node/services/BranchService.js +0 -465
  111. package/dist/node/services/CollabService.js +0 -724
  112. package/dist/node/services/DnsService.js +0 -321
  113. package/dist/node/services/FeatureFlagService.js +0 -156
  114. package/dist/node/services/FileService.js +0 -182
  115. package/dist/node/services/IntegrationService.js +0 -519
  116. package/dist/node/services/MetricsService.js +0 -43
  117. package/dist/node/services/PaymentService.js +0 -252
  118. package/dist/node/services/PlanService.js +0 -407
  119. package/dist/node/services/ProjectService.js +0 -1188
  120. package/dist/node/services/PullRequestService.js +0 -484
  121. package/dist/node/services/ScreenshotService.js +0 -285
  122. package/dist/node/services/SubscriptionService.js +0 -377
  123. package/dist/node/services/TrackingService.js +0 -632
  124. package/dist/node/services/WaitlistService.js +0 -129
  125. package/dist/node/state/RootStateManager.js +0 -36
  126. package/dist/node/state/rootEventBus.js +0 -55
  127. package/dist/node/utils/CollabClient.js +0 -194
  128. package/dist/node/utils/TokenManager.js +0 -403
  129. package/dist/node/utils/changePreprocessor.js +0 -180
  130. package/dist/node/utils/jsonDiff.js +0 -116
  131. package/dist/node/utils/ordering.js +0 -290
  132. package/src/services/AdminService.js +0 -374
  133. package/src/services/BranchService.js +0 -536
  134. package/src/services/CollabService.js +0 -900
  135. package/src/services/DnsService.js +0 -366
  136. package/src/services/FeatureFlagService.js +0 -174
  137. package/src/services/FileService.js +0 -213
  138. package/src/services/IntegrationService.js +0 -548
  139. package/src/services/MetricsService.js +0 -40
  140. package/src/services/PaymentService.js +0 -287
  141. package/src/services/PlanService.js +0 -468
  142. package/src/services/ProjectService.js +0 -1366
  143. package/src/services/PullRequestService.js +0 -537
  144. package/src/services/ScreenshotService.js +0 -258
  145. package/src/services/SubscriptionService.js +0 -425
  146. package/src/services/TrackingService.js +0 -853
  147. package/src/services/WaitlistService.js +0 -130
  148. package/src/services/tests/BranchService/createBranch.test.js +0 -153
  149. package/src/services/tests/BranchService/deleteBranch.test.js +0 -173
  150. package/src/services/tests/BranchService/getBranchChanges.test.js +0 -146
  151. package/src/services/tests/BranchService/listBranches.test.js +0 -87
  152. package/src/services/tests/BranchService/mergeBranch.test.js +0 -210
  153. package/src/services/tests/BranchService/publishVersion.test.js +0 -183
  154. package/src/services/tests/BranchService/renameBranch.test.js +0 -240
  155. package/src/services/tests/BranchService/resetBranch.test.js +0 -152
  156. package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +0 -67
  157. package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +0 -75
  158. package/src/services/tests/FileService/createFileFormData.test.js +0 -74
  159. package/src/services/tests/FileService/getFileUrl.test.js +0 -69
  160. package/src/services/tests/FileService/updateProjectIcon.test.js +0 -109
  161. package/src/services/tests/FileService/uploadDocument.test.js +0 -36
  162. package/src/services/tests/FileService/uploadFile.test.js +0 -78
  163. package/src/services/tests/FileService/uploadFileWithValidation.test.js +0 -114
  164. package/src/services/tests/FileService/uploadImage.test.js +0 -36
  165. package/src/services/tests/FileService/uploadMultipleFiles.test.js +0 -111
  166. package/src/services/tests/FileService/validateFile.test.js +0 -63
  167. package/src/services/tests/PlanService/createPlan.test.js +0 -104
  168. package/src/services/tests/PlanService/createPlanWithValidation.test.js +0 -523
  169. package/src/services/tests/PlanService/deletePlan.test.js +0 -92
  170. package/src/services/tests/PlanService/getActivePlans.test.js +0 -123
  171. package/src/services/tests/PlanService/getAdminPlans.test.js +0 -84
  172. package/src/services/tests/PlanService/getPlan.test.js +0 -50
  173. package/src/services/tests/PlanService/getPlanByKey.test.js +0 -109
  174. package/src/services/tests/PlanService/getPlanWithValidation.test.js +0 -85
  175. package/src/services/tests/PlanService/getPlans.test.js +0 -53
  176. package/src/services/tests/PlanService/getPlansByPriceRange.test.js +0 -109
  177. package/src/services/tests/PlanService/getPlansWithValidation.test.js +0 -48
  178. package/src/services/tests/PlanService/initializePlans.test.js +0 -75
  179. package/src/services/tests/PlanService/updatePlan.test.js +0 -111
  180. package/src/services/tests/PlanService/updatePlanWithValidation.test.js +0 -556
  181. package/src/state/RootStateManager.js +0 -76
  182. package/src/state/rootEventBus.js +0 -67
  183. package/src/utils/CollabClient.js +0 -248
  184. package/src/utils/TokenManager.js +0 -479
  185. package/src/utils/changePreprocessor.js +0 -239
  186. package/src/utils/jsonDiff.js +0 -144
  187. package/src/utils/ordering.js +0 -271
@@ -1,523 +0,0 @@
1
- /* eslint-disable no-useless-escape */
2
- /* eslint-disable no-undefined */
3
- import test from 'tape'
4
- import sinon from 'sinon'
5
- import { PlanService } from '../../PlanService.js'
6
-
7
- // #region Setup
8
- const sandbox = sinon.createSandbox()
9
- // #endregion
10
-
11
- // #region Tests
12
- test('createPlanWithValidation should return response data', async t => {
13
- t.plan(1)
14
- const responseStub = [sandbox.stub()]
15
- const planData = {
16
- name: 'testName',
17
- description: 'test description'
18
- }
19
- const planServiceStub = new PlanService()
20
- sandbox.stub(planServiceStub, 'createPlan').resolves(responseStub)
21
- const response = await planServiceStub.createPlanWithValidation(planData)
22
- t.ok(response, 'Response returned successfully')
23
-
24
- sandbox.restore()
25
- t.end()
26
- })
27
-
28
- function planDataEmptyOrNotAnObject () {
29
- // Data test object
30
- const badData = {
31
- planDataUndefined: {
32
- name: 'planData is undefined',
33
- testValue: undefined
34
- },
35
- planDataIsFalse: {
36
- name: 'planData is false',
37
- testValue: false
38
- },
39
- planDataNotAnObject: {
40
- name: 'planData is not an object',
41
- testValue: 'Not An Object'
42
- }
43
- }
44
-
45
- Object.keys(badData).forEach(key => {
46
- test(`createPlanWithValidation should return an error - ${badData[key].name}`, async t => {
47
- t.plan(1)
48
- const planData = badData[key].testValue
49
- const planServiceStub = new PlanService()
50
- try {
51
- await planServiceStub.createPlanWithValidation(planData)
52
- t.fail('createPlanWithValidation should have failed')
53
- } catch (err) {
54
- t.equal(
55
- err.toString(),
56
- 'Error: Plan data must be a valid object',
57
- `${badData[key].name} successfully caused an error`
58
- )
59
- }
60
- sandbox.restore()
61
- t.end()
62
- })
63
- })
64
- }
65
-
66
- function requiredFieldsMissing () {
67
- // Data test object
68
- const planData = {
69
- name: 'testName',
70
- description: 'test description'
71
- }
72
- Object.keys(planData).forEach(field => {
73
- test(`Required field validation for missing ${field} should return an error`, async t => {
74
- t.plan(1)
75
- const { ...testData } = planData
76
- delete testData[field]
77
- const responseStub = [sandbox.stub()]
78
- const planServiceStub = new PlanService()
79
- sandbox.stub(planServiceStub, 'createPlan').resolves(responseStub)
80
- try {
81
- await planServiceStub.createPlanWithValidation(testData)
82
- t.fail('createPlanWithValidation failed - missing required field')
83
- } catch (err) {
84
- t.equal(
85
- err.toString(),
86
- `Error: Required field \'${field}\' is missing`,
87
- `Required field validation failed on required field: ${field} successfully`
88
- )
89
- }
90
- sandbox.restore()
91
- t.end()
92
- })
93
- })
94
- }
95
-
96
- test('Price validation should throw an error when price field is present', async t => {
97
- t.plan(1)
98
- const planData = {
99
- name: 'testName',
100
- description: 'test description',
101
- price: 1.0
102
- }
103
- const responseStub = [sandbox.stub()]
104
- const planServiceStub = new PlanService()
105
- sandbox.stub(planServiceStub, 'createPlan').resolves(responseStub)
106
- try {
107
- await planServiceStub.createPlanWithValidation(planData)
108
- t.fail('Price validation successfully threw an error')
109
- } catch (err) {
110
- t.equal(
111
- err.toString(),
112
- 'Error: Field "price" is no longer supported. Use unified "pricingOptions" with "amount" instead.',
113
- 'Price validation detected unsupported price field'
114
- )
115
- }
116
- sandbox.restore()
117
- t.end()
118
- })
119
-
120
- function pricingOptionsValidation () {
121
- // Data test object
122
- const planData = {
123
- name: 'testName',
124
- description: 'test description'
125
- }
126
-
127
- const badPricingOptions = {
128
- stringValue: 'test string',
129
- numberValue: 123,
130
- booleanValue: false,
131
- emptyArray: []
132
- }
133
- Object.keys(badPricingOptions).forEach(field => {
134
- test(`pricingOptions validation throws error for ${field}`, async t => {
135
- t.plan(1)
136
- const { ...testData } = planData
137
- testData.pricingOptions = badPricingOptions[field]
138
- const responseStub = [sandbox.stub()]
139
- const planServiceStub = new PlanService()
140
- sandbox.stub(planServiceStub, 'createPlan').resolves(responseStub)
141
- try {
142
- await planServiceStub.createPlanWithValidation(testData)
143
- t.fail('createPlanWithValidation failed - bad pricingOptions detected')
144
- } catch (err) {
145
- t.equal(
146
- err.toString(),
147
- 'Error: pricingOptions must be a non-empty array when provided',
148
- `pricingOptions validation failed successfully on bad pricingOptions data: ${field}`
149
- )
150
- }
151
- sandbox.restore()
152
- t.end()
153
- })
154
- })
155
- }
156
-
157
- function keyTypeValidation () {
158
- const badKeyData = [
159
- { name: 'array value', key: [] },
160
- { name: 'number value', key: 123 },
161
- { name: 'null value', key: null },
162
- { name: 'undefined value', key: undefined },
163
- { name: 'false boolean value', key: false }
164
- ]
165
- for (let ii = 0; ii < badKeyData.length; ii++) {
166
- test(`Key type validation should throw an error checking for: ${badKeyData[ii].name}`, async t => {
167
- t.plan(1)
168
- const planData = {
169
- name: 'testName',
170
- description: 'test description',
171
- pricingOptions: []
172
- }
173
- planData.pricingOptions.push(badKeyData[ii])
174
- const responseStub = [sandbox.stub()]
175
- const planServiceStub = new PlanService()
176
- sandbox.stub(planServiceStub, 'createPlan').resolves(responseStub)
177
- try {
178
- await planServiceStub.createPlanWithValidation(planData)
179
- t.fail('Key type validation successfully threw an error')
180
- } catch (err) {
181
- t.ok(
182
- err
183
- .toString()
184
- .includes(
185
- "Error: Pricing option at index 0 is missing required field 'key'"
186
- ),
187
- `Key type validation detected bad data: ${badKeyData[ii].name}`
188
- )
189
- }
190
- sandbox.restore()
191
- t.end()
192
- })
193
- }
194
- }
195
-
196
- function keyFormatValidation () {
197
- const badKeyData = [
198
- { name: 'capital letters', key: 'CAPITALLETTERS' },
199
- { name: 'special character', key: 'Special @ Character' },
200
- { name: 'under score', key: 'under_score' },
201
- { name: 'punctuation', key: 'syntax!' }
202
- ]
203
- for (let ii = 0; ii < badKeyData.length; ii++) {
204
- test(`Key format validation should throw an error checking for: ${badKeyData[ii].name}`, async t => {
205
- t.plan(1)
206
- const planData = {
207
- name: 'testName',
208
- description: 'test description',
209
- pricingOptions: []
210
- }
211
- planData.pricingOptions.push(badKeyData[ii])
212
- const responseStub = [sandbox.stub()]
213
- const planServiceStub = new PlanService()
214
- sandbox.stub(planServiceStub, 'createPlan').resolves(responseStub)
215
- try {
216
- await planServiceStub.createPlanWithValidation(planData)
217
- t.fail('Key type validation successfully threw an error')
218
- } catch (err) {
219
- t.equal(
220
- err.toString(),
221
- `Error: Pricing option key '${badKeyData[ii].key}' must contain only lowercase letters, numbers, and hyphens`,
222
- `Key format validation detected bad data: ${badKeyData[ii].name}`
223
- )
224
- }
225
- sandbox.restore()
226
- t.end()
227
- })
228
- }
229
- }
230
-
231
- function displayNameValidation () {
232
- const badDisplayNameData = [
233
- {
234
- name: 'false boolean value',
235
- displayName: false,
236
- key: 'false-boolean-value'
237
- },
238
- { name: 'number value', displayName: 123, key: 'number-value' },
239
- { name: 'undefined value', displayName: undefined, key: 'undefined-value' },
240
- { name: 'null value', displayName: null, key: 'null-value' }
241
- ]
242
- for (let ii = 0; ii < badDisplayNameData.length; ii++) {
243
- test(`displayName validation should throw an error checking for: ${badDisplayNameData[ii].name}`, async t => {
244
- t.plan(1)
245
- const planData = {
246
- name: 'testName',
247
- description: 'test description',
248
- pricingOptions: []
249
- }
250
- planData.pricingOptions.push(badDisplayNameData[ii])
251
- const responseStub = [sandbox.stub()]
252
- const planServiceStub = new PlanService()
253
- sandbox.stub(planServiceStub, 'createPlan').resolves(responseStub)
254
- try {
255
- await planServiceStub.createPlanWithValidation(planData)
256
- t.fail('Key type validation successfully threw an error')
257
- } catch (err) {
258
- t.equal(
259
- err.toString(),
260
- `Error: Pricing option \'${badDisplayNameData[ii].key}\' is missing required field \'displayName\'`,
261
- `displayName validation detected bad data: ${badDisplayNameData[ii].name}`
262
- )
263
- }
264
- sandbox.restore()
265
- t.end()
266
- })
267
- }
268
- }
269
-
270
- function amountValidation () {
271
- const badAmountData = [
272
- {
273
- name: 'negative amount value',
274
- displayName: 'test displayname',
275
- key: 'negative-amount-value',
276
- amount: -1
277
- },
278
- {
279
- name: 'letter value',
280
- displayName: 'test displayname',
281
- key: 'letter-value',
282
- amount: 'abc123'
283
- },
284
- {
285
- name: 'undefined value',
286
- displayName: 'test displayname',
287
- key: 'undefined-value',
288
- amount: undefined
289
- },
290
- {
291
- name: 'null value',
292
- displayName: 'test displayname',
293
- key: 'null-value',
294
- amount: null
295
- }
296
- ]
297
- for (let ii = 0; ii < badAmountData.length; ii++) {
298
- test(`amount validation should throw an error checking for: ${badAmountData[ii].name}`, async t => {
299
- t.plan(1)
300
- const planData = {
301
- name: 'testName',
302
- description: 'test description',
303
- pricingOptions: []
304
- }
305
- planData.pricingOptions.push(badAmountData[ii])
306
- const responseStub = [sandbox.stub()]
307
- const planServiceStub = new PlanService()
308
- sandbox.stub(planServiceStub, 'createPlan').resolves(responseStub)
309
- try {
310
- await planServiceStub.createPlanWithValidation(planData)
311
- t.fail('Key type validation successfully threw an error')
312
- } catch (err) {
313
- t.equal(
314
- err.toString(),
315
- `Error: Pricing option \'${badAmountData[ii].key}\' must have a non-negative numeric \'amount\'`,
316
- `amount validation detected bad data: ${badAmountData[ii].name}`
317
- )
318
- }
319
- sandbox.restore()
320
- t.end()
321
- })
322
- }
323
- }
324
-
325
- function intervalValidation () {
326
- const badAmountData = [
327
- {
328
- name: 'number value',
329
- displayName: 'test displayname',
330
- key: 'number-amount-value',
331
- amount: 0,
332
- interval: 123
333
- },
334
- {
335
- name: 'unsupported string value',
336
- displayName: 'test displayname',
337
- key: 'letter-value',
338
- amount: 0,
339
- interval: 'abc123'
340
- },
341
- {
342
- name: 'undefined value',
343
- displayName: 'test displayname',
344
- key: 'undefined-value',
345
- amount: 0,
346
- interval: undefined
347
- }
348
- ]
349
- for (let ii = 0; ii < badAmountData.length; ii++) {
350
- test(`interval validation should throw an error checking for: ${badAmountData[ii].name}`, async t => {
351
- t.plan(1)
352
- const planData = {
353
- name: 'testName',
354
- description: 'test description',
355
- pricingOptions: []
356
- }
357
- planData.pricingOptions.push(badAmountData[ii])
358
- const responseStub = [sandbox.stub()]
359
- const planServiceStub = new PlanService()
360
- sandbox.stub(planServiceStub, 'createPlan').resolves(responseStub)
361
- try {
362
- await planServiceStub.createPlanWithValidation(planData)
363
- t.fail('Key type validation successfully threw an error')
364
- } catch (err) {
365
- t.equal(
366
- err.toString(),
367
- `Error: Pricing option \'${badAmountData[ii].key}\' has invalid interval \'${badAmountData[ii].interval}\'. Allowed: month, year, week, day or null`,
368
- `interval validation detected bad data: ${badAmountData[ii].name}`
369
- )
370
- }
371
- sandbox.restore()
372
- t.end()
373
- })
374
- }
375
- }
376
-
377
- function lookupKeyValidation () {
378
- const badData = [
379
- {
380
- name: 'number value',
381
- displayName: 'test displayname',
382
- key: 'number-amount-value',
383
- amount: 0,
384
- interval: null,
385
- lookupKey: 123
386
- },
387
- {
388
- name: 'false boolean value',
389
- displayName: 'test displayname',
390
- key: 'letter-value',
391
- amount: 0,
392
- interval: null,
393
- lookupKey: false
394
- },
395
- {
396
- name: 'true boolean value',
397
- displayName: 'test displayname',
398
- key: 'letter-value',
399
- amount: 0,
400
- interval: null,
401
- lookupKey: true
402
- },
403
- {
404
- name: 'object value',
405
- displayName: 'test displayname',
406
- key: 'undefined-value',
407
- amount: 0,
408
- interval: null,
409
- lookupKey: {}
410
- },
411
- {
412
- name: 'undefined value',
413
- displayName: 'test displayname',
414
- key: 'undefined-value',
415
- amount: 0,
416
- interval: null,
417
- lookupKey: undefined
418
- },
419
- {
420
- name: 'null value',
421
- displayName: 'test displayname',
422
- key: 'undefined-value',
423
- amount: 0,
424
- interval: null,
425
- lookupKey: null
426
- }
427
- ]
428
- for (let ii = 0; ii < badData.length; ii++) {
429
- test(`lookup key validation should throw an error checking for: ${badData[ii].name}`, async t => {
430
- t.plan(1)
431
- const planData = {
432
- name: 'testName',
433
- description: 'test description',
434
- pricingOptions: []
435
- }
436
- planData.pricingOptions.push(badData[ii])
437
- const responseStub = [sandbox.stub()]
438
- const planServiceStub = new PlanService()
439
- sandbox.stub(planServiceStub, 'createPlan').resolves(responseStub)
440
- try {
441
- await planServiceStub.createPlanWithValidation(planData)
442
- t.fail('Key type validation successfully threw an error')
443
- } catch (err) {
444
- t.equal(
445
- err.toString(),
446
- `Error: Pricing option \'${badData[ii].key}\' is missing required field \'lookupKey\'`,
447
- `lookup key validation detected bad data: ${badData[ii].name}`
448
- )
449
- }
450
- sandbox.restore()
451
- t.end()
452
- })
453
- }
454
- }
455
-
456
- function topLevelKeyValidation () {
457
- const planData = [
458
- {
459
- name: 'Uppercase letters',
460
- description: 'test description',
461
- key: 'ALLCAPS'
462
- },
463
- {
464
- name: 'Underscore character',
465
- description: 'test description',
466
- key: '_'
467
- },
468
- {
469
- name: 'Special characters',
470
- description: 'test description',
471
- key: '!@#$%'
472
- },
473
- {
474
- name: 'Object type',
475
- description: 'test description',
476
- key: {}
477
- },
478
- {
479
- name: 'Null value',
480
- description: 'test description',
481
- key: null
482
- }
483
- ]
484
- for (let ii = 0; ii < planData.length; ii++) {
485
- test(`top-level key validation should throw an error checking for: ${planData[ii].name}`, async t => {
486
- t.plan(1)
487
- const responseStub = [sandbox.stub()]
488
- const planServiceStub = new PlanService()
489
- sandbox.stub(planServiceStub, 'createPlan').resolves(responseStub)
490
- try {
491
- await planServiceStub.createPlanWithValidation(planData[ii])
492
- t.fail('Key type validation successfully threw an error')
493
- } catch (err) {
494
- t.equal(
495
- err.toString(),
496
- 'Error: Plan key must contain only lowercase letters, numbers, and hyphens',
497
- `displayName validation detected bad data: ${planData[ii].name} with ${err}`
498
- )
499
- }
500
- sandbox.restore()
501
- t.end()
502
- })
503
- }
504
- }
505
-
506
- amountValidation()
507
- displayNameValidation()
508
- intervalValidation()
509
- keyFormatValidation()
510
- keyTypeValidation()
511
- lookupKeyValidation()
512
- planDataEmptyOrNotAnObject()
513
- pricingOptionsValidation()
514
- requiredFieldsMissing()
515
- topLevelKeyValidation()
516
- // #endregion
517
-
518
- // #region Cleanup
519
- test('teardown', t => {
520
- sandbox.restore()
521
- t.end()
522
- })
523
- // #endregion
@@ -1,92 +0,0 @@
1
- import test from 'tape'
2
- import sinon from 'sinon'
3
- import { PlanService } from '../../PlanService.js'
4
-
5
- // #region Setup
6
- const sandbox = sinon.createSandbox()
7
- // #endregion
8
-
9
- // #region Tests
10
- test('deletePlan should return response data', async t => {
11
- t.plan(1)
12
-
13
- const planDataStub = {
14
- success: true,
15
- data: sandbox.stub()
16
- }
17
- const planServiceStub = new PlanService()
18
- sandbox.stub(planServiceStub, '_request').resolves(planDataStub)
19
- sandbox.stub(planServiceStub, '_requireReady').resolves()
20
- const response = await planServiceStub.deletePlan(true)
21
- t.equal(response, planDataStub.data, 'Response data returned')
22
-
23
- sandbox.restore()
24
- t.end()
25
- })
26
-
27
- test('deletePlan should return an error - Plan ID required', async t => {
28
- t.plan(1)
29
- const planServiceStub = new PlanService()
30
- sandbox.stub(planServiceStub, '_requireReady').resolves()
31
-
32
- try {
33
- await planServiceStub.deletePlan(false)
34
- t.fail('deletePlan should have failed')
35
- } catch (err) {
36
- t.equal(
37
- err.toString(),
38
- 'Error: Plan ID is required',
39
- 'Error correctly returned'
40
- )
41
- }
42
- sandbox.restore()
43
- t.end()
44
- })
45
-
46
- test('deletePlan should return an error - Failed to parse URL', async t => {
47
- t.plan(1)
48
- const planServiceStub = new PlanService()
49
- sandbox.stub(planServiceStub, '_requireReady').resolves()
50
-
51
- try {
52
- await planServiceStub.deletePlan(true)
53
- t.fail('deletePlan should have failed')
54
- } catch (err) {
55
- t.equal(
56
- err.toString(),
57
- 'Error: Failed to delete plan: Request failed: Failed to parse URL from null/core/admin/plans/true',
58
- 'Error correctly returned'
59
- )
60
- }
61
- sandbox.restore()
62
- t.end()
63
- })
64
-
65
- test('deletePlan should fail the requireReady', async t => {
66
- t.plan(1)
67
- const planServiceStub = new PlanService()
68
- sandbox
69
- .stub(planServiceStub, '_requireReady')
70
- .throws(() => new Error('Service not initialized for method: deletePlan'))
71
-
72
- try {
73
- await planServiceStub.deletePlan()
74
- t.fail('deletePlan should have failed')
75
- } catch (err) {
76
- t.equal(
77
- err.toString(),
78
- 'Error: Service not initialized for method: deletePlan',
79
- 'Error correctly returned'
80
- )
81
- }
82
- sandbox.restore()
83
- t.end()
84
- })
85
- // #endregion
86
-
87
- // #region Cleanup
88
- test('teardown', t => {
89
- sandbox.restore()
90
- t.end()
91
- })
92
- // #endregion