@symbo.ls/sdk 3.2.3 → 3.2.7

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 (183) hide show
  1. package/README.md +141 -0
  2. package/dist/cjs/config/environment.js +94 -10
  3. package/dist/cjs/index.js +152 -12
  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 +439 -116
  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 +60 -4
  23. package/dist/cjs/state/RootStateManager.js +2 -23
  24. package/dist/cjs/state/rootEventBus.js +9 -0
  25. package/dist/cjs/utils/CollabClient.js +78 -12
  26. package/dist/cjs/utils/TokenManager.js +16 -3
  27. package/dist/cjs/utils/changePreprocessor.js +199 -0
  28. package/dist/cjs/utils/jsonDiff.js +46 -4
  29. package/dist/cjs/utils/ordering.js +309 -0
  30. package/dist/cjs/utils/services.js +285 -128
  31. package/dist/cjs/utils/validation.js +0 -3
  32. package/dist/esm/config/environment.js +94 -10
  33. package/dist/esm/index.js +47862 -18248
  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 +24956 -16089
  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 +47373 -18027
  53. package/dist/esm/state/RootStateManager.js +11 -23
  54. package/dist/esm/state/rootEventBus.js +9 -0
  55. package/dist/esm/utils/CollabClient.js +17526 -16120
  56. package/dist/esm/utils/TokenManager.js +16 -3
  57. package/dist/esm/utils/changePreprocessor.js +542 -0
  58. package/dist/esm/utils/jsonDiff.js +958 -43
  59. package/dist/esm/utils/ordering.js +291 -0
  60. package/dist/esm/utils/services.js +285 -128
  61. package/dist/esm/utils/validation.js +116 -50
  62. package/dist/node/config/environment.js +94 -10
  63. package/dist/node/index.js +183 -16
  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 +439 -116
  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 +60 -4
  83. package/dist/node/state/RootStateManager.js +2 -23
  84. package/dist/node/state/rootEventBus.js +9 -0
  85. package/dist/node/utils/CollabClient.js +77 -11
  86. package/dist/node/utils/TokenManager.js +16 -3
  87. package/dist/node/utils/changePreprocessor.js +180 -0
  88. package/dist/node/utils/jsonDiff.js +46 -4
  89. package/dist/node/utils/ordering.js +290 -0
  90. package/dist/node/utils/services.js +285 -128
  91. package/dist/node/utils/validation.js +0 -3
  92. package/package.json +30 -18
  93. package/src/config/environment.js +95 -10
  94. package/src/index.js +190 -23
  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 +557 -148
  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 +79 -5
  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 +37 -32
  148. package/src/state/rootEventBus.js +19 -0
  149. package/src/utils/CollabClient.js +99 -12
  150. package/src/utils/TokenManager.js +20 -3
  151. package/src/utils/changePreprocessor.js +239 -0
  152. package/src/utils/jsonDiff.js +40 -5
  153. package/src/utils/ordering.js +271 -0
  154. package/src/utils/services.js +306 -139
  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 -2295
  159. package/dist/cjs/services/SocketService.js +0 -309
  160. package/dist/cjs/services/SymstoryService.js +0 -571
  161. package/dist/cjs/utils/basedQuerys.js +0 -181
  162. package/dist/cjs/utils/symstoryClient.js +0 -259
  163. package/dist/esm/services/AIService.js +0 -185
  164. package/dist/esm/services/BasedService.js +0 -5262
  165. package/dist/esm/services/CoreService.js +0 -2827
  166. package/dist/esm/services/SocketService.js +0 -456
  167. package/dist/esm/services/SymstoryService.js +0 -7025
  168. package/dist/esm/utils/basedQuerys.js +0 -163
  169. package/dist/esm/utils/symstoryClient.js +0 -354
  170. package/dist/node/services/AIService.js +0 -136
  171. package/dist/node/services/BasedService.js +0 -1156
  172. package/dist/node/services/CoreService.js +0 -2266
  173. package/dist/node/services/SocketService.js +0 -280
  174. package/dist/node/services/SymstoryService.js +0 -542
  175. package/dist/node/utils/basedQuerys.js +0 -162
  176. package/dist/node/utils/symstoryClient.js +0 -230
  177. package/src/services/AIService.js +0 -150
  178. package/src/services/BasedService.js +0 -1302
  179. package/src/services/CoreService.js +0 -2548
  180. package/src/services/SocketService.js +0 -336
  181. package/src/services/SymstoryService.js +0 -649
  182. package/src/utils/basedQuerys.js +0 -164
  183. package/src/utils/symstoryClient.js +0 -252
