@symbo.ls/sdk 2.34.4 → 2.34.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.
- package/package.json +6 -6
- 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/PlanService/getPlanByKey.test.js +109 -0
- package/src/services/tests/PlanService/getPlansByPriceRange.test.js +109 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/sdk",
|
|
3
|
-
"version": "2.34.
|
|
3
|
+
"version": "2.34.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/esm/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -46,12 +46,12 @@
|
|
|
46
46
|
"test:user": "cross-env NODE_ENV=$NODE_ENV npx tape integration-tests/index.js integration-tests/user/*.test.js | tap-spec"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@domql/element": "^2.34.
|
|
50
|
-
"@domql/utils": "^2.34.
|
|
49
|
+
"@domql/element": "^2.34.6",
|
|
50
|
+
"@domql/utils": "^2.34.6",
|
|
51
51
|
"@grafana/faro-web-sdk": "^1.19.0",
|
|
52
52
|
"@grafana/faro-web-tracing": "^1.19.0",
|
|
53
|
-
"@symbo.ls/router": "^2.34.
|
|
54
|
-
"@symbo.ls/socket": "^2.34.
|
|
53
|
+
"@symbo.ls/router": "^2.34.6",
|
|
54
|
+
"@symbo.ls/socket": "^2.34.6",
|
|
55
55
|
"acorn": "^8.14.0",
|
|
56
56
|
"acorn-walk": "^8.3.4",
|
|
57
57
|
"dexie": "^4.0.11",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"tap-spec": "^5.0.0",
|
|
75
75
|
"tape": "^5.9.0"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "d0ceab62f9a7fd775f741821b28efb4facf3b4fb"
|
|
78
78
|
}
|
|
@@ -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
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/* eslint-disable no-undefined */
|
|
2
|
+
import test from 'tape'
|
|
3
|
+
import sinon from 'sinon'
|
|
4
|
+
import { PlanService } from '../../PlanService.js'
|
|
5
|
+
|
|
6
|
+
// #region Setup
|
|
7
|
+
const sandbox = sinon.createSandbox()
|
|
8
|
+
// #endregion
|
|
9
|
+
|
|
10
|
+
// #region Tests
|
|
11
|
+
test('getPlanByKey should return response data', async t => {
|
|
12
|
+
t.plan(1)
|
|
13
|
+
const responseStub = {
|
|
14
|
+
key: 'test123'
|
|
15
|
+
}
|
|
16
|
+
const planServiceStub = new PlanService()
|
|
17
|
+
sandbox.stub(planServiceStub, 'getPlans').resolves([responseStub])
|
|
18
|
+
const response = await planServiceStub.getPlanByKey('test123')
|
|
19
|
+
t.equal(response.key, responseStub.key, 'Response data matches stubbed data')
|
|
20
|
+
sandbox.restore()
|
|
21
|
+
t.end()
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('getPlanByKey should return a key not found error', async t => {
|
|
25
|
+
t.plan(1)
|
|
26
|
+
const responseStub = {
|
|
27
|
+
key: 'test123'
|
|
28
|
+
}
|
|
29
|
+
const planServiceStub = new PlanService()
|
|
30
|
+
sandbox.stub(planServiceStub, 'getPlans').resolves([responseStub])
|
|
31
|
+
try {
|
|
32
|
+
await planServiceStub.getPlanByKey('wrongKey123')
|
|
33
|
+
t.fail('getPlanByKey key validation successfully threw an error')
|
|
34
|
+
} catch (err) {
|
|
35
|
+
t.equal(
|
|
36
|
+
err.toString(),
|
|
37
|
+
"Error: Failed to get plan by key: Plan with key 'wrongKey123' not found",
|
|
38
|
+
'Plan key not found validation successfully threw an error for a wrong key entered.'
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
sandbox.restore()
|
|
42
|
+
t.end()
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('getPlanByKey error handling catches and returns an error', async t => {
|
|
46
|
+
t.plan(1)
|
|
47
|
+
const planServiceStub = new PlanService()
|
|
48
|
+
sandbox.stub(planServiceStub, 'getPlans').throws('Test Error')
|
|
49
|
+
try {
|
|
50
|
+
await planServiceStub.getPlanByKey('test123')
|
|
51
|
+
} catch (err) {
|
|
52
|
+
t.equal(
|
|
53
|
+
err.toString(),
|
|
54
|
+
'Error: Failed to get plan by key: Sinon-provided Test Error',
|
|
55
|
+
'Error handling caught and returned the correct error.'
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
sandbox.restore()
|
|
59
|
+
t.end()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
function checkPlanKeyIsRequired () {
|
|
63
|
+
const badPlanKeys = [
|
|
64
|
+
{
|
|
65
|
+
name: 'an undefined value',
|
|
66
|
+
key: undefined
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'a null',
|
|
70
|
+
key: null
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'an empty string',
|
|
74
|
+
key: ''
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
for (let ii = 0; ii < badPlanKeys.length; ii++) {
|
|
78
|
+
test(`getPlanByKey should demand a Plan key when the key entered is ${badPlanKeys[ii].name}`, async t => {
|
|
79
|
+
t.plan(1)
|
|
80
|
+
const responseStub = {
|
|
81
|
+
key: 'test123'
|
|
82
|
+
}
|
|
83
|
+
const planServiceStub = new PlanService()
|
|
84
|
+
sandbox.stub(planServiceStub, 'getPlans').resolves([responseStub])
|
|
85
|
+
try {
|
|
86
|
+
await planServiceStub.getPlanByKey(badPlanKeys[ii].key)
|
|
87
|
+
t.fail('getPlanByKey key validation successfully threw an error')
|
|
88
|
+
} catch (err) {
|
|
89
|
+
t.equal(
|
|
90
|
+
err.toString(),
|
|
91
|
+
'Error: Plan key is required',
|
|
92
|
+
`Key requirement validation successfully threw an error when ${badPlanKeys[ii].name} key is entered.`
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
sandbox.restore()
|
|
96
|
+
t.end()
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
checkPlanKeyIsRequired()
|
|
102
|
+
// #endregion
|
|
103
|
+
|
|
104
|
+
// #region Cleanup
|
|
105
|
+
test('teardown', t => {
|
|
106
|
+
sandbox.restore()
|
|
107
|
+
t.end()
|
|
108
|
+
})
|
|
109
|
+
// #endregion
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/* eslint-disable no-undefined */
|
|
2
|
+
import test from 'tape'
|
|
3
|
+
import sinon from 'sinon'
|
|
4
|
+
import { PlanService } from '../../PlanService.js'
|
|
5
|
+
|
|
6
|
+
// #region Setup
|
|
7
|
+
const sandbox = sinon.createSandbox()
|
|
8
|
+
// #endregion
|
|
9
|
+
|
|
10
|
+
// #region Tests
|
|
11
|
+
test('getPlans should return response data', async t => {
|
|
12
|
+
t.plan(1)
|
|
13
|
+
const responseStub = {
|
|
14
|
+
pricing: {
|
|
15
|
+
bestPrice: {
|
|
16
|
+
amount: 1
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const planServiceStub = new PlanService()
|
|
21
|
+
sandbox.stub(planServiceStub, 'getPlansWithPricing').resolves([responseStub])
|
|
22
|
+
const response = await planServiceStub.getPlansByPriceRange()
|
|
23
|
+
t.equal(
|
|
24
|
+
response[0].pricing.bestPrice.amount,
|
|
25
|
+
responseStub.pricing.bestPrice.amount,
|
|
26
|
+
'Response data matches stubbed data'
|
|
27
|
+
)
|
|
28
|
+
sandbox.restore()
|
|
29
|
+
t.end()
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
function noPricingAmount () {
|
|
33
|
+
const noPriceAmounts = [
|
|
34
|
+
{
|
|
35
|
+
name: 'undefined',
|
|
36
|
+
amount: undefined
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'null',
|
|
40
|
+
amount: null
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'less than the minimum',
|
|
44
|
+
amount: 1
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'more than the maximum',
|
|
48
|
+
amount: 20
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'a string',
|
|
52
|
+
amount: 'test string'
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'an object',
|
|
56
|
+
amount: {}
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
for (let ii = 0; ii < noPriceAmounts.length; ii++) {
|
|
60
|
+
test(`getPlansWithPricing should return an empty response when the amount entered is ${noPriceAmounts[ii].name}`, async t => {
|
|
61
|
+
t.plan(1)
|
|
62
|
+
const responseStub = {
|
|
63
|
+
pricing: {
|
|
64
|
+
bestPrice: {}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
responseStub.pricing.bestPrice.amount = noPriceAmounts[ii].amount
|
|
68
|
+
const planServiceStub = new PlanService()
|
|
69
|
+
sandbox
|
|
70
|
+
.stub(planServiceStub, 'getPlansWithPricing')
|
|
71
|
+
.resolves([responseStub])
|
|
72
|
+
const response = await planServiceStub.getPlansByPriceRange(5, 10)
|
|
73
|
+
t.equal(
|
|
74
|
+
response.length,
|
|
75
|
+
0,
|
|
76
|
+
`Response is an empty array when entered amount is: ${responseStub.pricing.bestPrice.amount}`
|
|
77
|
+
)
|
|
78
|
+
sandbox.restore()
|
|
79
|
+
t.end()
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
test('getPlans should return an error', async t => {
|
|
85
|
+
t.plan(1)
|
|
86
|
+
const planServiceStub = new PlanService()
|
|
87
|
+
sandbox.stub(planServiceStub, 'getPlansWithPricing').throws('Test Error')
|
|
88
|
+
try {
|
|
89
|
+
await planServiceStub.getPlansByPriceRange()
|
|
90
|
+
} catch (err) {
|
|
91
|
+
t.equal(
|
|
92
|
+
err.toString(),
|
|
93
|
+
'Error: Failed to get plans by price range: Sinon-provided Test Error',
|
|
94
|
+
'Error caught and correctly returned'
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
sandbox.restore()
|
|
98
|
+
t.end()
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
noPricingAmount()
|
|
102
|
+
// #endregion
|
|
103
|
+
|
|
104
|
+
// #region Cleanup
|
|
105
|
+
test('teardown', t => {
|
|
106
|
+
sandbox.restore()
|
|
107
|
+
t.end()
|
|
108
|
+
})
|
|
109
|
+
// #endregion
|