@symbo.ls/sdk 2.34.13 → 2.34.15
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/BranchService/createBranch.test.js +153 -0
- package/src/services/tests/BranchService/deleteBranch.test.js +173 -0
- package/src/services/tests/BranchService/listBranches.test.js +87 -0
- package/src/services/tests/BranchService/renameBranch.test.js +240 -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.15",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/esm/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
"test:unit-all": "cross-env NODE_ENV=$NODE_ENV npx tape src/services/tests/**/*.test.js | tap-spec"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@domql/element": "^2.34.
|
|
51
|
-
"@domql/utils": "^2.34.
|
|
50
|
+
"@domql/element": "^2.34.15",
|
|
51
|
+
"@domql/utils": "^2.34.15",
|
|
52
52
|
"@grafana/faro-web-sdk": "^1.19.0",
|
|
53
53
|
"@grafana/faro-web-tracing": "^1.19.0",
|
|
54
|
-
"@symbo.ls/router": "^2.34.
|
|
55
|
-
"@symbo.ls/socket": "^2.34.
|
|
54
|
+
"@symbo.ls/router": "^2.34.15",
|
|
55
|
+
"@symbo.ls/socket": "^2.34.15",
|
|
56
56
|
"acorn": "^8.14.0",
|
|
57
57
|
"acorn-walk": "^8.3.4",
|
|
58
58
|
"dexie": "^4.0.11",
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"tap-spec": "^5.0.0",
|
|
76
76
|
"tape": "^5.9.0"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "d05a21975a9203c920d4238a26b02d9d0a9ca684"
|
|
79
79
|
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/* eslint-disable no-undefined */
|
|
2
|
+
import test from 'tape'
|
|
3
|
+
import sinon from 'sinon'
|
|
4
|
+
import { BranchService } from '../../BranchService.js'
|
|
5
|
+
|
|
6
|
+
// #region Setup
|
|
7
|
+
const sandbox = sinon.createSandbox()
|
|
8
|
+
// #endregion
|
|
9
|
+
|
|
10
|
+
// #region Tests
|
|
11
|
+
test('createBranch should return response data', async t => {
|
|
12
|
+
t.plan(1)
|
|
13
|
+
const responseStub = {
|
|
14
|
+
success: true,
|
|
15
|
+
data: 'Test data response'
|
|
16
|
+
}
|
|
17
|
+
const branchDataMock = {
|
|
18
|
+
name: 'Test_Branch_Name',
|
|
19
|
+
source: 'main'
|
|
20
|
+
}
|
|
21
|
+
const testProjectId = 'Test Project ID'
|
|
22
|
+
const branchServiceStub = new BranchService()
|
|
23
|
+
sandbox.stub(branchServiceStub, '_requireReady').resolves()
|
|
24
|
+
sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
|
|
25
|
+
const response = await branchServiceStub.createBranch(
|
|
26
|
+
testProjectId,
|
|
27
|
+
branchDataMock
|
|
28
|
+
)
|
|
29
|
+
t.equal(
|
|
30
|
+
response,
|
|
31
|
+
responseStub.data,
|
|
32
|
+
'Actual response matches expected response'
|
|
33
|
+
)
|
|
34
|
+
sandbox.restore()
|
|
35
|
+
t.end()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
function checkProjectIdValidation () {
|
|
39
|
+
const badData = [
|
|
40
|
+
{
|
|
41
|
+
testName: 'No Project ID'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
testName: 'Empty string',
|
|
45
|
+
projectId: ''
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
testName: 'False boolean value',
|
|
49
|
+
projectId: false
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
testName: 'Undefined value',
|
|
53
|
+
projectId: undefined
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
testName: 'Null value',
|
|
57
|
+
projectId: null
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
for (let ii = 0; ii < badData.length; ii++) {
|
|
61
|
+
test(`Project ID validation should throw an error when: ${badData[ii].testName} is passed in`, async t => {
|
|
62
|
+
t.plan(1)
|
|
63
|
+
const responseStub = {
|
|
64
|
+
success: true,
|
|
65
|
+
data: 'Test data response'
|
|
66
|
+
}
|
|
67
|
+
const branchDataMock = {
|
|
68
|
+
name: 'Test_Branch_Name',
|
|
69
|
+
source: 'main'
|
|
70
|
+
}
|
|
71
|
+
const testProjectId = badData[ii].projectId
|
|
72
|
+
const branchServiceStub = new BranchService()
|
|
73
|
+
sandbox.stub(branchServiceStub, '_requireReady').resolves()
|
|
74
|
+
sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
|
|
75
|
+
try {
|
|
76
|
+
await branchServiceStub.createBranch(testProjectId, branchDataMock)
|
|
77
|
+
t.fail('Project ID validation threw an error with an invalid value')
|
|
78
|
+
} catch (err) {
|
|
79
|
+
t.equal(
|
|
80
|
+
err.toString(),
|
|
81
|
+
'Error: Project ID is required',
|
|
82
|
+
`Project ID validation successfully threw an error with: ${badData[ii].testName}`
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
sandbox.restore()
|
|
86
|
+
t.end()
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function checkBranchDataNameValidation () {
|
|
92
|
+
const badData = [
|
|
93
|
+
{
|
|
94
|
+
testName: 'No name'
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
testName: 'Empty string',
|
|
98
|
+
name: ''
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
testName: 'False boolean value',
|
|
102
|
+
name: false
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
testName: 'Undefined value',
|
|
106
|
+
name: undefined
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
testName: 'Null value',
|
|
110
|
+
name: null
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
for (let ii = 0; ii < badData.length; ii++) {
|
|
114
|
+
test(`Branch name validation should throw an error when: ${badData[ii].testName} is passed in`, async t => {
|
|
115
|
+
t.plan(1)
|
|
116
|
+
const responseStub = {
|
|
117
|
+
success: true,
|
|
118
|
+
data: 'Test data response'
|
|
119
|
+
}
|
|
120
|
+
const branchName = {
|
|
121
|
+
name: badData[ii].name,
|
|
122
|
+
source: 'main'
|
|
123
|
+
}
|
|
124
|
+
const testProjectId = 'Test Project ID'
|
|
125
|
+
const branchServiceStub = new BranchService()
|
|
126
|
+
sandbox.stub(branchServiceStub, '_requireReady').resolves()
|
|
127
|
+
sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
|
|
128
|
+
try {
|
|
129
|
+
await branchServiceStub.createBranch(testProjectId, branchName)
|
|
130
|
+
t.fail('Branch name validation threw an error with an invalid value')
|
|
131
|
+
} catch (err) {
|
|
132
|
+
t.equal(
|
|
133
|
+
err.toString(),
|
|
134
|
+
'Error: Branch name is required',
|
|
135
|
+
`Branch name validation successfully threw an error with: ${badData[ii].testName}`
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
sandbox.restore()
|
|
139
|
+
t.end()
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
checkBranchDataNameValidation()
|
|
145
|
+
checkProjectIdValidation()
|
|
146
|
+
// #endregion
|
|
147
|
+
|
|
148
|
+
// #region Cleanup
|
|
149
|
+
test('teardown', t => {
|
|
150
|
+
sandbox.restore()
|
|
151
|
+
t.end()
|
|
152
|
+
})
|
|
153
|
+
// #endregion
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/* eslint-disable no-undefined */
|
|
2
|
+
import test from 'tape'
|
|
3
|
+
import sinon from 'sinon'
|
|
4
|
+
import { BranchService } from '../../BranchService.js'
|
|
5
|
+
|
|
6
|
+
// #region Setup
|
|
7
|
+
const sandbox = sinon.createSandbox()
|
|
8
|
+
// #endregion
|
|
9
|
+
|
|
10
|
+
// #region Tests
|
|
11
|
+
test('deleteBranch should return response data', async t => {
|
|
12
|
+
t.plan(2)
|
|
13
|
+
const responseStub = {
|
|
14
|
+
success: true,
|
|
15
|
+
data: 'Test data response'
|
|
16
|
+
}
|
|
17
|
+
const branchDataMock = {
|
|
18
|
+
name: 'Test_Branch_Name',
|
|
19
|
+
branch: 'not_main'
|
|
20
|
+
}
|
|
21
|
+
const testProjectId = 'Test Project ID'
|
|
22
|
+
const branchServiceStub = new BranchService()
|
|
23
|
+
sandbox.stub(branchServiceStub, '_requireReady').resolves()
|
|
24
|
+
sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
|
|
25
|
+
const response = await branchServiceStub.deleteBranch(
|
|
26
|
+
testProjectId,
|
|
27
|
+
branchDataMock.branch
|
|
28
|
+
)
|
|
29
|
+
t.ok(response.success, 'Response successfully returned')
|
|
30
|
+
t.equal(
|
|
31
|
+
response.data,
|
|
32
|
+
responseStub.data,
|
|
33
|
+
'Actual response matches expected response'
|
|
34
|
+
)
|
|
35
|
+
sandbox.restore()
|
|
36
|
+
t.end()
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test('Branch name validation should throw an error when the branch is main', async t => {
|
|
40
|
+
t.plan(1)
|
|
41
|
+
const responseStub = {
|
|
42
|
+
success: true,
|
|
43
|
+
data: 'Test data response'
|
|
44
|
+
}
|
|
45
|
+
const branchServiceStub = new BranchService()
|
|
46
|
+
sandbox.stub(branchServiceStub, '_requireReady').resolves()
|
|
47
|
+
sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
|
|
48
|
+
try {
|
|
49
|
+
await branchServiceStub.deleteBranch('Test Project ID', 'main')
|
|
50
|
+
t.fail('Branch name validation threw an error with an invalid value')
|
|
51
|
+
} catch (err) {
|
|
52
|
+
t.equal(
|
|
53
|
+
err.toString(),
|
|
54
|
+
'Error: Cannot delete main branch',
|
|
55
|
+
'deleteBranch successfully threw an error when the main branch is deleted'
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
sandbox.restore()
|
|
59
|
+
t.end()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
function checkProjectIdValidation () {
|
|
63
|
+
const badData = [
|
|
64
|
+
{
|
|
65
|
+
testName: 'No Project ID'
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
testName: 'Empty string',
|
|
69
|
+
projectId: ''
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
testName: 'False boolean value',
|
|
73
|
+
projectId: false
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
testName: 'Undefined value',
|
|
77
|
+
projectId: undefined
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
testName: 'Null value',
|
|
81
|
+
projectId: null
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
for (let ii = 0; ii < badData.length; ii++) {
|
|
85
|
+
test(`Project ID validation should throw an error when: ${badData[ii].testName} is passed in`, async t => {
|
|
86
|
+
t.plan(1)
|
|
87
|
+
const responseStub = {
|
|
88
|
+
success: true,
|
|
89
|
+
data: 'Test data response'
|
|
90
|
+
}
|
|
91
|
+
const branchDataMock = {
|
|
92
|
+
name: 'Test_Branch_Name',
|
|
93
|
+
branch: 'not_main'
|
|
94
|
+
}
|
|
95
|
+
const testProjectId = badData[ii].projectId
|
|
96
|
+
const branchServiceStub = new BranchService()
|
|
97
|
+
sandbox.stub(branchServiceStub, '_requireReady').resolves()
|
|
98
|
+
sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
|
|
99
|
+
try {
|
|
100
|
+
await branchServiceStub.deleteBranch(testProjectId, branchDataMock)
|
|
101
|
+
t.fail('Project ID validation threw an error with an invalid value')
|
|
102
|
+
} catch (err) {
|
|
103
|
+
t.equal(
|
|
104
|
+
err.toString(),
|
|
105
|
+
'Error: Project ID is required',
|
|
106
|
+
`Project ID validation successfully threw an error with: ${badData[ii].testName}`
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
sandbox.restore()
|
|
110
|
+
t.end()
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function checkBranchDataNameValidation () {
|
|
116
|
+
const badData = [
|
|
117
|
+
{
|
|
118
|
+
testName: 'No name'
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
testName: 'Empty string',
|
|
122
|
+
name: ''
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
testName: 'False boolean value',
|
|
126
|
+
name: false
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
testName: 'Undefined value',
|
|
130
|
+
name: undefined
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
testName: 'Null value',
|
|
134
|
+
name: null
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
for (let ii = 0; ii < badData.length; ii++) {
|
|
138
|
+
test(`Branch name validation should throw an error when: ${badData[ii].testName} is passed in`, async t => {
|
|
139
|
+
t.plan(1)
|
|
140
|
+
const responseStub = {
|
|
141
|
+
success: true,
|
|
142
|
+
data: 'Test data response'
|
|
143
|
+
}
|
|
144
|
+
const testProjectId = 'Test Project ID'
|
|
145
|
+
const branchServiceStub = new BranchService()
|
|
146
|
+
sandbox.stub(branchServiceStub, '_requireReady').resolves()
|
|
147
|
+
sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
|
|
148
|
+
try {
|
|
149
|
+
await branchServiceStub.deleteBranch(testProjectId, badData[ii].name)
|
|
150
|
+
t.fail('Branch name validation threw an error with an invalid value')
|
|
151
|
+
} catch (err) {
|
|
152
|
+
t.equal(
|
|
153
|
+
err.toString(),
|
|
154
|
+
'Error: Branch name is required',
|
|
155
|
+
`Branch name validation successfully threw an error with: ${badData[ii].testName}`
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
sandbox.restore()
|
|
159
|
+
t.end()
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
checkBranchDataNameValidation()
|
|
165
|
+
checkProjectIdValidation()
|
|
166
|
+
// #endregion
|
|
167
|
+
|
|
168
|
+
// #region Cleanup
|
|
169
|
+
test('teardown', t => {
|
|
170
|
+
sandbox.restore()
|
|
171
|
+
t.end()
|
|
172
|
+
})
|
|
173
|
+
// #endregion
|
|
@@ -0,0 +1,87 @@
|
|
|
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('listBranches should return response data', async t => {
|
|
12
|
+
t.plan(1)
|
|
13
|
+
const responseStub = {
|
|
14
|
+
success: true,
|
|
15
|
+
data: 'Test data response'
|
|
16
|
+
}
|
|
17
|
+
const testProjectId = 'Test Project ID'
|
|
18
|
+
const branchServiceStub = new BranchService()
|
|
19
|
+
sandbox.stub(branchServiceStub, '_requireReady').resolves()
|
|
20
|
+
sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
|
|
21
|
+
const response = await branchServiceStub.listBranches(testProjectId)
|
|
22
|
+
t.equal(
|
|
23
|
+
response,
|
|
24
|
+
responseStub.data,
|
|
25
|
+
'Actual response matches expected response'
|
|
26
|
+
)
|
|
27
|
+
sandbox.restore()
|
|
28
|
+
t.end()
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
function checkProjectIdValidation () {
|
|
32
|
+
const badData = [
|
|
33
|
+
{
|
|
34
|
+
name: 'No Project ID'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'Empty string',
|
|
38
|
+
value: ''
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'False boolean value',
|
|
42
|
+
value: false
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'Undefined value',
|
|
46
|
+
value: undefined
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'Null value',
|
|
50
|
+
value: null
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
for (let ii = 0; ii < badData.length; ii++) {
|
|
54
|
+
test(`Project ID validation should throw an error when: ${badData[ii].name} is passed in`, async t => {
|
|
55
|
+
t.plan(1)
|
|
56
|
+
const responseStub = {
|
|
57
|
+
success: true,
|
|
58
|
+
data: 'Test data response'
|
|
59
|
+
}
|
|
60
|
+
const testProjectId = badData[ii].value
|
|
61
|
+
const branchServiceStub = new BranchService()
|
|
62
|
+
sandbox.stub(branchServiceStub, '_requireReady').resolves()
|
|
63
|
+
sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
|
|
64
|
+
try {
|
|
65
|
+
await branchServiceStub.listBranches(testProjectId)
|
|
66
|
+
t.fail('Project ID validation threw an error with an invalid value')
|
|
67
|
+
} catch (err) {
|
|
68
|
+
t.equal(
|
|
69
|
+
err.toString(),
|
|
70
|
+
'Error: Project ID is required',
|
|
71
|
+
`Project ID validation successfully threw an error with: ${badData[ii].name}`
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
sandbox.restore()
|
|
75
|
+
t.end()
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
checkProjectIdValidation()
|
|
80
|
+
// #endregion
|
|
81
|
+
|
|
82
|
+
// #region Cleanup
|
|
83
|
+
test('teardown', t => {
|
|
84
|
+
sandbox.restore()
|
|
85
|
+
t.end()
|
|
86
|
+
})
|
|
87
|
+
// #endregion
|
|
@@ -0,0 +1,240 @@
|
|
|
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('renameBranch should return response data', async t => {
|
|
12
|
+
t.plan(2)
|
|
13
|
+
const responseStub = {
|
|
14
|
+
success: true,
|
|
15
|
+
data: 'Test data response'
|
|
16
|
+
}
|
|
17
|
+
const branchDataMock = {
|
|
18
|
+
name: 'Test_Branch_Name',
|
|
19
|
+
branch: 'not_main'
|
|
20
|
+
}
|
|
21
|
+
const testProjectId = 'Test Project ID'
|
|
22
|
+
const testNewBranchName = 'Test_New_Branch_Name'
|
|
23
|
+
const branchServiceStub = new BranchService()
|
|
24
|
+
sandbox.stub(branchServiceStub, '_requireReady').resolves()
|
|
25
|
+
sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
|
|
26
|
+
const response = await branchServiceStub.renameBranch(
|
|
27
|
+
testProjectId,
|
|
28
|
+
branchDataMock.branch,
|
|
29
|
+
testNewBranchName
|
|
30
|
+
)
|
|
31
|
+
t.ok(response.success, 'Response successfully returned')
|
|
32
|
+
t.equal(
|
|
33
|
+
response.data,
|
|
34
|
+
responseStub.data,
|
|
35
|
+
'Actual response matches expected response'
|
|
36
|
+
)
|
|
37
|
+
sandbox.restore()
|
|
38
|
+
t.end()
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test('Branch name validation should throw an error when the branch is main', async t => {
|
|
42
|
+
t.plan(1)
|
|
43
|
+
const responseStub = {
|
|
44
|
+
success: true,
|
|
45
|
+
data: 'Test data response'
|
|
46
|
+
}
|
|
47
|
+
const branchServiceStub = new BranchService()
|
|
48
|
+
sandbox.stub(branchServiceStub, '_requireReady').resolves()
|
|
49
|
+
sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
|
|
50
|
+
try {
|
|
51
|
+
await branchServiceStub.renameBranch(
|
|
52
|
+
'Test Project ID',
|
|
53
|
+
'main',
|
|
54
|
+
'Test_New_Branch_Name'
|
|
55
|
+
)
|
|
56
|
+
t.fail('Branch name validation threw an error with an invalid value')
|
|
57
|
+
} catch (err) {
|
|
58
|
+
t.equal(
|
|
59
|
+
err.toString(),
|
|
60
|
+
'Error: Cannot rename main branch',
|
|
61
|
+
'renameBranch successfully threw an error when the main branch is deleted'
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
sandbox.restore()
|
|
65
|
+
t.end()
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
function checkProjectIdValidation () {
|
|
69
|
+
const badData = [
|
|
70
|
+
{
|
|
71
|
+
testName: 'No Project ID'
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
testName: 'Empty string',
|
|
75
|
+
projectId: ''
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
testName: 'False boolean value',
|
|
79
|
+
projectId: false
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
testName: 'Undefined value',
|
|
83
|
+
projectId: undefined
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
testName: 'Null value',
|
|
87
|
+
projectId: null
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
for (let ii = 0; ii < badData.length; ii++) {
|
|
91
|
+
test(`Project ID validation should throw an error when: ${badData[ii].testName} is passed in`, async t => {
|
|
92
|
+
t.plan(1)
|
|
93
|
+
const responseStub = {
|
|
94
|
+
success: true,
|
|
95
|
+
data: 'Test data response'
|
|
96
|
+
}
|
|
97
|
+
const branchDataMock = {
|
|
98
|
+
name: 'Test_Branch_Name',
|
|
99
|
+
branch: 'not_main'
|
|
100
|
+
}
|
|
101
|
+
const testProjectId = badData[ii].projectId
|
|
102
|
+
const branchServiceStub = new BranchService()
|
|
103
|
+
sandbox.stub(branchServiceStub, '_requireReady').resolves()
|
|
104
|
+
sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
|
|
105
|
+
try {
|
|
106
|
+
await branchServiceStub.renameBranch(
|
|
107
|
+
testProjectId,
|
|
108
|
+
branchDataMock.branch,
|
|
109
|
+
'Test_New_Branch_Name'
|
|
110
|
+
)
|
|
111
|
+
t.fail('Project ID validation threw an error with an invalid value')
|
|
112
|
+
} catch (err) {
|
|
113
|
+
t.equal(
|
|
114
|
+
err.toString(),
|
|
115
|
+
'Error: Project ID is required',
|
|
116
|
+
`Project ID validation successfully threw an error with: ${badData[ii].testName}`
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
sandbox.restore()
|
|
120
|
+
t.end()
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function checkBranchDataNameValidation () {
|
|
126
|
+
const badData = [
|
|
127
|
+
{
|
|
128
|
+
testName: 'No name'
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
testName: 'Empty string',
|
|
132
|
+
name: ''
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
testName: 'False boolean value',
|
|
136
|
+
name: false
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
testName: 'Undefined value',
|
|
140
|
+
name: undefined
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
testName: 'Null value',
|
|
144
|
+
name: null
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
for (let ii = 0; ii < badData.length; ii++) {
|
|
148
|
+
test(`Branch name validation should throw an error when: ${badData[ii].testName} is passed in`, async t => {
|
|
149
|
+
t.plan(1)
|
|
150
|
+
const responseStub = {
|
|
151
|
+
success: true,
|
|
152
|
+
data: 'Test data response'
|
|
153
|
+
}
|
|
154
|
+
const testProjectId = 'Test Project ID'
|
|
155
|
+
const branchServiceStub = new BranchService()
|
|
156
|
+
sandbox.stub(branchServiceStub, '_requireReady').resolves()
|
|
157
|
+
sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
|
|
158
|
+
try {
|
|
159
|
+
await branchServiceStub.renameBranch(
|
|
160
|
+
testProjectId,
|
|
161
|
+
badData[ii].name,
|
|
162
|
+
'Test_New_Branch_Name'
|
|
163
|
+
)
|
|
164
|
+
t.fail('Branch name validation threw an error with an invalid value')
|
|
165
|
+
} catch (err) {
|
|
166
|
+
t.equal(
|
|
167
|
+
err.toString(),
|
|
168
|
+
'Error: Current branch name is required',
|
|
169
|
+
`Branch name validation successfully threw an error with: ${badData[ii].testName}`
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
sandbox.restore()
|
|
173
|
+
t.end()
|
|
174
|
+
})
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function checkNewBranchNameValidation () {
|
|
179
|
+
const badData = [
|
|
180
|
+
{
|
|
181
|
+
testName: 'No name'
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
testName: 'Empty string',
|
|
185
|
+
name: ''
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
testName: 'False boolean value',
|
|
189
|
+
name: false
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
testName: 'Undefined value',
|
|
193
|
+
name: undefined
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
testName: 'Null value',
|
|
197
|
+
name: null
|
|
198
|
+
}
|
|
199
|
+
]
|
|
200
|
+
for (let ii = 0; ii < badData.length; ii++) {
|
|
201
|
+
test(`New branch name validation should throw an error when: ${badData[ii].testName} is passed in`, async t => {
|
|
202
|
+
t.plan(1)
|
|
203
|
+
const responseStub = {
|
|
204
|
+
success: true,
|
|
205
|
+
data: 'Test data response'
|
|
206
|
+
}
|
|
207
|
+
const branchServiceStub = new BranchService()
|
|
208
|
+
sandbox.stub(branchServiceStub, '_requireReady').resolves()
|
|
209
|
+
sandbox.stub(branchServiceStub, '_request').resolves(responseStub)
|
|
210
|
+
try {
|
|
211
|
+
await branchServiceStub.renameBranch(
|
|
212
|
+
'Test Project ID',
|
|
213
|
+
'Test_Branch_Name',
|
|
214
|
+
badData[ii].name
|
|
215
|
+
)
|
|
216
|
+
t.fail('Branch name validation threw an error with an invalid value')
|
|
217
|
+
} catch (err) {
|
|
218
|
+
t.equal(
|
|
219
|
+
err.toString(),
|
|
220
|
+
'Error: New branch name is required',
|
|
221
|
+
`Branch name validation successfully threw an error with: ${badData[ii].testName}`
|
|
222
|
+
)
|
|
223
|
+
}
|
|
224
|
+
sandbox.restore()
|
|
225
|
+
t.end()
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
checkBranchDataNameValidation()
|
|
231
|
+
checkNewBranchNameValidation()
|
|
232
|
+
checkProjectIdValidation()
|
|
233
|
+
// #endregion
|
|
234
|
+
|
|
235
|
+
// #region Cleanup
|
|
236
|
+
test('teardown', t => {
|
|
237
|
+
sandbox.restore()
|
|
238
|
+
t.end()
|
|
239
|
+
})
|
|
240
|
+
// #endregion
|