@symbo.ls/sdk 3.1.2 → 3.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/README.md +143 -2
  2. package/dist/cjs/config/environment.js +98 -30
  3. package/dist/cjs/index.js +144 -24
  4. package/dist/cjs/services/AdminService.js +351 -0
  5. package/dist/cjs/services/AuthService.js +738 -305
  6. package/dist/cjs/services/BaseService.js +158 -6
  7. package/dist/cjs/services/BranchService.js +484 -0
  8. package/dist/cjs/services/CollabService.js +743 -0
  9. package/dist/cjs/services/DnsService.js +340 -0
  10. package/dist/cjs/services/FeatureFlagService.js +175 -0
  11. package/dist/cjs/services/FileService.js +201 -0
  12. package/dist/cjs/services/IntegrationService.js +538 -0
  13. package/dist/cjs/services/MetricsService.js +62 -0
  14. package/dist/cjs/services/PaymentService.js +271 -0
  15. package/dist/cjs/services/PlanService.js +426 -0
  16. package/dist/cjs/services/ProjectService.js +1207 -0
  17. package/dist/cjs/services/PullRequestService.js +503 -0
  18. package/dist/cjs/services/ScreenshotService.js +304 -0
  19. package/dist/cjs/services/SubscriptionService.js +396 -0
  20. package/dist/cjs/services/TrackingService.js +661 -0
  21. package/dist/cjs/services/WaitlistService.js +148 -0
  22. package/dist/cjs/services/index.js +64 -16
  23. package/dist/cjs/state/RootStateManager.js +65 -0
  24. package/dist/cjs/state/rootEventBus.js +74 -0
  25. package/dist/cjs/utils/CollabClient.js +223 -0
  26. package/dist/cjs/utils/TokenManager.js +78 -30
  27. package/dist/cjs/utils/changePreprocessor.js +199 -0
  28. package/dist/cjs/utils/jsonDiff.js +145 -0
  29. package/dist/cjs/utils/ordering.js +309 -0
  30. package/dist/cjs/utils/services.js +301 -103
  31. package/dist/cjs/utils/validation.js +0 -3
  32. package/dist/esm/config/environment.js +98 -30
  33. package/dist/esm/index.js +49505 -8718
  34. package/dist/esm/services/AdminService.js +1132 -0
  35. package/dist/esm/services/AuthService.js +1493 -386
  36. package/dist/esm/services/BaseService.js +757 -6
  37. package/dist/esm/services/BranchService.js +1265 -0
  38. package/dist/esm/services/CollabService.js +26895 -0
  39. package/dist/esm/services/DnsService.js +1121 -0
  40. package/dist/esm/services/FeatureFlagService.js +956 -0
  41. package/dist/esm/services/FileService.js +982 -0
  42. package/dist/esm/services/IntegrationService.js +1319 -0
  43. package/dist/esm/services/MetricsService.js +843 -0
  44. package/dist/esm/services/PaymentService.js +1052 -0
  45. package/dist/esm/services/PlanService.js +1207 -0
  46. package/dist/esm/services/ProjectService.js +2526 -0
  47. package/dist/esm/services/PullRequestService.js +1284 -0
  48. package/dist/esm/services/ScreenshotService.js +1085 -0
  49. package/dist/esm/services/SubscriptionService.js +1177 -0
  50. package/dist/esm/services/TrackingService.js +18454 -0
  51. package/dist/esm/services/WaitlistService.js +929 -0
  52. package/dist/esm/services/index.js +49062 -8569
  53. package/dist/esm/state/RootStateManager.js +90 -0
  54. package/dist/esm/state/rootEventBus.js +56 -0
  55. package/dist/esm/utils/CollabClient.js +18889 -0
  56. package/dist/esm/utils/TokenManager.js +78 -30
  57. package/dist/esm/utils/changePreprocessor.js +542 -0
  58. package/dist/esm/utils/jsonDiff.js +7011 -0
  59. package/dist/esm/utils/ordering.js +291 -0
  60. package/dist/esm/utils/services.js +301 -103
  61. package/dist/esm/utils/validation.js +116 -50
  62. package/dist/node/config/environment.js +98 -30
  63. package/dist/node/index.js +175 -32
  64. package/dist/node/services/AdminService.js +332 -0
  65. package/dist/node/services/AuthService.js +742 -310
  66. package/dist/node/services/BaseService.js +148 -6
  67. package/dist/node/services/BranchService.js +465 -0
  68. package/dist/node/services/CollabService.js +724 -0
  69. package/dist/node/services/DnsService.js +321 -0
  70. package/dist/node/services/FeatureFlagService.js +156 -0
  71. package/dist/node/services/FileService.js +182 -0
  72. package/dist/node/services/IntegrationService.js +519 -0
  73. package/dist/node/services/MetricsService.js +43 -0
  74. package/dist/node/services/PaymentService.js +252 -0
  75. package/dist/node/services/PlanService.js +407 -0
  76. package/dist/node/services/ProjectService.js +1188 -0
  77. package/dist/node/services/PullRequestService.js +484 -0
  78. package/dist/node/services/ScreenshotService.js +285 -0
  79. package/dist/node/services/SubscriptionService.js +377 -0
  80. package/dist/node/services/TrackingService.js +632 -0
  81. package/dist/node/services/WaitlistService.js +129 -0
  82. package/dist/node/services/index.js +64 -16
  83. package/dist/node/state/RootStateManager.js +36 -0
  84. package/dist/node/state/rootEventBus.js +55 -0
  85. package/dist/node/utils/CollabClient.js +194 -0
  86. package/dist/node/utils/TokenManager.js +78 -30
  87. package/dist/node/utils/changePreprocessor.js +180 -0
  88. package/dist/node/utils/jsonDiff.js +116 -0
  89. package/dist/node/utils/ordering.js +290 -0
  90. package/dist/node/utils/services.js +301 -103
  91. package/dist/node/utils/validation.js +0 -3
  92. package/package.json +39 -21
  93. package/src/config/environment.js +99 -28
  94. package/src/index.js +181 -36
  95. package/src/services/AdminService.js +374 -0
  96. package/src/services/AuthService.js +874 -328
  97. package/src/services/BaseService.js +166 -6
  98. package/src/services/BranchService.js +536 -0
  99. package/src/services/CollabService.js +900 -0
  100. package/src/services/DnsService.js +366 -0
  101. package/src/services/FeatureFlagService.js +174 -0
  102. package/src/services/FileService.js +213 -0
  103. package/src/services/IntegrationService.js +548 -0
  104. package/src/services/MetricsService.js +40 -0
  105. package/src/services/PaymentService.js +287 -0
  106. package/src/services/PlanService.js +468 -0
  107. package/src/services/ProjectService.js +1366 -0
  108. package/src/services/PullRequestService.js +537 -0
  109. package/src/services/ScreenshotService.js +258 -0
  110. package/src/services/SubscriptionService.js +425 -0
  111. package/src/services/TrackingService.js +853 -0
  112. package/src/services/WaitlistService.js +130 -0
  113. package/src/services/index.js +80 -13
  114. package/src/services/tests/BranchService/createBranch.test.js +153 -0
  115. package/src/services/tests/BranchService/deleteBranch.test.js +173 -0
  116. package/src/services/tests/BranchService/getBranchChanges.test.js +146 -0
  117. package/src/services/tests/BranchService/listBranches.test.js +87 -0
  118. package/src/services/tests/BranchService/mergeBranch.test.js +210 -0
  119. package/src/services/tests/BranchService/publishVersion.test.js +183 -0
  120. package/src/services/tests/BranchService/renameBranch.test.js +240 -0
  121. package/src/services/tests/BranchService/resetBranch.test.js +152 -0
  122. package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +67 -0
  123. package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +75 -0
  124. package/src/services/tests/FileService/createFileFormData.test.js +74 -0
  125. package/src/services/tests/FileService/getFileUrl.test.js +69 -0
  126. package/src/services/tests/FileService/updateProjectIcon.test.js +109 -0
  127. package/src/services/tests/FileService/uploadDocument.test.js +36 -0
  128. package/src/services/tests/FileService/uploadFile.test.js +78 -0
  129. package/src/services/tests/FileService/uploadFileWithValidation.test.js +114 -0
  130. package/src/services/tests/FileService/uploadImage.test.js +36 -0
  131. package/src/services/tests/FileService/uploadMultipleFiles.test.js +111 -0
  132. package/src/services/tests/FileService/validateFile.test.js +63 -0
  133. package/src/services/tests/PlanService/createPlan.test.js +104 -0
  134. package/src/services/tests/PlanService/createPlanWithValidation.test.js +523 -0
  135. package/src/services/tests/PlanService/deletePlan.test.js +92 -0
  136. package/src/services/tests/PlanService/getActivePlans.test.js +123 -0
  137. package/src/services/tests/PlanService/getAdminPlans.test.js +84 -0
  138. package/src/services/tests/PlanService/getPlan.test.js +50 -0
  139. package/src/services/tests/PlanService/getPlanByKey.test.js +109 -0
  140. package/src/services/tests/PlanService/getPlanWithValidation.test.js +85 -0
  141. package/src/services/tests/PlanService/getPlans.test.js +53 -0
  142. package/src/services/tests/PlanService/getPlansByPriceRange.test.js +109 -0
  143. package/src/services/tests/PlanService/getPlansWithValidation.test.js +48 -0
  144. package/src/services/tests/PlanService/initializePlans.test.js +75 -0
  145. package/src/services/tests/PlanService/updatePlan.test.js +111 -0
  146. package/src/services/tests/PlanService/updatePlanWithValidation.test.js +556 -0
  147. package/src/state/RootStateManager.js +76 -0
  148. package/src/state/rootEventBus.js +67 -0
  149. package/src/utils/CollabClient.js +248 -0
  150. package/src/utils/TokenManager.js +88 -33
  151. package/src/utils/changePreprocessor.js +239 -0
  152. package/src/utils/jsonDiff.js +144 -0
  153. package/src/utils/ordering.js +271 -0
  154. package/src/utils/services.js +326 -107
  155. package/src/utils/validation.js +0 -3
  156. package/dist/cjs/services/AIService.js +0 -155
  157. package/dist/cjs/services/BasedService.js +0 -1185
  158. package/dist/cjs/services/CoreService.js +0 -1751
  159. package/dist/cjs/services/SocketIOService.js +0 -307
  160. package/dist/cjs/services/SocketService.js +0 -161
  161. package/dist/cjs/services/SymstoryService.js +0 -571
  162. package/dist/cjs/utils/basedQuerys.js +0 -181
  163. package/dist/cjs/utils/symstoryClient.js +0 -259
  164. package/dist/esm/services/AIService.js +0 -185
  165. package/dist/esm/services/BasedService.js +0 -5278
  166. package/dist/esm/services/CoreService.js +0 -2264
  167. package/dist/esm/services/SocketIOService.js +0 -470
  168. package/dist/esm/services/SocketService.js +0 -191
  169. package/dist/esm/services/SymstoryService.js +0 -7041
  170. package/dist/esm/utils/basedQuerys.js +0 -163
  171. package/dist/esm/utils/symstoryClient.js +0 -370
  172. package/dist/node/services/AIService.js +0 -136
  173. package/dist/node/services/BasedService.js +0 -1156
  174. package/dist/node/services/CoreService.js +0 -1722
  175. package/dist/node/services/SocketIOService.js +0 -278
  176. package/dist/node/services/SocketService.js +0 -142
  177. package/dist/node/services/SymstoryService.js +0 -542
  178. package/dist/node/utils/basedQuerys.js +0 -162
  179. package/dist/node/utils/symstoryClient.js +0 -230
  180. package/src/services/AIService.js +0 -150
  181. package/src/services/BasedService.js +0 -1301
  182. package/src/services/CoreService.js +0 -1943
  183. package/src/services/SocketIOService.js +0 -334
  184. package/src/services/SocketService.js +0 -168
  185. package/src/services/SymstoryService.js +0 -649
  186. package/src/utils/basedQuerys.js +0 -164
  187. package/src/utils/symstoryClient.js +0 -252
