@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,152 +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('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
@@ -1,67 +0,0 @@
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
-
@@ -1,75 +0,0 @@
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
-
@@ -1,74 +0,0 @@
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
@@ -1,69 +0,0 @@
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
@@ -1,109 +0,0 @@
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
@@ -1,36 +0,0 @@
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
@@ -1,78 +0,0 @@
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