@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,152 @@
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('resetBranch 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
+ branchName: '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.resetBranch(
26
+ testProjectId,
27
+ branchDataMock.branchName
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
+ branchName: '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.resetBranch(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
+ branchName: ''
99
+ },
100
+ {
101
+ testName: 'False boolean value',
102
+ branchName: false
103
+ },
104
+ {
105
+ testName: 'Undefined value',
106
+ branchName: undefined
107
+ },
108
+ {
109
+ testName: 'Null value',
110
+ branchName: 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 testProjectId = 'Test Project ID'
121
+ const branchServiceStub = new BranchService()
122
+ sandbox.stub(branchServiceStub, '_requireReady').resolves()
123
+ sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
124
+ try {
125
+ await branchServiceStub.resetBranch(
126
+ testProjectId,
127
+ badData[ii].branchName
128
+ )
129
+ t.fail('Branch name validation threw an error with an invalid value')
130
+ } catch (err) {
131
+ t.equal(
132
+ err.toString(),
133
+ 'Error: Branch name is required',
134
+ `Branch name validation successfully threw an error with: ${badData[ii].testName}`
135
+ )
136
+ }
137
+ sandbox.restore()
138
+ t.end()
139
+ })
140
+ }
141
+ }
142
+
143
+ checkBranchDataNameValidation()
144
+ checkProjectIdValidation()
145
+ // #endregion
146
+
147
+ // #region Cleanup
148
+ test('teardown', (t) => {
149
+ sandbox.restore()
150
+ t.end()
151
+ })
152
+ // #endregion
@@ -0,0 +1,67 @@
1
+ import test from 'tape'
2
+ import sinon from 'sinon'
3
+ import { FeatureFlagService } from '../../FeatureFlagService.js'
4
+
5
+ // #region Setup
6
+ const sandbox = sinon.createSandbox()
7
+ // #endregion
8
+
9
+ // #region Tests
10
+ test('getAdminFeatureFlags should pass includeArchived=false', async t => {
11
+ t.plan(1)
12
+ const responseStub = { success: true, data: [] }
13
+ const service = new FeatureFlagService()
14
+ sandbox.stub(service, '_requireReady').resolves()
15
+ const requestStub = sandbox.stub(service, '_request').resolves(responseStub)
16
+
17
+ await service.getAdminFeatureFlags({ includeArchived: false })
18
+ t.equal(
19
+ requestStub.firstCall.args[0],
20
+ '/admin/feature-flags?includeArchived=false',
21
+ 'includeArchived=false included'
22
+ )
23
+
24
+ sandbox.restore()
25
+ t.end()
26
+ })
27
+
28
+ test('createFeatureFlag should require key', async t => {
29
+ t.plan(1)
30
+ const service = new FeatureFlagService()
31
+ sandbox.stub(service, '_requireReady').resolves()
32
+
33
+ try {
34
+ await service.createFeatureFlag({ enabled: true })
35
+ t.fail('Expected createFeatureFlag to throw without key')
36
+ } catch (err) {
37
+ t.equal(err.toString(), 'Error: Feature flag key is required', 'Key validation works')
38
+ }
39
+
40
+ sandbox.restore()
41
+ t.end()
42
+ })
43
+
44
+ test('updateFeatureFlag should require id', async t => {
45
+ t.plan(1)
46
+ const service = new FeatureFlagService()
47
+ sandbox.stub(service, '_requireReady').resolves()
48
+
49
+ try {
50
+ await service.updateFeatureFlag(null, { enabled: false })
51
+ t.fail('Expected updateFeatureFlag to throw without id')
52
+ } catch (err) {
53
+ t.equal(err.toString(), 'Error: Feature flag id is required', 'Id validation works')
54
+ }
55
+
56
+ sandbox.restore()
57
+ t.end()
58
+ })
59
+ // #endregion
60
+
61
+ // #region Cleanup
62
+ test('teardown', t => {
63
+ sandbox.restore()
64
+ t.end()
65
+ })
66
+ // #endregion
67
+
@@ -0,0 +1,75 @@
1
+ import test from 'tape'
2
+ import sinon from 'sinon'
3
+ import { FeatureFlagService } from '../../FeatureFlagService.js'
4
+
5
+ // #region Setup
6
+ const sandbox = sinon.createSandbox()
7
+ // #endregion
8
+
9
+ // #region Tests
10
+ test('getFeatureFlags should return response data', async t => {
11
+ t.plan(1)
12
+ const responseStub = {
13
+ success: true,
14
+ data: { flags: { new_ui: { enabled: true, variant: null, payload: null } } }
15
+ }
16
+ const service = new FeatureFlagService()
17
+ sandbox.stub(service, '_requireReady').resolves()
18
+ sandbox.stub(service, '_request').resolves(responseStub)
19
+
20
+ const response = await service.getFeatureFlags()
21
+ t.equal(response, responseStub.data, 'Response data returned')
22
+
23
+ sandbox.restore()
24
+ t.end()
25
+ })
26
+
27
+ test('getFeatureFlags should pass keys query param', async t => {
28
+ t.plan(1)
29
+ const responseStub = { success: true, data: { flags: {} } }
30
+ const service = new FeatureFlagService()
31
+ sandbox.stub(service, '_requireReady').resolves()
32
+ const requestStub = sandbox.stub(service, '_request').resolves(responseStub)
33
+
34
+ await service.getFeatureFlags({ keys: ['new_ui', 'checkout_experiment'] })
35
+ t.ok(
36
+ requestStub.firstCall.args[0].includes('/feature-flags?keys=new_ui%2Ccheckout_experiment'),
37
+ 'Keys query param included'
38
+ )
39
+
40
+ sandbox.restore()
41
+ t.end()
42
+ })
43
+
44
+ test('getFeatureFlags should return an error', async t => {
45
+ t.plan(1)
46
+ const responseStub = {
47
+ success: false,
48
+ data: {},
49
+ message: 'Negative getFeatureFlags Test'
50
+ }
51
+ const service = new FeatureFlagService()
52
+ sandbox.stub(service, '_requireReady').resolves()
53
+ sandbox.stub(service, '_request').resolves(responseStub)
54
+
55
+ try {
56
+ await service.getFeatureFlags()
57
+ } catch (err) {
58
+ t.ok(
59
+ err.toString().includes(`Failed to get feature flags: ${responseStub.message}`),
60
+ 'Error correctly returned'
61
+ )
62
+ }
63
+
64
+ sandbox.restore()
65
+ t.end()
66
+ })
67
+ // #endregion
68
+
69
+ // #region Cleanup
70
+ test('teardown', t => {
71
+ sandbox.restore()
72
+ t.end()
73
+ })
74
+ // #endregion
75
+
@@ -0,0 +1,74 @@
1
+ import test from 'tape'
2
+ import { FileService } from '../../FileService.js'
3
+
4
+ // #region Tests
5
+ test('createFileFormData should return a basic formData object', t => {
6
+ t.plan(3)
7
+ const mockFileData = {
8
+ size: 13,
9
+ type: 'text/*',
10
+ name: 'filename.txt'
11
+ }
12
+ const mockFile = new File(['file contents'], mockFileData.name, {
13
+ type: mockFileData.type
14
+ })
15
+ const fileServiceStub = new FileService()
16
+ const response = fileServiceStub.createFileFormData(mockFile)
17
+ t.equal(
18
+ Array.from(response)[0][1].size,
19
+ mockFileData.size,
20
+ 'Actual file size matches expected file size'
21
+ )
22
+ t.equal(
23
+ Array.from(response)[0][1].type,
24
+ mockFileData.type,
25
+ 'Actual file type matches expected file type'
26
+ )
27
+ t.equal(
28
+ Array.from(response)[0][1].name,
29
+ mockFileData.name,
30
+ 'Actual file name matches expected file name'
31
+ )
32
+ t.end()
33
+ })
34
+
35
+ test('createFileFormData should return a formData object with metadata', t => {
36
+ t.plan(4)
37
+ const mockFileData = {
38
+ size: 13,
39
+ type: 'text/*',
40
+ name: 'filename.txt'
41
+ }
42
+ const mockFile = new File(['file contents'], mockFileData.name, {
43
+ type: mockFileData.type
44
+ })
45
+ const mockMetaData = {
46
+ name: 'Test Name',
47
+ description: 'Test Description',
48
+ key: 'Test Key'
49
+ }
50
+ const fileServiceStub = new FileService()
51
+ const response = fileServiceStub.createFileFormData(mockFile, mockMetaData)
52
+ t.equal(
53
+ Array.from(response)[0][1].size,
54
+ mockFileData.size,
55
+ 'Actual file size matches expected file size'
56
+ )
57
+ t.equal(
58
+ Array.from(response)[0][1].type,
59
+ mockFileData.type,
60
+ 'Actual file type matches expected file type'
61
+ )
62
+ t.equal(
63
+ Array.from(response)[0][1].name,
64
+ mockFileData.name,
65
+ 'Actual file name matches expected file name'
66
+ )
67
+ t.equal(
68
+ Array.from(response)[1][1],
69
+ JSON.stringify(mockMetaData),
70
+ 'Actual metadata matches expected metadata'
71
+ )
72
+ t.end()
73
+ })
74
+ // #endregion
@@ -0,0 +1,69 @@
1
+ /* eslint-disable no-undefined */
2
+ import test from 'tape'
3
+ import { FileService } from '../../FileService.js'
4
+ import { BaseService } from '../../BaseService.js'
5
+
6
+ // #region Tests
7
+ test('getFileUrl should return a good file url', t => {
8
+ t.plan(1)
9
+ const mockFileId = 'testFileId'
10
+ const fileServiceStub = new FileService()
11
+ const baseServiceStub = new BaseService()
12
+ const response = fileServiceStub.getFileUrl(mockFileId)
13
+ t.equal(
14
+ response,
15
+ `${baseServiceStub._apiUrl}/core/files/public/${mockFileId}/download`,
16
+ 'Actual file url matches expected file url'
17
+ )
18
+ t.end()
19
+ })
20
+
21
+ function testFileIdValidation () {
22
+ const badData = [
23
+ {
24
+ name: 'Empty String',
25
+ fileId: ''
26
+ },
27
+ {
28
+ name: 'Undefined',
29
+ fileId: undefined
30
+ },
31
+ {
32
+ name: 'Null',
33
+ fileId: null
34
+ },
35
+ {
36
+ name: 'False boolean value',
37
+ fileId: false
38
+ },
39
+ {
40
+ name: 'True boolean value',
41
+ fileId: true
42
+ },
43
+ {
44
+ name: 'Object',
45
+ fileId: {}
46
+ }
47
+ ]
48
+ for (let ii = 0; ii < badData.length; ii++) {
49
+ test(`fileId validation should throw an error when fileId value is: ${badData[ii].name}`, t => {
50
+ t.plan(1)
51
+ const mockFileId = null
52
+ const fileServiceStub = new FileService()
53
+ try {
54
+ fileServiceStub.getFileUrl(mockFileId)
55
+ t.fail('file ID successfully threw an error')
56
+ } catch (err) {
57
+ t.equal(
58
+ err.toString(),
59
+ 'Error: File ID is required',
60
+ `file ID validation successfully threw an error when fileId is: ${badData[ii].name}`
61
+ )
62
+ }
63
+ t.end()
64
+ })
65
+ }
66
+ }
67
+
68
+ testFileIdValidation()
69
+ // #endregion
@@ -0,0 +1,109 @@
1
+ /* eslint-disable no-undefined */
2
+ import test from 'tape'
3
+ import sinon from 'sinon'
4
+ import { FileService } from '../../FileService.js'
5
+
6
+ // #region Setup
7
+ const sandbox = sinon.createSandbox()
8
+ // #endregion
9
+
10
+ // #region Tests
11
+ test('updateProjectIcon should return response data', async t => {
12
+ t.plan(1)
13
+ const uploadFileResponseStub = {
14
+ success: true,
15
+ data: 'test data response'
16
+ }
17
+ const projectIdStub = sandbox.stub()
18
+ const iconStub = sandbox.stub()
19
+ const fileServiceStub = new FileService()
20
+ sandbox.stub(fileServiceStub, '_request').resolves(uploadFileResponseStub)
21
+ sandbox.stub(fileServiceStub, '_requireReady').resolves()
22
+ const response = await fileServiceStub.updateProjectIcon(
23
+ projectIdStub,
24
+ iconStub
25
+ )
26
+ t.equal(
27
+ response,
28
+ uploadFileResponseStub.data,
29
+ 'Response data matches stubbed data'
30
+ )
31
+ sandbox.restore()
32
+ t.end()
33
+ })
34
+
35
+ test('projectId validation should throw an error', async t => {
36
+ t.plan(1)
37
+ const uploadFileResponseStub = {
38
+ success: true,
39
+ data: 'test data response'
40
+ }
41
+ const iconStub = sandbox.stub()
42
+ const fileServiceStub = new FileService()
43
+ sandbox.stub(fileServiceStub, '_request').resolves(uploadFileResponseStub)
44
+ sandbox.stub(fileServiceStub, '_requireReady').resolves()
45
+ try {
46
+ await fileServiceStub.updateProjectIcon(undefined, iconStub)
47
+ t.fail('file validation successfully threw an error')
48
+ } catch (err) {
49
+ t.equal(
50
+ err.toString(),
51
+ 'Error: Project ID and icon file are required',
52
+ 'file validation successfully threw an error when no file was uploaded.'
53
+ )
54
+ }
55
+ sandbox.restore()
56
+ t.end()
57
+ })
58
+
59
+ test('iconFile validation should throw an error', async t => {
60
+ t.plan(1)
61
+ const uploadFileResponseStub = {
62
+ success: true,
63
+ data: 'test data response'
64
+ }
65
+ const projectIdStub = sandbox.stub()
66
+ const fileServiceStub = new FileService()
67
+ sandbox.stub(fileServiceStub, '_request').resolves(uploadFileResponseStub)
68
+ sandbox.stub(fileServiceStub, '_requireReady').resolves()
69
+ try {
70
+ await fileServiceStub.updateProjectIcon(projectIdStub)
71
+ t.fail('file validation successfully threw an error')
72
+ } catch (err) {
73
+ t.equal(
74
+ err.toString(),
75
+ 'Error: Project ID and icon file are required',
76
+ 'file validation successfully threw an error when no file was uploaded.'
77
+ )
78
+ }
79
+ sandbox.restore()
80
+ t.end()
81
+ })
82
+
83
+ test('updateProjectIcon error handling catches and returns an error', async t => {
84
+ t.plan(1)
85
+ const projectIdStub = sandbox.stub()
86
+ const iconStub = sandbox.stub()
87
+ const fileServiceStub = new FileService()
88
+ sandbox.stub(fileServiceStub, '_requireReady').resolves()
89
+ sandbox.stub(fileServiceStub, '_request').throws('Test Error')
90
+ try {
91
+ await fileServiceStub.updateProjectIcon(projectIdStub, iconStub)
92
+ } catch (err) {
93
+ t.equal(
94
+ err.toString(),
95
+ 'Error: Failed to update project icon: Sinon-provided Test Error',
96
+ 'Error handling caught and returned the correct error.'
97
+ )
98
+ }
99
+ sandbox.restore()
100
+ t.end()
101
+ })
102
+ // #endregion
103
+
104
+ // #region Cleanup
105
+ test('teardown', t => {
106
+ sandbox.restore()
107
+ t.end()
108
+ })
109
+ // #endregion
@@ -0,0 +1,36 @@
1
+ import test from 'tape'
2
+ import sinon from 'sinon'
3
+ import { FileService } from '../../FileService.js'
4
+
5
+ // #region Setup
6
+ const sandbox = sinon.createSandbox()
7
+ // #endregion
8
+
9
+ // #region Tests
10
+ test('uploadDocument should return response data', async t => {
11
+ t.plan(2)
12
+ const uploadFileResponseStub = {
13
+ success: true,
14
+ data: 'test data response'
15
+ }
16
+ const mockFile = new File(['file contents'], 'filename.txt', {
17
+ type: 'application/pdf'
18
+ })
19
+ const fileServiceStub = new FileService()
20
+ const uploadFileStub = sandbox
21
+ .stub(fileServiceStub, 'uploadFileWithValidation')
22
+ .resolves(uploadFileResponseStub)
23
+ const response = await fileServiceStub.uploadImage(mockFile)
24
+ t.ok(response.success, 'response successfully returned')
25
+ t.ok(uploadFileStub.calledOnce, 'uploadFileStub called once')
26
+ sandbox.restore()
27
+ t.end()
28
+ })
29
+ // #endregion
30
+
31
+ // #region Cleanup
32
+ test('teardown', t => {
33
+ sandbox.restore()
34
+ t.end()
35
+ })
36
+ // #endregion
@@ -0,0 +1,78 @@
1
+ import test from 'tape'
2
+ import sinon from 'sinon'
3
+ import { FileService } from '../../FileService.js'
4
+
5
+ // #region Setup
6
+ const sandbox = sinon.createSandbox()
7
+ // #endregion
8
+
9
+ // #region Tests
10
+ test('uploadFile should return response data', async t => {
11
+ t.plan(1)
12
+ const uploadFileResponseStub = {
13
+ success: true,
14
+ data: 'test data response'
15
+ }
16
+ const file = sandbox.stub()
17
+ const fileServiceStub = new FileService()
18
+ sandbox.stub(fileServiceStub, '_request').resolves(uploadFileResponseStub)
19
+ sandbox.stub(fileServiceStub, '_requireReady').resolves()
20
+ const response = await fileServiceStub.uploadFile(file)
21
+ t.equal(
22
+ response,
23
+ uploadFileResponseStub.data,
24
+ 'Response data matches stubbed data'
25
+ )
26
+ sandbox.restore()
27
+ t.end()
28
+ })
29
+
30
+ test('file validation should throw an error when no file is uploaded', async t => {
31
+ t.plan(1)
32
+ const uploadFileResponseStub = {
33
+ success: true,
34
+ data: 'test data response'
35
+ }
36
+ const fileServiceStub = new FileService()
37
+ sandbox.stub(fileServiceStub, '_request').resolves(uploadFileResponseStub)
38
+ sandbox.stub(fileServiceStub, '_requireReady').resolves()
39
+ try {
40
+ await fileServiceStub.uploadFile()
41
+ t.fail('file validation successfully threw an error')
42
+ } catch (err) {
43
+ t.equal(
44
+ err.toString(),
45
+ 'Error: File is required for upload',
46
+ 'file validation successfully threw an error when no file was uploaded.'
47
+ )
48
+ }
49
+ sandbox.restore()
50
+ t.end()
51
+ })
52
+
53
+ test('uploadFile error handling catches and returns an error', async t => {
54
+ t.plan(1)
55
+ const file = sandbox.stub()
56
+ const fileServiceStub = new FileService()
57
+ sandbox.stub(fileServiceStub, '_requireReady').resolves()
58
+ sandbox.stub(fileServiceStub, '_request').throws('Test Error')
59
+ try {
60
+ await fileServiceStub.uploadFile(file)
61
+ } catch (err) {
62
+ t.equal(
63
+ err.toString(),
64
+ 'Error: File upload failed: Sinon-provided Test Error',
65
+ 'Error handling caught and returned the correct error.'
66
+ )
67
+ }
68
+ sandbox.restore()
69
+ t.end()
70
+ })
71
+ // #endregion
72
+
73
+ // #region Cleanup
74
+ test('teardown', t => {
75
+ sandbox.restore()
76
+ t.end()
77
+ })
78
+ // #endregion