@@ -0,0 +1,130 @@
1
+ import { BaseService } from './BaseService.js'
2
+
3
+ export class WaitlistService extends BaseService {
4
+ // ==================== WAITLIST METHODS ====================
5
+
6
+ /**
7
+ * Join a waitlist campaign (public).
8
+ *
9
+ * Mirrors: POST /waitlist (WaitlistController.join)
10
+ */
11
+ async joinWaitlist (data = {}) {
12
+ this._requireReady('joinWaitlist')
13
+ if (!data || typeof data !== 'object') {
14
+ throw new Error('Waitlist join payload is required')
15
+ }
16
+ if (!data.email) {
17
+ throw new Error('Email is required')
18
+ }
19
+
20
+ try {
21
+ const response = await this._request('/waitlist', {
22
+ method: 'POST',
23
+ body: JSON.stringify(data),
24
+ methodName: 'joinWaitlist'
25
+ })
26
+ if (response.success) {
27
+ return response.data
28
+ }
29
+ throw new Error(response.message)
30
+ } catch (error) {
31
+ throw new Error(`Failed to join waitlist: ${error.message}`, { cause: error })
32
+ }
33
+ }
34
+
35
+ /**
36
+ * List waitlist entries (admin).
37
+ *
38
+ * Mirrors: GET /waitlist (WaitlistController.list)
39
+ */
40
+ async listWaitlistEntries (options = {}) {
41
+ this._requireReady('listWaitlistEntries')
42
+
43
+ const {
44
+ campaignKey,
45
+ status,
46
+ search,
47
+ page,
48
+ limit
49
+ } = options || {}
50
+
51
+ const queryParams = new URLSearchParams()
52
+ if (campaignKey != null) { queryParams.append('campaignKey', String(campaignKey)) }
53
+ if (status != null) { queryParams.append('status', String(status)) }
54
+ if (search != null) { queryParams.append('search', String(search)) }
55
+ if (page != null) { queryParams.append('page', String(page)) }
56
+ if (limit != null) { queryParams.append('limit', String(limit)) }
57
+
58
+ const queryString = queryParams.toString()
59
+ const url = `/waitlist${queryString ? `?${queryString}` : ''}`
60
+
61
+ try {
62
+ const response = await this._request(url, {
63
+ method: 'GET',
64
+ methodName: 'listWaitlistEntries'
65
+ })
66
+ if (response.success) {
67
+ return response.data
68
+ }
69
+ throw new Error(response.message)
70
+ } catch (error) {
71
+ throw new Error(`Failed to list waitlist entries: ${error.message}`, { cause: error })
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Update a waitlist entry (admin).
77
+ *
78
+ * Mirrors: PATCH /waitlist/:id (WaitlistController.update)
79
+ */
80
+ async updateWaitlistEntry (id, update = {}) {
81
+ this._requireReady('updateWaitlistEntry')
82
+ if (!id) {
83
+ throw new Error('Waitlist entry ID is required')
84
+ }
85
+ if (!update || typeof update !== 'object') {
86
+ throw new Error('Update payload is required')
87
+ }
88
+
89
+ try {
90
+ const response = await this._request(`/waitlist/${id}`, {
91
+ method: 'PATCH',
92
+ body: JSON.stringify(update),
93
+ methodName: 'updateWaitlistEntry'
94
+ })
95
+ if (response.success) {
96
+ return response.data
97
+ }
98
+ throw new Error(response.message)
99
+ } catch (error) {
100
+ throw new Error(`Failed to update waitlist entry: ${error.message}`, { cause: error })
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Send an invitation email for a waitlist entry (admin).
106
+ *
107
+ * Mirrors: POST /waitlist/:id/invite (WaitlistController.invite)
108
+ */
109
+ async inviteWaitlistEntry (id) {
110
+ this._requireReady('inviteWaitlistEntry')
111
+ if (!id) {
112
+ throw new Error('Waitlist entry ID is required')
113
+ }
114
+
115
+ try {
116
+ const response = await this._request(`/waitlist/${id}/invite`, {
117
+ method: 'POST',
118
+ methodName: 'inviteWaitlistEntry'
119
+ })
120
+ if (response.success) {
121
+ return response.data
122
+ }
123
+ throw new Error(response.message)
124
+ } catch (error) {
125
+ throw new Error(`Failed to invite waitlist entry: ${error.message}`, { cause: error })
126
+ }
127
+ }
128
+ }
129
+
130
+ // End
@@ -1,23 +1,90 @@
1
- import { SymstoryService } from './SymstoryService.js'
2
1
  import { AuthService } from './AuthService.js'
3
- import { AIService } from './AIService.js'
4
- import { SocketService } from './SocketIOService.js'
5
- import { CoreService } from './CoreService.js'
2
+ import { CollabService } from './CollabService.js'
3
+ import { ProjectService } from './ProjectService.js'
4
+ import { PlanService } from './PlanService.js'
5
+ import { SubscriptionService } from './SubscriptionService.js'
6
+ import { FileService } from './FileService.js'
7
+ import { PaymentService } from './PaymentService.js'
8
+ import { DnsService } from './DnsService.js'
9
+ import { BranchService } from './BranchService.js'
10
+ import { PullRequestService } from './PullRequestService.js'
11
+ import { AdminService } from './AdminService.js'
12
+ import { ScreenshotService } from './ScreenshotService.js'
13
+ import { TrackingService } from './TrackingService.js'
14
+ import { WaitlistService } from './WaitlistService.js'
15
+ import { MetricsService } from './MetricsService.js'
16
+ import { IntegrationService } from './IntegrationService.js'
17
+ import { FeatureFlagService } from './FeatureFlagService.js'
6
18
 
7
19
  const createService = (ServiceClass, config) => new ServiceClass(config)
8
20
 
9
21
  // Export service creators
10
- export const createSymstoryService = config =>
11
- createService(SymstoryService, config)
12
-
13
22
  export const createAuthService = config => createService(AuthService, config)
14
23
 
15
- export const createAIService = config => createService(AIService, config)
24
+ export const createCollabService = config =>
25
+ createService(CollabService, config)
26
+
27
+ export const createProjectService = config =>
28
+ createService(ProjectService, config)
29
+
30
+ export const createPlanService = config =>
31
+ createService(PlanService, config)
32
+
33
+ export const createSubscriptionService = config =>
34
+ createService(SubscriptionService, config)
35
+
36
+ export const createFileService = config =>
37
+ createService(FileService, config)
38
+
39
+ export const createPaymentService = config =>
40
+ createService(PaymentService, config)
41
+
42
+ export const createDnsService = config =>
43
+ createService(DnsService, config)
44
+
45
+ export const createBranchService = config =>
46
+ createService(BranchService, config)
47
+
48
+ export const createPullRequestService = config =>
49
+ createService(PullRequestService, config)
50
+
51
+ export const createAdminService = config =>
52
+ createService(AdminService, config)
53
+
54
+ export const createScreenshotService = config =>
55
+ createService(ScreenshotService, config)
56
+
57
+ export const createTrackingService = config =>
58
+ createService(TrackingService, config)
59
+
60
+ export const createWaitlistService = config =>
61
+ createService(WaitlistService, config)
62
+
63
+ export const createMetricsService = config =>
64
+ createService(MetricsService, config)
16
65
 
17
- export const createSocketService = config =>
18
- createService(SocketService, config)
66
+ export const createIntegrationService = config =>
67
+ createService(IntegrationService, config)
19
68
 
20
- export const createCoreService = config => createService(CoreService, config)
69
+ export const createFeatureFlagService = config =>
70
+ createService(FeatureFlagService, config)
21
71
 
22
- // Export service classes for direct usage
23
- export { SymstoryService, AuthService, AIService, SocketService, CoreService }
72
+ export {
73
+ AuthService,
74
+ CollabService,
75
+ ProjectService,
76
+ PlanService,
77
+ SubscriptionService,
78
+ FileService,
79
+ PaymentService,
80
+ DnsService,
81
+ BranchService,
82
+ PullRequestService,
83
+ AdminService,
84
+ ScreenshotService,
85
+ TrackingService,
86
+ WaitlistService,
87
+ MetricsService,
88
+ IntegrationService,
89
+ FeatureFlagService
90
+ }
@@ -0,0 +1,153 @@
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('createBranch 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
+ source: 'main'
20
+ }
21
+ const testProjectId = 'Test Project ID'
22
+ const branchServiceStub = new BranchService()
23
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
24
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
25
+ const response = await branchServiceStub.createBranch(
26
+ testProjectId,
27
+ branchDataMock
28
+ )
29
+ t.equal(
30
+ response,
31
+ responseStub.data,
32
+ 'Actual response matches expected response'
33
+ )
34
+ sandbox.restore()
35
+ t.end()
36
+ })
37
+
38
+ function checkProjectIdValidation () {
39
+ const badData = [
40
+ {
41
+ testName: 'No Project ID'
42
+ },
43
+ {
44
+ testName: 'Empty string',
45
+ projectId: ''
46
+ },
47
+ {
48
+ testName: 'False boolean value',
49
+ projectId: false
50
+ },
51
+ {
52
+ testName: 'Undefined value',
53
+ projectId: undefined
54
+ },
55
+ {
56
+ testName: 'Null value',
57
+ projectId: null
58
+ }
59
+ ]
60
+ for (let ii = 0; ii < badData.length; ii++) {
61
+ test(`Project ID validation should throw an error when: ${badData[ii].testName} is passed in`, async t => {
62
+ t.plan(1)
63
+ const responseStub = {
64
+ success: true,
65
+ data: 'Test data response'
66
+ }
67
+ const branchDataMock = {
68
+ name: 'Test_Branch_Name',
69
+ source: 'main'
70
+ }
71
+ const testProjectId = badData[ii].projectId
72
+ const branchServiceStub = new BranchService()
73
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
74
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
75
+ try {
76
+ await branchServiceStub.createBranch(testProjectId, branchDataMock)
77
+ t.fail('Project ID validation threw an error with an invalid value')
78
+ } catch (err) {
79
+ t.equal(
80
+ err.toString(),
81
+ 'Error: Project ID is required',
82
+ `Project ID validation successfully threw an error with: ${badData[ii].testName}`
83
+ )
84
+ }
85
+ sandbox.restore()
86
+ t.end()
87
+ })
88
+ }
89
+ }
90
+
91
+ function checkBranchDataNameValidation () {
92
+ const badData = [
93
+ {
94
+ testName: 'No name'
95
+ },
96
+ {
97
+ testName: 'Empty string',
98
+ name: ''
99
+ },
100
+ {
101
+ testName: 'False boolean value',
102
+ name: false
103
+ },
104
+ {
105
+ testName: 'Undefined value',
106
+ name: undefined
107
+ },
108
+ {
109
+ testName: 'Null value',
110
+ name: null
111
+ }
112
+ ]
113
+ for (let ii = 0; ii < badData.length; ii++) {
114
+ test(`Branch name validation should throw an error when: ${badData[ii].testName} is passed in`, async t => {
115
+ t.plan(1)
116
+ const responseStub = {
117
+ success: true,
118
+ data: 'Test data response'
119
+ }
120
+ const branchName = {
121
+ name: badData[ii].name,
122
+ source: 'main'
123
+ }
124
+ const testProjectId = 'Test Project ID'
125
+ const branchServiceStub = new BranchService()
126
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
127
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
128
+ try {
129
+ await branchServiceStub.createBranch(testProjectId, branchName)
130
+ t.fail('Branch name validation threw an error with an invalid value')
131
+ } catch (err) {
132
+ t.equal(
133
+ err.toString(),
134
+ 'Error: Branch name is required',
135
+ `Branch name validation successfully threw an error with: ${badData[ii].testName}`
136
+ )
137
+ }
138
+ sandbox.restore()
139
+ t.end()
140
+ })
141
+ }
142
+ }
143
+
144
+ checkBranchDataNameValidation()
145
+ checkProjectIdValidation()
146
+ // #endregion
147
+
148
+ // #region Cleanup
149
+ test('teardown', t => {
150
+ sandbox.restore()
151
+ t.end()
152
+ })
153
+ // #endregion
@@ -0,0 +1,173 @@
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('deleteBranch 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 branchServiceStub = new BranchService()
23
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
24
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
25
+ const response = await branchServiceStub.deleteBranch(
26
+ testProjectId,
27
+ branchDataMock.branch
28
+ )
29
+ t.ok(response.success, 'Response successfully returned')
30
+ t.equal(
31
+ response.data,
32
+ responseStub.data,
33
+ 'Actual response matches expected response'
34
+ )
35
+ sandbox.restore()
36
+ t.end()
37
+ })
38
+
39
+ test('Branch name validation should throw an error when the branch is main', async t => {
40
+ t.plan(1)
41
+ const responseStub = {
42
+ success: true,
43
+ data: 'Test data response'
44
+ }
45
+ const branchServiceStub = new BranchService()
46
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
47
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
48
+ try {
49
+ await branchServiceStub.deleteBranch('Test Project ID', 'main')
50
+ t.fail('Branch name validation threw an error with an invalid value')
51
+ } catch (err) {
52
+ t.equal(
53
+ err.toString(),
54
+ 'Error: Cannot delete main branch',
55
+ 'deleteBranch successfully threw an error when the main branch is deleted'
56
+ )
57
+ }
58
+ sandbox.restore()
59
+ t.end()
60
+ })
61
+
62
+ function checkProjectIdValidation () {
63
+ const badData = [
64
+ {
65
+ testName: 'No Project ID'
66
+ },
67
+ {
68
+ testName: 'Empty string',
69
+ projectId: ''
70
+ },
71
+ {
72
+ testName: 'False boolean value',
73
+ projectId: false
74
+ },
75
+ {
76
+ testName: 'Undefined value',
77
+ projectId: undefined
78
+ },
79
+ {
80
+ testName: 'Null value',
81
+ projectId: null
82
+ }
83
+ ]
84
+ for (let ii = 0; ii < badData.length; ii++) {
85
+ test(`Project ID validation should throw an error when: ${badData[ii].testName} is passed in`, async t => {
86
+ t.plan(1)
87
+ const responseStub = {
88
+ success: true,
89
+ data: 'Test data response'
90
+ }
91
+ const branchDataMock = {
92
+ name: 'Test_Branch_Name',
93
+ branch: 'not_main'
94
+ }
95
+ const testProjectId = badData[ii].projectId
96
+ const branchServiceStub = new BranchService()
97
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
98
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
99
+ try {
100
+ await branchServiceStub.deleteBranch(testProjectId, branchDataMock)
101
+ t.fail('Project ID validation threw an error with an invalid value')
102
+ } catch (err) {
103
+ t.equal(
104
+ err.toString(),
105
+ 'Error: Project ID is required',
106
+ `Project ID validation successfully threw an error with: ${badData[ii].testName}`
107
+ )
108
+ }
109
+ sandbox.restore()
110
+ t.end()
111
+ })
112
+ }
113
+ }
114
+
115
+ function checkBranchDataNameValidation () {
116
+ const badData = [
117
+ {
118
+ testName: 'No name'
119
+ },
120
+ {
121
+ testName: 'Empty string',
122
+ name: ''
123
+ },
124
+ {
125
+ testName: 'False boolean value',
126
+ name: false
127
+ },
128
+ {
129
+ testName: 'Undefined value',
130
+ name: undefined
131
+ },
132
+ {
133
+ testName: 'Null value',
134
+ name: null
135
+ }
136
+ ]
137
+ for (let ii = 0; ii < badData.length; ii++) {
138
+ test(`Branch name validation should throw an error when: ${badData[ii].testName} is passed in`, async t => {
139
+ t.plan(1)
140
+ const responseStub = {
141
+ success: true,
142
+ data: 'Test data response'
143
+ }
144
+ const testProjectId = 'Test Project ID'
145
+ const branchServiceStub = new BranchService()
146
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
147
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
148
+ try {
149
+ await branchServiceStub.deleteBranch(testProjectId, badData[ii].name)
150
+ t.fail('Branch name validation threw an error with an invalid value')
151
+ } catch (err) {
152
+ t.equal(
153
+ err.toString(),
154
+ 'Error: Branch name is required',
155
+ `Branch name validation successfully threw an error with: ${badData[ii].testName}`
156
+ )
157
+ }
158
+ sandbox.restore()
159
+ t.end()
160
+ })
161
+ }
162
+ }
163
+
164
+ checkBranchDataNameValidation()
165
+ checkProjectIdValidation()
166
+ // #endregion
167
+
168
+ // #region Cleanup
169
+ test('teardown', t => {
170
+ sandbox.restore()
171
+ t.end()
172
+ })
173
+ // #endregion
@@ -0,0 +1,146 @@
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('getBranchChanges 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.getBranchChanges(
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
+ function checkProjectIdValidation () {
38
+ const badData = [
39
+ {
40
+ testName: 'No Project ID'
41
+ },
42
+ {
43
+ testName: 'Empty string',
44
+ projectId: ''
45
+ },
46
+ {
47
+ testName: 'False boolean value',
48
+ projectId: false
49
+ },
50
+ {
51
+ testName: 'Undefined value',
52
+ projectId: undefined
53
+ },
54
+ {
55
+ testName: 'Null value',
56
+ projectId: null
57
+ }
58
+ ]
59
+ for (let ii = 0; ii < badData.length; ii++) {
60
+ test(`Project ID validation should throw an error when: ${badData[ii].testName} is passed in`, async (t) => {
61
+ t.plan(1)
62
+ const responseStub = {
63
+ success: true,
64
+ data: 'Test data response'
65
+ }
66
+ const branchDataMock = {
67
+ name: 'Test_Branch_Name'
68
+ }
69
+ const testProjectId = badData[ii].projectId
70
+ const branchServiceStub = new BranchService()
71
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
72
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
73
+ try {
74
+ await branchServiceStub.getBranchChanges(
75
+ testProjectId,
76
+ branchDataMock.name
77
+ )
78
+ t.fail('Project ID validation threw an error with an invalid value')
79
+ } catch (err) {
80
+ t.equal(
81
+ err.toString(),
82
+ 'Error: Project ID is required',
83
+ `Project ID validation successfully threw an error with: ${badData[ii].testName}`
84
+ )
85
+ }
86
+ sandbox.restore()
87
+ t.end()
88
+ })
89
+ }
90
+ }
91
+
92
+ function checkBranchDataNameValidation () {
93
+ const badData = [
94
+ {
95
+ testName: 'Empty string',
96
+ name: ''
97
+ },
98
+ {
99
+ testName: 'False boolean value',
100
+ name: false
101
+ },
102
+ {
103
+ testName: 'Null value',
104
+ name: null
105
+ }
106
+ ]
107
+ for (let ii = 0; ii < badData.length; ii++) {
108
+ test(`Branch name validation should throw an error when: ${badData[ii].testName} is passed in`, async (t) => {
109
+ t.plan(1)
110
+ const responseStub = {
111
+ success: true,
112
+ data: 'Test data response'
113
+ }
114
+ const testProjectId = 'Test Project ID'
115
+ const branchServiceStub = new BranchService()
116
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
117
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
118
+ try {
119
+ await branchServiceStub.getBranchChanges(
120
+ testProjectId,
121
+ badData[ii].name
122
+ )
123
+ t.fail('Branch name validation threw an error with an invalid value')
124
+ } catch (err) {
125
+ t.equal(
126
+ err.toString(),
127
+ 'Error: Branch name is required',
128
+ `Branch name validation successfully threw an error with: ${badData[ii].testName}`
129
+ )
130
+ }
131
+ sandbox.restore()
132
+ t.end()
133
+ })
134
+ }
135
+ }
136
+
137
+ checkBranchDataNameValidation()
138
+ checkProjectIdValidation()
139
+ // #endregion
140
+
141
+ // #region Cleanup
142
+ test('teardown', (t) => {
143
+ sandbox.restore()
144
+ t.end()
145
+ })
146
+ // #endregion