@@ -0,0 +1,87 @@
1
+ /* eslint-disable no-undefined */
2
+ import test from 'tape'
3
+ import sinon from 'sinon'
4
+ import { BranchService } from '../../BranchService.js'
5
+
6
+ // #region Setup
7
+ const sandbox = sinon.createSandbox()
8
+ // #endregion
9
+
10
+ // #region Tests
11
+ test('listBranches should return response data', async t => {
12
+ t.plan(1)
13
+ const responseStub = {
14
+ success: true,
15
+ data: 'Test data response'
16
+ }
17
+ const testProjectId = 'Test Project ID'
18
+ const branchServiceStub = new BranchService()
19
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
20
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
21
+ const response = await branchServiceStub.listBranches(testProjectId)
22
+ t.equal(
23
+ response,
24
+ responseStub.data,
25
+ 'Actual response matches expected response'
26
+ )
27
+ sandbox.restore()
28
+ t.end()
29
+ })
30
+
31
+ function checkProjectIdValidation () {
32
+ const badData = [
33
+ {
34
+ name: 'No Project ID'
35
+ },
36
+ {
37
+ name: 'Empty string',
38
+ value: ''
39
+ },
40
+ {
41
+ name: 'False boolean value',
42
+ value: false
43
+ },
44
+ {
45
+ name: 'Undefined value',
46
+ value: undefined
47
+ },
48
+ {
49
+ name: 'Null value',
50
+ value: null
51
+ }
52
+ ]
53
+ for (let ii = 0; ii < badData.length; ii++) {
54
+ test(`Project ID validation should throw an error when: ${badData[ii].name} is passed in`, async t => {
55
+ t.plan(1)
56
+ const responseStub = {
57
+ success: true,
58
+ data: 'Test data response'
59
+ }
60
+ const testProjectId = badData[ii].value
61
+ const branchServiceStub = new BranchService()
62
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
63
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
64
+ try {
65
+ await branchServiceStub.listBranches(testProjectId)
66
+ t.fail('Project ID validation threw an error with an invalid value')
67
+ } catch (err) {
68
+ t.equal(
69
+ err.toString(),
70
+ 'Error: Project ID is required',
71
+ `Project ID validation successfully threw an error with: ${badData[ii].name}`
72
+ )
73
+ }
74
+ sandbox.restore()
75
+ t.end()
76
+ })
77
+ }
78
+ }
79
+ checkProjectIdValidation()
80
+ // #endregion
81
+
82
+ // #region Cleanup
83
+ test('teardown', t => {
84
+ sandbox.restore()
85
+ t.end()
86
+ })
87
+ // #endregion
@@ -0,0 +1,210 @@
1
+ /* eslint-disable no-undefined */
2
+ import test from 'tape'
3
+ import sinon from 'sinon'
4
+ import { BranchService } from '../../BranchService.js'
5
+
6
+ // #region Setup
7
+ const sandbox = sinon.createSandbox()
8
+ // #endregion
9
+
10
+ // #region Tests
11
+ test('mergeBranch should return response data', async (t) => {
12
+ t.plan(1)
13
+ const responseStub = {
14
+ success: true,
15
+ data: 'Test data response'
16
+ }
17
+ const branchDataMock = {
18
+ name: 'Test_Branch_Name'
19
+ }
20
+ const testProjectId = 'Test Project ID'
21
+ const branchServiceStub = new BranchService()
22
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
23
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
24
+ const response = await branchServiceStub.mergeBranch(
25
+ testProjectId,
26
+ branchDataMock.name
27
+ )
28
+ t.equal(
29
+ response,
30
+ responseStub.data,
31
+ 'Actual response matches expected response'
32
+ )
33
+ sandbox.restore()
34
+ t.end()
35
+ })
36
+
37
+ test('mergeBranch should handle error', async (t) => {
38
+ t.plan(1)
39
+ const branchDataMock = {
40
+ name: 'Test_Branch_Name'
41
+ }
42
+ const testProjectId = 'Test Project ID'
43
+ const branchServiceStub = new BranchService()
44
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
45
+ sandbox.stub(branchServiceStub, '_request').throws('Test Error')
46
+ try {
47
+ await branchServiceStub.mergeBranch(testProjectId, branchDataMock.name)
48
+ t.fail('mergeBranch successfully failed')
49
+ } catch (err) {
50
+ t.equal(
51
+ err.toString(),
52
+ 'Error: Failed to merge branch: Sinon-provided Test Error',
53
+ 'Actual error matches expected error'
54
+ )
55
+ }
56
+ sandbox.restore()
57
+ t.end()
58
+ })
59
+
60
+ function checkProjectIdValidation () {
61
+ const badData = [
62
+ {
63
+ testName: 'No Project ID'
64
+ },
65
+ {
66
+ testName: 'Empty string',
67
+ projectId: ''
68
+ },
69
+ {
70
+ testName: 'False boolean value',
71
+ projectId: false
72
+ },
73
+ {
74
+ testName: 'Undefined value',
75
+ projectId: undefined
76
+ },
77
+ {
78
+ testName: 'Null value',
79
+ projectId: null
80
+ }
81
+ ]
82
+ for (let ii = 0; ii < badData.length; ii++) {
83
+ test(`Project ID validation should throw an error when: ${badData[ii].testName} is passed in`, async (t) => {
84
+ t.plan(1)
85
+ const responseStub = {
86
+ success: true,
87
+ data: 'Test data response'
88
+ }
89
+ const branchDataMock = {
90
+ name: 'Test_Branch_Name'
91
+ }
92
+ const testProjectId = badData[ii].projectId
93
+ const branchServiceStub = new BranchService()
94
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
95
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
96
+ try {
97
+ await branchServiceStub.mergeBranch(testProjectId, branchDataMock.name)
98
+ t.fail('Project ID validation threw an error with an invalid value')
99
+ } catch (err) {
100
+ t.equal(
101
+ err.toString(),
102
+ 'Error: Project ID is required',
103
+ `Project ID validation successfully threw an error with: ${badData[ii].testName}`
104
+ )
105
+ }
106
+ sandbox.restore()
107
+ t.end()
108
+ })
109
+ }
110
+ }
111
+
112
+ function checkBranchDataNameValidation () {
113
+ const badData = [
114
+ {
115
+ testName: 'No name'
116
+ },
117
+ {
118
+ testName: 'Empty string',
119
+ name: ''
120
+ },
121
+ {
122
+ testName: 'False boolean value',
123
+ name: false
124
+ },
125
+ {
126
+ testName: 'Undefined value',
127
+ name: undefined
128
+ },
129
+ {
130
+ testName: 'Null value',
131
+ name: null
132
+ }
133
+ ]
134
+ for (let ii = 0; ii < badData.length; ii++) {
135
+ test(`Branch name validation should throw an error when: ${badData[ii].testName} is passed in`, async (t) => {
136
+ t.plan(1)
137
+ const responseStub = {
138
+ success: true,
139
+ data: 'Test data response'
140
+ }
141
+ const testProjectId = 'Test Project ID'
142
+ const branchServiceStub = new BranchService()
143
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
144
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
145
+ try {
146
+ await branchServiceStub.mergeBranch(testProjectId, badData[ii].name)
147
+ t.fail('Branch name validation threw an error with an invalid value')
148
+ } catch (err) {
149
+ t.equal(
150
+ err.toString(),
151
+ 'Error: Source branch name is required',
152
+ `Branch name validation successfully threw an error with: ${badData[ii].testName}`
153
+ )
154
+ }
155
+ sandbox.restore()
156
+ t.end()
157
+ })
158
+ }
159
+ }
160
+
161
+ function checkMergeConflictErrorHandling () {
162
+ const mergeError = [
163
+ {
164
+ name: 'merge conflict error',
165
+ value: 'conflicts',
166
+ expectedError: 'Error: Merge conflicts detected: Sinon-provided conflicts'
167
+ },
168
+ {
169
+ name: '409 Conflict client error',
170
+ value: '409',
171
+ expectedError: 'Error: Merge conflicts detected: Sinon-provided 409'
172
+ }
173
+ ]
174
+ for (let ii = 0; ii < mergeError.length; ii++) {
175
+ test(`mergeBranch should handle ${mergeError[ii].name}`, async (t) => {
176
+ t.plan(1)
177
+ const branchDataMock = {
178
+ name: 'Test_Branch_Name'
179
+ }
180
+ const testProjectId = 'Test Project ID'
181
+ const branchServiceStub = new BranchService()
182
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
183
+ sandbox.stub(branchServiceStub, '_request').throws(mergeError[ii].value)
184
+ try {
185
+ await branchServiceStub.mergeBranch(testProjectId, branchDataMock.name)
186
+ t.fail('mergeBranch successfully failed')
187
+ } catch (err) {
188
+ t.equal(
189
+ err.toString(),
190
+ mergeError[ii].expectedError,
191
+ 'Actual error matches expected error'
192
+ )
193
+ }
194
+ sandbox.restore()
195
+ t.end()
196
+ })
197
+ }
198
+ }
199
+
200
+ checkBranchDataNameValidation()
201
+ checkProjectIdValidation()
202
+ checkMergeConflictErrorHandling()
203
+ // #endregion
204
+
205
+ // #region Cleanup
206
+ test('teardown', (t) => {
207
+ sandbox.restore()
208
+ t.end()
209
+ })
210
+ // #endregion
@@ -0,0 +1,183 @@
1
+ /* eslint-disable no-undefined */
2
+ import test from 'tape'
3
+ import sinon from 'sinon'
4
+ import { BranchService } from '../../BranchService.js'
5
+
6
+ // #region Setup
7
+ const sandbox = sinon.createSandbox()
8
+ // #endregion
9
+
10
+ // #region Tests
11
+ test('publishVersion should return response data', async (t) => {
12
+ t.plan(1)
13
+ const responseStub = {
14
+ success: true,
15
+ data: 'Test data response'
16
+ }
17
+ const publishVersionMock = {
18
+ name: 'Test_Branch_Name',
19
+ version: '1.0.0',
20
+ branch: 'main'
21
+ }
22
+ const testProjectId = 'Test Project ID'
23
+ const branchServiceStub = new BranchService()
24
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
25
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
26
+ const response = await branchServiceStub.publishVersion(
27
+ testProjectId,
28
+ publishVersionMock
29
+ )
30
+ t.equal(
31
+ response,
32
+ responseStub.data,
33
+ 'Actual response matches expected response'
34
+ )
35
+ sandbox.restore()
36
+ t.end()
37
+ })
38
+
39
+ test('publishVersion should return response data', async (t) => {
40
+ t.plan(1)
41
+ const publishVersionMock = {
42
+ name: 'Test_Branch_Name',
43
+ version: '1.0.0',
44
+ branch: 'main'
45
+ }
46
+ const testProjectId = 'Test Project ID'
47
+ const branchServiceStub = new BranchService()
48
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
49
+ sandbox.stub(branchServiceStub, '_request').throws('Test Error')
50
+ try {
51
+ await branchServiceStub.publishVersion(testProjectId, publishVersionMock)
52
+ t.fail('publish version threw an error')
53
+ } catch (err) {
54
+ t.equal(
55
+ err.toString(),
56
+ 'Error: Failed to publish version: Sinon-provided Test Error',
57
+ 'Actual error matches expected error'
58
+ )
59
+ }
60
+ sandbox.restore()
61
+ t.end()
62
+ })
63
+
64
+ function checkProjectIdValidation () {
65
+ const badData = [
66
+ {
67
+ testName: 'No Project ID'
68
+ },
69
+ {
70
+ testName: 'Empty string',
71
+ projectId: ''
72
+ },
73
+ {
74
+ testName: 'False boolean value',
75
+ projectId: false
76
+ },
77
+ {
78
+ testName: 'Undefined value',
79
+ projectId: undefined
80
+ },
81
+ {
82
+ testName: 'Null value',
83
+ projectId: null
84
+ }
85
+ ]
86
+ for (let ii = 0; ii < badData.length; ii++) {
87
+ test(`Project ID validation should throw an error when: ${badData[ii].testName} is passed in`, async (t) => {
88
+ t.plan(1)
89
+ const responseStub = {
90
+ success: true,
91
+ data: 'Test data response'
92
+ }
93
+ const publishVersionMock = {
94
+ name: 'Test_Branch_Name',
95
+ version: '1.0.0',
96
+ branch: 'main'
97
+ }
98
+ const testProjectId = badData[ii].projectId
99
+ const branchServiceStub = new BranchService()
100
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
101
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
102
+ try {
103
+ await branchServiceStub.publishVersion(
104
+ testProjectId,
105
+ publishVersionMock
106
+ )
107
+ t.fail('Project ID validation threw an error with an invalid value')
108
+ } catch (err) {
109
+ t.equal(
110
+ err.toString(),
111
+ 'Error: Project ID is required',
112
+ `Project ID validation successfully threw an error with: ${badData[ii].testName}`
113
+ )
114
+ }
115
+ sandbox.restore()
116
+ t.end()
117
+ })
118
+ }
119
+ }
120
+
121
+ function checkBranchDataNameValidation () {
122
+ const badData = [
123
+ {
124
+ testName: 'No name',
125
+ branch: 'main'
126
+ },
127
+ {
128
+ testName: 'Empty string',
129
+ version: '',
130
+ branch: 'main'
131
+ },
132
+ {
133
+ testName: 'False boolean value',
134
+ version: false,
135
+ branch: 'main'
136
+ },
137
+ {
138
+ testName: 'Undefined value',
139
+ version: undefined,
140
+ branch: 'main'
141
+ },
142
+ {
143
+ testName: 'Null value',
144
+ version: null,
145
+ branch: 'main'
146
+ }
147
+ ]
148
+ for (let ii = 0; ii < badData.length; ii++) {
149
+ test(`publishData version validation should throw an error when: ${badData[ii].testName} is passed in`, async (t) => {
150
+ t.plan(1)
151
+ const responseStub = {
152
+ success: true,
153
+ data: 'Test data response'
154
+ }
155
+ const testProjectId = 'Test Project ID'
156
+ const branchServiceStub = new BranchService()
157
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
158
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
159
+ try {
160
+ await branchServiceStub.publishVersion(testProjectId, badData[ii])
161
+ t.fail('Branch name validation threw an error with an invalid value')
162
+ } catch (err) {
163
+ t.equal(
164
+ err.toString(),
165
+ 'Error: Version is required',
166
+ `publishData version validation successfully threw an error with: ${badData[ii].testName}`
167
+ )
168
+ }
169
+ sandbox.restore()
170
+ t.end()
171
+ })
172
+ }
173
+ }
174
+ checkBranchDataNameValidation()
175
+ checkProjectIdValidation()
176
+ // #endregion
177
+
178
+ // #region Cleanup
179
+ test('teardown', (t) => {
180
+ sandbox.restore()
181
+ t.end()
182
+ })
183
+ // #endregion
@@ -0,0 +1,240 @@
1
+ /* eslint-disable no-undefined */
2
+ import test from 'tape'
3
+ import sinon from 'sinon'
4
+ import { BranchService } from '../../BranchService.js'
5
+
6
+ // #region Setup
7
+ const sandbox = sinon.createSandbox()
8
+ // #endregion
9
+
10
+ // #region Tests
11
+ test('renameBranch should return response data', async t => {
12
+ t.plan(2)
13
+ const responseStub = {
14
+ success: true,
15
+ data: 'Test data response'
16
+ }
17
+ const branchDataMock = {
18
+ name: 'Test_Branch_Name',
19
+ branch: 'not_main'
20
+ }
21
+ const testProjectId = 'Test Project ID'
22
+ const testNewBranchName = 'Test_New_Branch_Name'
23
+ const branchServiceStub = new BranchService()
24
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
25
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
26
+ const response = await branchServiceStub.renameBranch(
27
+ testProjectId,
28
+ branchDataMock.branch,
29
+ testNewBranchName
30
+ )
31
+ t.ok(response.success, 'Response successfully returned')
32
+ t.equal(
33
+ response.data,
34
+ responseStub.data,
35
+ 'Actual response matches expected response'
36
+ )
37
+ sandbox.restore()
38
+ t.end()
39
+ })
40
+
41
+ test('Branch name validation should throw an error when the branch is main', async t => {
42
+ t.plan(1)
43
+ const responseStub = {
44
+ success: true,
45
+ data: 'Test data response'
46
+ }
47
+ const branchServiceStub = new BranchService()
48
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
49
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
50
+ try {
51
+ await branchServiceStub.renameBranch(
52
+ 'Test Project ID',
53
+ 'main',
54
+ 'Test_New_Branch_Name'
55
+ )
56
+ t.fail('Branch name validation threw an error with an invalid value')
57
+ } catch (err) {
58
+ t.equal(
59
+ err.toString(),
60
+ 'Error: Cannot rename main branch',
61
+ 'renameBranch successfully threw an error when the main branch is deleted'
62
+ )
63
+ }
64
+ sandbox.restore()
65
+ t.end()
66
+ })
67
+
68
+ function checkProjectIdValidation () {
69
+ const badData = [
70
+ {
71
+ testName: 'No Project ID'
72
+ },
73
+ {
74
+ testName: 'Empty string',
75
+ projectId: ''
76
+ },
77
+ {
78
+ testName: 'False boolean value',
79
+ projectId: false
80
+ },
81
+ {
82
+ testName: 'Undefined value',
83
+ projectId: undefined
84
+ },
85
+ {
86
+ testName: 'Null value',
87
+ projectId: null
88
+ }
89
+ ]
90
+ for (let ii = 0; ii < badData.length; ii++) {
91
+ test(`Project ID validation should throw an error when: ${badData[ii].testName} is passed in`, async t => {
92
+ t.plan(1)
93
+ const responseStub = {
94
+ success: true,
95
+ data: 'Test data response'
96
+ }
97
+ const branchDataMock = {
98
+ name: 'Test_Branch_Name',
99
+ branch: 'not_main'
100
+ }
101
+ const testProjectId = badData[ii].projectId
102
+ const branchServiceStub = new BranchService()
103
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
104
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
105
+ try {
106
+ await branchServiceStub.renameBranch(
107
+ testProjectId,
108
+ branchDataMock.branch,
109
+ 'Test_New_Branch_Name'
110
+ )
111
+ t.fail('Project ID validation threw an error with an invalid value')
112
+ } catch (err) {
113
+ t.equal(
114
+ err.toString(),
115
+ 'Error: Project ID is required',
116
+ `Project ID validation successfully threw an error with: ${badData[ii].testName}`
117
+ )
118
+ }
119
+ sandbox.restore()
120
+ t.end()
121
+ })
122
+ }
123
+ }
124
+
125
+ function checkBranchDataNameValidation () {
126
+ const badData = [
127
+ {
128
+ testName: 'No name'
129
+ },
130
+ {
131
+ testName: 'Empty string',
132
+ name: ''
133
+ },
134
+ {
135
+ testName: 'False boolean value',
136
+ name: false
137
+ },
138
+ {
139
+ testName: 'Undefined value',
140
+ name: undefined
141
+ },
142
+ {
143
+ testName: 'Null value',
144
+ name: null
145
+ }
146
+ ]
147
+ for (let ii = 0; ii < badData.length; ii++) {
148
+ test(`Branch name validation should throw an error when: ${badData[ii].testName} is passed in`, async t => {
149
+ t.plan(1)
150
+ const responseStub = {
151
+ success: true,
152
+ data: 'Test data response'
153
+ }
154
+ const testProjectId = 'Test Project ID'
155
+ const branchServiceStub = new BranchService()
156
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
157
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
158
+ try {
159
+ await branchServiceStub.renameBranch(
160
+ testProjectId,
161
+ badData[ii].name,
162
+ 'Test_New_Branch_Name'
163
+ )
164
+ t.fail('Branch name validation threw an error with an invalid value')
165
+ } catch (err) {
166
+ t.equal(
167
+ err.toString(),
168
+ 'Error: Current branch name is required',
169
+ `Branch name validation successfully threw an error with: ${badData[ii].testName}`
170
+ )
171
+ }
172
+ sandbox.restore()
173
+ t.end()
174
+ })
175
+ }
176
+ }
177
+
178
+ function checkNewBranchNameValidation () {
179
+ const badData = [
180
+ {
181
+ testName: 'No name'
182
+ },
183
+ {
184
+ testName: 'Empty string',
185
+ name: ''
186
+ },
187
+ {
188
+ testName: 'False boolean value',
189
+ name: false
190
+ },
191
+ {
192
+ testName: 'Undefined value',
193
+ name: undefined
194
+ },
195
+ {
196
+ testName: 'Null value',
197
+ name: null
198
+ }
199
+ ]
200
+ for (let ii = 0; ii < badData.length; ii++) {
201
+ test(`New branch name validation should throw an error when: ${badData[ii].testName} is passed in`, async t => {
202
+ t.plan(1)
203
+ const responseStub = {
204
+ success: true,
205
+ data: 'Test data response'
206
+ }
207
+ const branchServiceStub = new BranchService()
208
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
209
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
210
+ try {
211
+ await branchServiceStub.renameBranch(
212
+ 'Test Project ID',
213
+ 'Test_Branch_Name',
214
+ badData[ii].name
215
+ )
216
+ t.fail('Branch name validation threw an error with an invalid value')
217
+ } catch (err) {
218
+ t.equal(
219
+ err.toString(),
220
+ 'Error: New branch name is required',
221
+ `Branch name validation successfully threw an error with: ${badData[ii].testName}`
222
+ )
223
+ }
224
+ sandbox.restore()
225
+ t.end()
226
+ })
227
+ }
228
+ }
229
+
230
+ checkBranchDataNameValidation()
231
+ checkNewBranchNameValidation()
232
+ checkProjectIdValidation()
233
+ // #endregion
234
+
235
+ // #region Cleanup
236
+ test('teardown', t => {
237
+ sandbox.restore()
238
+ t.end()
239
+ })
240
+ // #endregion