@symbo.ls/sdk 2.34.35 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/README.md +13 -315
  2. package/dist/cjs/config/environment.js +50 -124
  3. package/dist/cjs/index.js +22 -169
  4. package/dist/cjs/services/AIService.js +155 -0
  5. package/dist/cjs/services/AuthService.js +277 -751
  6. package/dist/cjs/services/BaseService.js +6 -158
  7. package/dist/cjs/services/BasedService.js +679 -0
  8. package/dist/cjs/services/SocketIOService.js +309 -0
  9. package/dist/cjs/services/SocketService.js +161 -0
  10. package/dist/cjs/services/SymstoryService.js +485 -0
  11. package/dist/cjs/services/index.js +16 -64
  12. package/dist/cjs/utils/basedQuerys.js +61 -0
  13. package/dist/cjs/utils/permission.js +4 -4
  14. package/dist/cjs/utils/services.js +80 -301
  15. package/dist/cjs/utils/symstoryClient.js +228 -0
  16. package/dist/cjs/utils/validation.js +3 -0
  17. package/dist/esm/config/environment.js +50 -124
  18. package/dist/esm/index.js +11282 -49789
  19. package/dist/esm/services/AIService.js +185 -0
  20. package/dist/esm/services/AuthService.js +358 -1506
  21. package/dist/esm/services/BaseService.js +6 -757
  22. package/dist/esm/services/BasedService.js +4651 -0
  23. package/dist/esm/services/SocketIOService.js +467 -0
  24. package/dist/esm/services/SocketService.js +191 -0
  25. package/dist/esm/services/SymstoryService.js +6849 -0
  26. package/dist/esm/services/index.js +11188 -49352
  27. package/dist/esm/utils/basedQuerys.js +43 -0
  28. package/dist/esm/utils/permission.js +4 -4
  29. package/dist/esm/utils/services.js +80 -301
  30. package/dist/esm/utils/symstoryClient.js +334 -0
  31. package/dist/esm/utils/validation.js +26 -93
  32. package/dist/node/config/environment.js +50 -124
  33. package/dist/node/index.js +26 -202
  34. package/dist/node/services/AIService.js +136 -0
  35. package/dist/node/services/AuthService.js +278 -751
  36. package/dist/node/services/BaseService.js +6 -148
  37. package/dist/node/services/BasedService.js +650 -0
  38. package/dist/node/services/SocketIOService.js +280 -0
  39. package/dist/node/services/SocketService.js +142 -0
  40. package/dist/node/services/SymstoryService.js +456 -0
  41. package/dist/node/services/index.js +16 -64
  42. package/dist/node/utils/basedQuerys.js +42 -0
  43. package/dist/node/utils/permission.js +4 -4
  44. package/dist/node/utils/services.js +80 -301
  45. package/dist/node/utils/symstoryClient.js +199 -0
  46. package/dist/node/utils/validation.js +3 -0
  47. package/package.json +21 -43
  48. package/src/config/environment.js +50 -126
  49. package/src/index.js +24 -208
  50. package/src/services/AIService.js +150 -0
  51. package/src/services/AuthService.js +298 -893
  52. package/src/services/BaseService.js +6 -166
  53. package/src/services/BasedService.js +722 -0
  54. package/src/services/SocketIOService.js +356 -0
  55. package/src/services/SocketService.js +168 -0
  56. package/src/services/SymstoryService.js +563 -0
  57. package/src/services/index.js +13 -80
  58. package/src/utils/basedQuerys.js +41 -0
  59. package/src/utils/permission.js +4 -4
  60. package/src/utils/services.js +83 -325
  61. package/src/utils/symstoryClient.js +218 -0
  62. package/src/utils/validation.js +3 -0
  63. package/dist/cjs/services/AdminService.js +0 -351
  64. package/dist/cjs/services/BranchService.js +0 -484
  65. package/dist/cjs/services/CollabService.js +0 -743
  66. package/dist/cjs/services/DnsService.js +0 -340
  67. package/dist/cjs/services/FeatureFlagService.js +0 -175
  68. package/dist/cjs/services/FileService.js +0 -201
  69. package/dist/cjs/services/IntegrationService.js +0 -538
  70. package/dist/cjs/services/MetricsService.js +0 -62
  71. package/dist/cjs/services/PaymentService.js +0 -271
  72. package/dist/cjs/services/PlanService.js +0 -426
  73. package/dist/cjs/services/ProjectService.js +0 -1207
  74. package/dist/cjs/services/PullRequestService.js +0 -503
  75. package/dist/cjs/services/ScreenshotService.js +0 -304
  76. package/dist/cjs/services/SubscriptionService.js +0 -396
  77. package/dist/cjs/services/TrackingService.js +0 -661
  78. package/dist/cjs/services/WaitlistService.js +0 -148
  79. package/dist/cjs/state/RootStateManager.js +0 -65
  80. package/dist/cjs/state/rootEventBus.js +0 -74
  81. package/dist/cjs/utils/CollabClient.js +0 -223
  82. package/dist/cjs/utils/TokenManager.js +0 -422
  83. package/dist/cjs/utils/changePreprocessor.js +0 -199
  84. package/dist/cjs/utils/jsonDiff.js +0 -145
  85. package/dist/cjs/utils/ordering.js +0 -309
  86. package/dist/esm/services/AdminService.js +0 -1132
  87. package/dist/esm/services/BranchService.js +0 -1265
  88. package/dist/esm/services/CollabService.js +0 -26838
  89. package/dist/esm/services/DnsService.js +0 -1121
  90. package/dist/esm/services/FeatureFlagService.js +0 -956
  91. package/dist/esm/services/FileService.js +0 -982
  92. package/dist/esm/services/IntegrationService.js +0 -1319
  93. package/dist/esm/services/MetricsService.js +0 -843
  94. package/dist/esm/services/PaymentService.js +0 -1052
  95. package/dist/esm/services/PlanService.js +0 -1207
  96. package/dist/esm/services/ProjectService.js +0 -2526
  97. package/dist/esm/services/PullRequestService.js +0 -1284
  98. package/dist/esm/services/ScreenshotService.js +0 -1085
  99. package/dist/esm/services/SubscriptionService.js +0 -1177
  100. package/dist/esm/services/TrackingService.js +0 -18343
  101. package/dist/esm/services/WaitlistService.js +0 -929
  102. package/dist/esm/state/RootStateManager.js +0 -90
  103. package/dist/esm/state/rootEventBus.js +0 -56
  104. package/dist/esm/utils/CollabClient.js +0 -18901
  105. package/dist/esm/utils/TokenManager.js +0 -408
  106. package/dist/esm/utils/changePreprocessor.js +0 -542
  107. package/dist/esm/utils/jsonDiff.js +0 -7011
  108. package/dist/esm/utils/ordering.js +0 -291
  109. package/dist/node/services/AdminService.js +0 -332
  110. package/dist/node/services/BranchService.js +0 -465
  111. package/dist/node/services/CollabService.js +0 -724
  112. package/dist/node/services/DnsService.js +0 -321
  113. package/dist/node/services/FeatureFlagService.js +0 -156
  114. package/dist/node/services/FileService.js +0 -182
  115. package/dist/node/services/IntegrationService.js +0 -519
  116. package/dist/node/services/MetricsService.js +0 -43
  117. package/dist/node/services/PaymentService.js +0 -252
  118. package/dist/node/services/PlanService.js +0 -407
  119. package/dist/node/services/ProjectService.js +0 -1188
  120. package/dist/node/services/PullRequestService.js +0 -484
  121. package/dist/node/services/ScreenshotService.js +0 -285
  122. package/dist/node/services/SubscriptionService.js +0 -377
  123. package/dist/node/services/TrackingService.js +0 -632
  124. package/dist/node/services/WaitlistService.js +0 -129
  125. package/dist/node/state/RootStateManager.js +0 -36
  126. package/dist/node/state/rootEventBus.js +0 -55
  127. package/dist/node/utils/CollabClient.js +0 -194
  128. package/dist/node/utils/TokenManager.js +0 -403
  129. package/dist/node/utils/changePreprocessor.js +0 -180
  130. package/dist/node/utils/jsonDiff.js +0 -116
  131. package/dist/node/utils/ordering.js +0 -290
  132. package/src/services/AdminService.js +0 -374
  133. package/src/services/BranchService.js +0 -536
  134. package/src/services/CollabService.js +0 -900
  135. package/src/services/DnsService.js +0 -366
  136. package/src/services/FeatureFlagService.js +0 -174
  137. package/src/services/FileService.js +0 -213
  138. package/src/services/IntegrationService.js +0 -548
  139. package/src/services/MetricsService.js +0 -40
  140. package/src/services/PaymentService.js +0 -287
  141. package/src/services/PlanService.js +0 -468
  142. package/src/services/ProjectService.js +0 -1366
  143. package/src/services/PullRequestService.js +0 -537
  144. package/src/services/ScreenshotService.js +0 -258
  145. package/src/services/SubscriptionService.js +0 -425
  146. package/src/services/TrackingService.js +0 -853
  147. package/src/services/WaitlistService.js +0 -130
  148. package/src/services/tests/BranchService/createBranch.test.js +0 -153
  149. package/src/services/tests/BranchService/deleteBranch.test.js +0 -173
  150. package/src/services/tests/BranchService/getBranchChanges.test.js +0 -146
  151. package/src/services/tests/BranchService/listBranches.test.js +0 -87
  152. package/src/services/tests/BranchService/mergeBranch.test.js +0 -210
  153. package/src/services/tests/BranchService/publishVersion.test.js +0 -183
  154. package/src/services/tests/BranchService/renameBranch.test.js +0 -240
  155. package/src/services/tests/BranchService/resetBranch.test.js +0 -152
  156. package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +0 -67
  157. package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +0 -75
  158. package/src/services/tests/FileService/createFileFormData.test.js +0 -74
  159. package/src/services/tests/FileService/getFileUrl.test.js +0 -69
  160. package/src/services/tests/FileService/updateProjectIcon.test.js +0 -109
  161. package/src/services/tests/FileService/uploadDocument.test.js +0 -36
  162. package/src/services/tests/FileService/uploadFile.test.js +0 -78
  163. package/src/services/tests/FileService/uploadFileWithValidation.test.js +0 -114
  164. package/src/services/tests/FileService/uploadImage.test.js +0 -36
  165. package/src/services/tests/FileService/uploadMultipleFiles.test.js +0 -111
  166. package/src/services/tests/FileService/validateFile.test.js +0 -63
  167. package/src/services/tests/PlanService/createPlan.test.js +0 -104
  168. package/src/services/tests/PlanService/createPlanWithValidation.test.js +0 -523
  169. package/src/services/tests/PlanService/deletePlan.test.js +0 -92
  170. package/src/services/tests/PlanService/getActivePlans.test.js +0 -123
  171. package/src/services/tests/PlanService/getAdminPlans.test.js +0 -84
  172. package/src/services/tests/PlanService/getPlan.test.js +0 -50
  173. package/src/services/tests/PlanService/getPlanByKey.test.js +0 -109
  174. package/src/services/tests/PlanService/getPlanWithValidation.test.js +0 -85
  175. package/src/services/tests/PlanService/getPlans.test.js +0 -53
  176. package/src/services/tests/PlanService/getPlansByPriceRange.test.js +0 -109
  177. package/src/services/tests/PlanService/getPlansWithValidation.test.js +0 -48
  178. package/src/services/tests/PlanService/initializePlans.test.js +0 -75
  179. package/src/services/tests/PlanService/updatePlan.test.js +0 -111
  180. package/src/services/tests/PlanService/updatePlanWithValidation.test.js +0 -556
  181. package/src/state/RootStateManager.js +0 -76
  182. package/src/state/rootEventBus.js +0 -67
  183. package/src/utils/CollabClient.js +0 -248
  184. package/src/utils/TokenManager.js +0 -479
  185. package/src/utils/changePreprocessor.js +0 -239
  186. package/src/utils/jsonDiff.js +0 -144
  187. package/src/utils/ordering.js +0 -271
@@ -1,210 +0,0 @@
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
@@ -1,183 +0,0 @@
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
@@ -1,240 +0,0 @@
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