@symbo.ls/sdk 3.2.3 → 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.
- package/README.md +141 -0
- package/dist/cjs/config/environment.js +94 -10
- package/dist/cjs/index.js +152 -12
- package/dist/cjs/services/AdminService.js +351 -0
- package/dist/cjs/services/AuthService.js +738 -305
- package/dist/cjs/services/BaseService.js +158 -6
- package/dist/cjs/services/BranchService.js +484 -0
- package/dist/cjs/services/CollabService.js +439 -116
- package/dist/cjs/services/DnsService.js +340 -0
- package/dist/cjs/services/FeatureFlagService.js +175 -0
- package/dist/cjs/services/FileService.js +201 -0
- package/dist/cjs/services/IntegrationService.js +538 -0
- package/dist/cjs/services/MetricsService.js +62 -0
- package/dist/cjs/services/PaymentService.js +271 -0
- package/dist/cjs/services/PlanService.js +426 -0
- package/dist/cjs/services/ProjectService.js +1207 -0
- package/dist/cjs/services/PullRequestService.js +503 -0
- package/dist/cjs/services/ScreenshotService.js +304 -0
- package/dist/cjs/services/SubscriptionService.js +396 -0
- package/dist/cjs/services/TrackingService.js +661 -0
- package/dist/cjs/services/WaitlistService.js +148 -0
- package/dist/cjs/services/index.js +60 -4
- package/dist/cjs/state/RootStateManager.js +2 -23
- package/dist/cjs/state/rootEventBus.js +9 -0
- package/dist/cjs/utils/CollabClient.js +78 -12
- package/dist/cjs/utils/TokenManager.js +16 -3
- package/dist/cjs/utils/changePreprocessor.js +199 -0
- package/dist/cjs/utils/jsonDiff.js +46 -4
- package/dist/cjs/utils/ordering.js +309 -0
- package/dist/cjs/utils/services.js +285 -128
- package/dist/cjs/utils/validation.js +0 -3
- package/dist/esm/config/environment.js +94 -10
- package/dist/esm/index.js +47862 -18248
- package/dist/esm/services/AdminService.js +1132 -0
- package/dist/esm/services/AuthService.js +1493 -386
- package/dist/esm/services/BaseService.js +757 -6
- package/dist/esm/services/BranchService.js +1265 -0
- package/dist/esm/services/CollabService.js +24956 -16089
- package/dist/esm/services/DnsService.js +1121 -0
- package/dist/esm/services/FeatureFlagService.js +956 -0
- package/dist/esm/services/FileService.js +982 -0
- package/dist/esm/services/IntegrationService.js +1319 -0
- package/dist/esm/services/MetricsService.js +843 -0
- package/dist/esm/services/PaymentService.js +1052 -0
- package/dist/esm/services/PlanService.js +1207 -0
- package/dist/esm/services/ProjectService.js +2526 -0
- package/dist/esm/services/PullRequestService.js +1284 -0
- package/dist/esm/services/ScreenshotService.js +1085 -0
- package/dist/esm/services/SubscriptionService.js +1177 -0
- package/dist/esm/services/TrackingService.js +18454 -0
- package/dist/esm/services/WaitlistService.js +929 -0
- package/dist/esm/services/index.js +47373 -18027
- package/dist/esm/state/RootStateManager.js +11 -23
- package/dist/esm/state/rootEventBus.js +9 -0
- package/dist/esm/utils/CollabClient.js +17526 -16120
- package/dist/esm/utils/TokenManager.js +16 -3
- package/dist/esm/utils/changePreprocessor.js +542 -0
- package/dist/esm/utils/jsonDiff.js +958 -43
- package/dist/esm/utils/ordering.js +291 -0
- package/dist/esm/utils/services.js +285 -128
- package/dist/esm/utils/validation.js +116 -50
- package/dist/node/config/environment.js +94 -10
- package/dist/node/index.js +183 -16
- package/dist/node/services/AdminService.js +332 -0
- package/dist/node/services/AuthService.js +742 -310
- package/dist/node/services/BaseService.js +148 -6
- package/dist/node/services/BranchService.js +465 -0
- package/dist/node/services/CollabService.js +439 -116
- package/dist/node/services/DnsService.js +321 -0
- package/dist/node/services/FeatureFlagService.js +156 -0
- package/dist/node/services/FileService.js +182 -0
- package/dist/node/services/IntegrationService.js +519 -0
- package/dist/node/services/MetricsService.js +43 -0
- package/dist/node/services/PaymentService.js +252 -0
- package/dist/node/services/PlanService.js +407 -0
- package/dist/node/services/ProjectService.js +1188 -0
- package/dist/node/services/PullRequestService.js +484 -0
- package/dist/node/services/ScreenshotService.js +285 -0
- package/dist/node/services/SubscriptionService.js +377 -0
- package/dist/node/services/TrackingService.js +632 -0
- package/dist/node/services/WaitlistService.js +129 -0
- package/dist/node/services/index.js +60 -4
- package/dist/node/state/RootStateManager.js +2 -23
- package/dist/node/state/rootEventBus.js +9 -0
- package/dist/node/utils/CollabClient.js +77 -11
- package/dist/node/utils/TokenManager.js +16 -3
- package/dist/node/utils/changePreprocessor.js +180 -0
- package/dist/node/utils/jsonDiff.js +46 -4
- package/dist/node/utils/ordering.js +290 -0
- package/dist/node/utils/services.js +285 -128
- package/dist/node/utils/validation.js +0 -3
- package/package.json +30 -18
- package/src/config/environment.js +95 -10
- package/src/index.js +190 -23
- package/src/services/AdminService.js +374 -0
- package/src/services/AuthService.js +874 -328
- package/src/services/BaseService.js +166 -6
- package/src/services/BranchService.js +536 -0
- package/src/services/CollabService.js +557 -148
- package/src/services/DnsService.js +366 -0
- package/src/services/FeatureFlagService.js +174 -0
- package/src/services/FileService.js +213 -0
- package/src/services/IntegrationService.js +548 -0
- package/src/services/MetricsService.js +40 -0
- package/src/services/PaymentService.js +287 -0
- package/src/services/PlanService.js +468 -0
- package/src/services/ProjectService.js +1366 -0
- package/src/services/PullRequestService.js +537 -0
- package/src/services/ScreenshotService.js +258 -0
- package/src/services/SubscriptionService.js +425 -0
- package/src/services/TrackingService.js +853 -0
- package/src/services/WaitlistService.js +130 -0
- package/src/services/index.js +79 -5
- package/src/services/tests/BranchService/createBranch.test.js +153 -0
- package/src/services/tests/BranchService/deleteBranch.test.js +173 -0
- package/src/services/tests/BranchService/getBranchChanges.test.js +146 -0
- package/src/services/tests/BranchService/listBranches.test.js +87 -0
- package/src/services/tests/BranchService/mergeBranch.test.js +210 -0
- package/src/services/tests/BranchService/publishVersion.test.js +183 -0
- package/src/services/tests/BranchService/renameBranch.test.js +240 -0
- package/src/services/tests/BranchService/resetBranch.test.js +152 -0
- package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +67 -0
- package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +75 -0
- package/src/services/tests/FileService/createFileFormData.test.js +74 -0
- package/src/services/tests/FileService/getFileUrl.test.js +69 -0
- package/src/services/tests/FileService/updateProjectIcon.test.js +109 -0
- package/src/services/tests/FileService/uploadDocument.test.js +36 -0
- package/src/services/tests/FileService/uploadFile.test.js +78 -0
- package/src/services/tests/FileService/uploadFileWithValidation.test.js +114 -0
- package/src/services/tests/FileService/uploadImage.test.js +36 -0
- package/src/services/tests/FileService/uploadMultipleFiles.test.js +111 -0
- package/src/services/tests/FileService/validateFile.test.js +63 -0
- package/src/services/tests/PlanService/createPlan.test.js +104 -0
- package/src/services/tests/PlanService/createPlanWithValidation.test.js +523 -0
- package/src/services/tests/PlanService/deletePlan.test.js +92 -0
- package/src/services/tests/PlanService/getActivePlans.test.js +123 -0
- package/src/services/tests/PlanService/getAdminPlans.test.js +84 -0
- package/src/services/tests/PlanService/getPlan.test.js +50 -0
- package/src/services/tests/PlanService/getPlanByKey.test.js +109 -0
- package/src/services/tests/PlanService/getPlanWithValidation.test.js +85 -0
- package/src/services/tests/PlanService/getPlans.test.js +53 -0
- package/src/services/tests/PlanService/getPlansByPriceRange.test.js +109 -0
- package/src/services/tests/PlanService/getPlansWithValidation.test.js +48 -0
- package/src/services/tests/PlanService/initializePlans.test.js +75 -0
- package/src/services/tests/PlanService/updatePlan.test.js +111 -0
- package/src/services/tests/PlanService/updatePlanWithValidation.test.js +556 -0
- package/src/state/RootStateManager.js +37 -32
- package/src/state/rootEventBus.js +19 -0
- package/src/utils/CollabClient.js +99 -12
- package/src/utils/TokenManager.js +20 -3
- package/src/utils/changePreprocessor.js +239 -0
- package/src/utils/jsonDiff.js +40 -5
- package/src/utils/ordering.js +271 -0
- package/src/utils/services.js +306 -139
- package/src/utils/validation.js +0 -3
- package/dist/cjs/services/AIService.js +0 -155
- package/dist/cjs/services/BasedService.js +0 -1185
- package/dist/cjs/services/CoreService.js +0 -2295
- package/dist/cjs/services/SocketService.js +0 -309
- package/dist/cjs/services/SymstoryService.js +0 -571
- package/dist/cjs/utils/basedQuerys.js +0 -181
- package/dist/cjs/utils/symstoryClient.js +0 -259
- package/dist/esm/services/AIService.js +0 -185
- package/dist/esm/services/BasedService.js +0 -5262
- package/dist/esm/services/CoreService.js +0 -2827
- package/dist/esm/services/SocketService.js +0 -456
- package/dist/esm/services/SymstoryService.js +0 -7025
- package/dist/esm/utils/basedQuerys.js +0 -163
- package/dist/esm/utils/symstoryClient.js +0 -354
- package/dist/node/services/AIService.js +0 -136
- package/dist/node/services/BasedService.js +0 -1156
- package/dist/node/services/CoreService.js +0 -2266
- package/dist/node/services/SocketService.js +0 -280
- package/dist/node/services/SymstoryService.js +0 -542
- package/dist/node/utils/basedQuerys.js +0 -162
- package/dist/node/utils/symstoryClient.js +0 -230
- package/src/services/AIService.js +0 -150
- package/src/services/BasedService.js +0 -1302
- package/src/services/CoreService.js +0 -2548
- package/src/services/SocketService.js +0 -336
- package/src/services/SymstoryService.js +0 -649
- package/src/utils/basedQuerys.js +0 -164
- 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
|