@symbo.ls/sdk 3.1.2 → 3.2.6

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 +143 -2
  2. package/dist/cjs/config/environment.js +98 -30
  3. package/dist/cjs/index.js +144 -24
  4. package/dist/cjs/services/AdminService.js +351 -0
  5. package/dist/cjs/services/AuthService.js +738 -305
  6. package/dist/cjs/services/BaseService.js +158 -6
  7. package/dist/cjs/services/BranchService.js +484 -0
  8. package/dist/cjs/services/CollabService.js +743 -0
  9. package/dist/cjs/services/DnsService.js +340 -0
  10. package/dist/cjs/services/FeatureFlagService.js +175 -0
  11. package/dist/cjs/services/FileService.js +201 -0
  12. package/dist/cjs/services/IntegrationService.js +538 -0
  13. package/dist/cjs/services/MetricsService.js +62 -0
  14. package/dist/cjs/services/PaymentService.js +271 -0
  15. package/dist/cjs/services/PlanService.js +426 -0
  16. package/dist/cjs/services/ProjectService.js +1207 -0
  17. package/dist/cjs/services/PullRequestService.js +503 -0
  18. package/dist/cjs/services/ScreenshotService.js +304 -0
  19. package/dist/cjs/services/SubscriptionService.js +396 -0
  20. package/dist/cjs/services/TrackingService.js +661 -0
  21. package/dist/cjs/services/WaitlistService.js +148 -0
  22. package/dist/cjs/services/index.js +64 -16
  23. package/dist/cjs/state/RootStateManager.js +65 -0
  24. package/dist/cjs/state/rootEventBus.js +74 -0
  25. package/dist/cjs/utils/CollabClient.js +223 -0
  26. package/dist/cjs/utils/TokenManager.js +78 -30
  27. package/dist/cjs/utils/changePreprocessor.js +199 -0
  28. package/dist/cjs/utils/jsonDiff.js +145 -0
  29. package/dist/cjs/utils/ordering.js +309 -0
  30. package/dist/cjs/utils/services.js +301 -103
  31. package/dist/cjs/utils/validation.js +0 -3
  32. package/dist/esm/config/environment.js +98 -30
  33. package/dist/esm/index.js +49505 -8718
  34. package/dist/esm/services/AdminService.js +1132 -0
  35. package/dist/esm/services/AuthService.js +1493 -386
  36. package/dist/esm/services/BaseService.js +757 -6
  37. package/dist/esm/services/BranchService.js +1265 -0
  38. package/dist/esm/services/CollabService.js +26895 -0
  39. package/dist/esm/services/DnsService.js +1121 -0
  40. package/dist/esm/services/FeatureFlagService.js +956 -0
  41. package/dist/esm/services/FileService.js +982 -0
  42. package/dist/esm/services/IntegrationService.js +1319 -0
  43. package/dist/esm/services/MetricsService.js +843 -0
  44. package/dist/esm/services/PaymentService.js +1052 -0
  45. package/dist/esm/services/PlanService.js +1207 -0
  46. package/dist/esm/services/ProjectService.js +2526 -0
  47. package/dist/esm/services/PullRequestService.js +1284 -0
  48. package/dist/esm/services/ScreenshotService.js +1085 -0
  49. package/dist/esm/services/SubscriptionService.js +1177 -0
  50. package/dist/esm/services/TrackingService.js +18454 -0
  51. package/dist/esm/services/WaitlistService.js +929 -0
  52. package/dist/esm/services/index.js +49062 -8569
  53. package/dist/esm/state/RootStateManager.js +90 -0
  54. package/dist/esm/state/rootEventBus.js +56 -0
  55. package/dist/esm/utils/CollabClient.js +18889 -0
  56. package/dist/esm/utils/TokenManager.js +78 -30
  57. package/dist/esm/utils/changePreprocessor.js +542 -0
  58. package/dist/esm/utils/jsonDiff.js +7011 -0
  59. package/dist/esm/utils/ordering.js +291 -0
  60. package/dist/esm/utils/services.js +301 -103
  61. package/dist/esm/utils/validation.js +116 -50
  62. package/dist/node/config/environment.js +98 -30
  63. package/dist/node/index.js +175 -32
  64. package/dist/node/services/AdminService.js +332 -0
  65. package/dist/node/services/AuthService.js +742 -310
  66. package/dist/node/services/BaseService.js +148 -6
  67. package/dist/node/services/BranchService.js +465 -0
  68. package/dist/node/services/CollabService.js +724 -0
  69. package/dist/node/services/DnsService.js +321 -0
  70. package/dist/node/services/FeatureFlagService.js +156 -0
  71. package/dist/node/services/FileService.js +182 -0
  72. package/dist/node/services/IntegrationService.js +519 -0
  73. package/dist/node/services/MetricsService.js +43 -0
  74. package/dist/node/services/PaymentService.js +252 -0
  75. package/dist/node/services/PlanService.js +407 -0
  76. package/dist/node/services/ProjectService.js +1188 -0
  77. package/dist/node/services/PullRequestService.js +484 -0
  78. package/dist/node/services/ScreenshotService.js +285 -0
  79. package/dist/node/services/SubscriptionService.js +377 -0
  80. package/dist/node/services/TrackingService.js +632 -0
  81. package/dist/node/services/WaitlistService.js +129 -0
  82. package/dist/node/services/index.js +64 -16
  83. package/dist/node/state/RootStateManager.js +36 -0
  84. package/dist/node/state/rootEventBus.js +55 -0
  85. package/dist/node/utils/CollabClient.js +194 -0
  86. package/dist/node/utils/TokenManager.js +78 -30
  87. package/dist/node/utils/changePreprocessor.js +180 -0
  88. package/dist/node/utils/jsonDiff.js +116 -0
  89. package/dist/node/utils/ordering.js +290 -0
  90. package/dist/node/utils/services.js +301 -103
  91. package/dist/node/utils/validation.js +0 -3
  92. package/package.json +39 -21
  93. package/src/config/environment.js +99 -28
  94. package/src/index.js +181 -36
  95. package/src/services/AdminService.js +374 -0
  96. package/src/services/AuthService.js +874 -328
  97. package/src/services/BaseService.js +166 -6
  98. package/src/services/BranchService.js +536 -0
  99. package/src/services/CollabService.js +900 -0
  100. package/src/services/DnsService.js +366 -0
  101. package/src/services/FeatureFlagService.js +174 -0
  102. package/src/services/FileService.js +213 -0
  103. package/src/services/IntegrationService.js +548 -0
  104. package/src/services/MetricsService.js +40 -0
  105. package/src/services/PaymentService.js +287 -0
  106. package/src/services/PlanService.js +468 -0
  107. package/src/services/ProjectService.js +1366 -0
  108. package/src/services/PullRequestService.js +537 -0
  109. package/src/services/ScreenshotService.js +258 -0
  110. package/src/services/SubscriptionService.js +425 -0
  111. package/src/services/TrackingService.js +853 -0
  112. package/src/services/WaitlistService.js +130 -0
  113. package/src/services/index.js +80 -13
  114. package/src/services/tests/BranchService/createBranch.test.js +153 -0
  115. package/src/services/tests/BranchService/deleteBranch.test.js +173 -0
  116. package/src/services/tests/BranchService/getBranchChanges.test.js +146 -0
  117. package/src/services/tests/BranchService/listBranches.test.js +87 -0
  118. package/src/services/tests/BranchService/mergeBranch.test.js +210 -0
  119. package/src/services/tests/BranchService/publishVersion.test.js +183 -0
  120. package/src/services/tests/BranchService/renameBranch.test.js +240 -0
  121. package/src/services/tests/BranchService/resetBranch.test.js +152 -0
  122. package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +67 -0
  123. package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +75 -0
  124. package/src/services/tests/FileService/createFileFormData.test.js +74 -0
  125. package/src/services/tests/FileService/getFileUrl.test.js +69 -0
  126. package/src/services/tests/FileService/updateProjectIcon.test.js +109 -0
  127. package/src/services/tests/FileService/uploadDocument.test.js +36 -0
  128. package/src/services/tests/FileService/uploadFile.test.js +78 -0
  129. package/src/services/tests/FileService/uploadFileWithValidation.test.js +114 -0
  130. package/src/services/tests/FileService/uploadImage.test.js +36 -0
  131. package/src/services/tests/FileService/uploadMultipleFiles.test.js +111 -0
  132. package/src/services/tests/FileService/validateFile.test.js +63 -0
  133. package/src/services/tests/PlanService/createPlan.test.js +104 -0
  134. package/src/services/tests/PlanService/createPlanWithValidation.test.js +523 -0
  135. package/src/services/tests/PlanService/deletePlan.test.js +92 -0
  136. package/src/services/tests/PlanService/getActivePlans.test.js +123 -0
  137. package/src/services/tests/PlanService/getAdminPlans.test.js +84 -0
  138. package/src/services/tests/PlanService/getPlan.test.js +50 -0
  139. package/src/services/tests/PlanService/getPlanByKey.test.js +109 -0
  140. package/src/services/tests/PlanService/getPlanWithValidation.test.js +85 -0
  141. package/src/services/tests/PlanService/getPlans.test.js +53 -0
  142. package/src/services/tests/PlanService/getPlansByPriceRange.test.js +109 -0
  143. package/src/services/tests/PlanService/getPlansWithValidation.test.js +48 -0
  144. package/src/services/tests/PlanService/initializePlans.test.js +75 -0
  145. package/src/services/tests/PlanService/updatePlan.test.js +111 -0
  146. package/src/services/tests/PlanService/updatePlanWithValidation.test.js +556 -0
  147. package/src/state/RootStateManager.js +76 -0
  148. package/src/state/rootEventBus.js +67 -0
  149. package/src/utils/CollabClient.js +248 -0
  150. package/src/utils/TokenManager.js +88 -33
  151. package/src/utils/changePreprocessor.js +239 -0
  152. package/src/utils/jsonDiff.js +144 -0
  153. package/src/utils/ordering.js +271 -0
  154. package/src/utils/services.js +326 -107
  155. package/src/utils/validation.js +0 -3
  156. package/dist/cjs/services/AIService.js +0 -155
  157. package/dist/cjs/services/BasedService.js +0 -1185
  158. package/dist/cjs/services/CoreService.js +0 -1751
  159. package/dist/cjs/services/SocketIOService.js +0 -307
  160. package/dist/cjs/services/SocketService.js +0 -161
  161. package/dist/cjs/services/SymstoryService.js +0 -571
  162. package/dist/cjs/utils/basedQuerys.js +0 -181
  163. package/dist/cjs/utils/symstoryClient.js +0 -259
  164. package/dist/esm/services/AIService.js +0 -185
  165. package/dist/esm/services/BasedService.js +0 -5278
  166. package/dist/esm/services/CoreService.js +0 -2264
  167. package/dist/esm/services/SocketIOService.js +0 -470
  168. package/dist/esm/services/SocketService.js +0 -191
  169. package/dist/esm/services/SymstoryService.js +0 -7041
  170. package/dist/esm/utils/basedQuerys.js +0 -163
  171. package/dist/esm/utils/symstoryClient.js +0 -370
  172. package/dist/node/services/AIService.js +0 -136
  173. package/dist/node/services/BasedService.js +0 -1156
  174. package/dist/node/services/CoreService.js +0 -1722
  175. package/dist/node/services/SocketIOService.js +0 -278
  176. package/dist/node/services/SocketService.js +0 -142
  177. package/dist/node/services/SymstoryService.js +0 -542
  178. package/dist/node/utils/basedQuerys.js +0 -162
  179. package/dist/node/utils/symstoryClient.js +0 -230
  180. package/src/services/AIService.js +0 -150
  181. package/src/services/BasedService.js +0 -1301
  182. package/src/services/CoreService.js +0 -1943
  183. package/src/services/SocketIOService.js +0 -334
  184. package/src/services/SocketService.js +0 -168
  185. package/src/services/SymstoryService.js +0 -649
  186. package/src/utils/basedQuerys.js +0 -164
  187. package/src/utils/symstoryClient.js +0 -252
@@ -0,0 +1,523 @@
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
@@ -0,0 +1,92 @@
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