@symbo.ls/sdk 2.34.4 → 2.34.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.
- package/dist/cjs/index.js +24 -0
- package/dist/cjs/services/BranchService.js +4 -4
- package/dist/cjs/services/IntegrationService.js +538 -0
- package/dist/cjs/services/MetricsService.js +62 -0
- package/dist/cjs/services/PaymentService.js +1 -1
- package/dist/cjs/services/PullRequestService.js +8 -6
- package/dist/cjs/services/WaitlistService.js +148 -0
- package/dist/cjs/services/index.js +13 -1
- package/dist/cjs/utils/services.js +26 -1
- package/dist/esm/index.js +751 -12
- package/dist/esm/services/BranchService.js +4 -4
- package/dist/esm/services/IntegrationService.js +1319 -0
- package/dist/esm/services/MetricsService.js +843 -0
- package/dist/esm/services/PaymentService.js +1 -1
- package/dist/esm/services/PullRequestService.js +8 -6
- package/dist/esm/services/WaitlistService.js +929 -0
- package/dist/esm/services/index.js +708 -12
- package/dist/esm/utils/services.js +26 -1
- package/dist/node/index.js +32 -2
- package/dist/node/services/BranchService.js +4 -4
- package/dist/node/services/IntegrationService.js +519 -0
- package/dist/node/services/MetricsService.js +43 -0
- package/dist/node/services/PaymentService.js +1 -1
- package/dist/node/services/PullRequestService.js +8 -6
- package/dist/node/services/WaitlistService.js +129 -0
- package/dist/node/services/index.js +13 -1
- package/dist/node/utils/services.js +26 -1
- package/package.json +8 -7
- package/src/index.js +40 -13
- package/src/services/BranchService.js +5 -5
- package/src/services/IntegrationService.js +548 -0
- package/src/services/MetricsService.js +40 -0
- package/src/services/PaymentService.js +1 -1
- package/src/services/PullRequestService.js +6 -6
- package/src/services/WaitlistService.js +130 -0
- package/src/services/index.js +16 -2
- package/src/services/tests/FileService/createFileFormData.test.js +74 -0
- package/src/services/tests/FileService/getFileUrl.test.js +69 -0
- package/src/services/tests/FileService/updateProjectIcon.test.js +109 -0
- package/src/services/tests/FileService/uploadDocument.test.js +36 -0
- package/src/services/tests/FileService/uploadFile.test.js +78 -0
- package/src/services/tests/FileService/uploadFileWithValidation.test.js +114 -0
- package/src/services/tests/FileService/uploadImage.test.js +36 -0
- package/src/services/tests/FileService/uploadMultipleFiles.test.js +111 -0
- package/src/services/tests/FileService/validateFile.test.js +63 -0
- package/src/services/tests/PlanService/getActivePlans.test.js +0 -2
- package/src/services/tests/PlanService/getPlanByKey.test.js +109 -0
- package/src/services/tests/PlanService/getPlansByPriceRange.test.js +109 -0
- package/src/utils/services.js +29 -1
|
@@ -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
|
package/src/services/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
import { AuthService } from './AuthService.js'
|
|
3
2
|
import { CollabService } from './CollabService.js'
|
|
4
3
|
import { ProjectService } from './ProjectService.js'
|
|
@@ -12,6 +11,9 @@ import { PullRequestService } from './PullRequestService.js'
|
|
|
12
11
|
import { AdminService } from './AdminService.js'
|
|
13
12
|
import { ScreenshotService } from './ScreenshotService.js'
|
|
14
13
|
import { TrackingService } from './TrackingService.js'
|
|
14
|
+
import { WaitlistService } from './WaitlistService.js'
|
|
15
|
+
import { MetricsService } from './MetricsService.js'
|
|
16
|
+
import { IntegrationService } from './IntegrationService.js'
|
|
15
17
|
|
|
16
18
|
const createService = (ServiceClass, config) => new ServiceClass(config)
|
|
17
19
|
|
|
@@ -54,6 +56,15 @@ export const createScreenshotService = config =>
|
|
|
54
56
|
export const createTrackingService = config =>
|
|
55
57
|
createService(TrackingService, config)
|
|
56
58
|
|
|
59
|
+
export const createWaitlistService = config =>
|
|
60
|
+
createService(WaitlistService, config)
|
|
61
|
+
|
|
62
|
+
export const createMetricsService = config =>
|
|
63
|
+
createService(MetricsService, config)
|
|
64
|
+
|
|
65
|
+
export const createIntegrationService = config =>
|
|
66
|
+
createService(IntegrationService, config)
|
|
67
|
+
|
|
57
68
|
export {
|
|
58
69
|
AuthService,
|
|
59
70
|
CollabService,
|
|
@@ -67,5 +78,8 @@ export {
|
|
|
67
78
|
PullRequestService,
|
|
68
79
|
AdminService,
|
|
69
80
|
ScreenshotService,
|
|
70
|
-
TrackingService
|
|
81
|
+
TrackingService,
|
|
82
|
+
WaitlistService,
|
|
83
|
+
MetricsService,
|
|
84
|
+
IntegrationService
|
|
71
85
|
}
|
|
@@ -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
|
|
@@ -0,0 +1,114 @@
|
|
|
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('uploadFileWithValidation 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: 'text/*'
|
|
18
|
+
})
|
|
19
|
+
const fileServiceStub = new FileService()
|
|
20
|
+
const uploadFileStub = sandbox
|
|
21
|
+
.stub(fileServiceStub, 'uploadFile')
|
|
22
|
+
.resolves(uploadFileResponseStub)
|
|
23
|
+
const response = await fileServiceStub.uploadFileWithValidation(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
|
+
|
|
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, 'uploadFile').resolves(uploadFileResponseStub)
|
|
38
|
+
try {
|
|
39
|
+
await fileServiceStub.uploadFileWithValidation()
|
|
40
|
+
t.fail('file validation successfully threw an error')
|
|
41
|
+
} catch (err) {
|
|
42
|
+
t.equal(
|
|
43
|
+
err.toString(),
|
|
44
|
+
'Error: File is required',
|
|
45
|
+
'file validation successfully threw an error when no file was uploaded.'
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
sandbox.restore()
|
|
49
|
+
t.end()
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('file size validation throws an error', async t => {
|
|
53
|
+
t.plan(1)
|
|
54
|
+
const uploadFileResponseStub = {
|
|
55
|
+
success: true,
|
|
56
|
+
data: 'test data response'
|
|
57
|
+
}
|
|
58
|
+
const mockFile = new File(['file contents'], 'filename.txt', {
|
|
59
|
+
type: 'text/*'
|
|
60
|
+
})
|
|
61
|
+
const options = {
|
|
62
|
+
maxSize: 1
|
|
63
|
+
}
|
|
64
|
+
const fileServiceStub = new FileService()
|
|
65
|
+
sandbox.stub(fileServiceStub, 'uploadFile').resolves(uploadFileResponseStub)
|
|
66
|
+
try {
|
|
67
|
+
await fileServiceStub.uploadFileWithValidation(mockFile, options)
|
|
68
|
+
t.fail('file size validation successfully threw an error')
|
|
69
|
+
} catch (err) {
|
|
70
|
+
t.ok(
|
|
71
|
+
err
|
|
72
|
+
.toString()
|
|
73
|
+
.includes('Error: File size exceeds maximum allowed size of ')
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
sandbox.restore()
|
|
77
|
+
t.end()
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
test('isValid type check throws an error', async t => {
|
|
81
|
+
t.plan(1)
|
|
82
|
+
const uploadFileResponseStub = {
|
|
83
|
+
success: true,
|
|
84
|
+
data: 'test data response'
|
|
85
|
+
}
|
|
86
|
+
const mockFile = new File(['file contents'], 'filename.txt', {
|
|
87
|
+
type: 'text/*'
|
|
88
|
+
})
|
|
89
|
+
const options = {
|
|
90
|
+
allowedTypes: ['test type']
|
|
91
|
+
}
|
|
92
|
+
const fileServiceStub = new FileService()
|
|
93
|
+
sandbox.stub(fileServiceStub, 'uploadFile').resolves(uploadFileResponseStub)
|
|
94
|
+
try {
|
|
95
|
+
await fileServiceStub.uploadFileWithValidation(mockFile, options)
|
|
96
|
+
t.fail('isValid check successfully threw an error')
|
|
97
|
+
} catch (err) {
|
|
98
|
+
t.equal(
|
|
99
|
+
err.toString(),
|
|
100
|
+
"Error: File type 'text/*' is not allowed. Allowed types: test type",
|
|
101
|
+
'isValid check succeeded.'
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
sandbox.restore()
|
|
105
|
+
t.end()
|
|
106
|
+
})
|
|
107
|
+
// #endregion
|
|
108
|
+
|
|
109
|
+
// #region Cleanup
|
|
110
|
+
test('teardown', t => {
|
|
111
|
+
sandbox.restore()
|
|
112
|
+
t.end()
|
|
113
|
+
})
|
|
114
|
+
// #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('uploadImage 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: 'image/*'
|
|
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
|