Skip to content

Commit 34be60b

Browse files
Muzaffer AydinMuzaffer Aydin
authored andcommitted
fix(docdb): fix jscpd errors
1 parent 50fc468 commit 34be60b

File tree

12 files changed

+68
-86
lines changed

12 files changed

+68
-86
lines changed

packages/core/src/docdb/explorer/dbClusterNode.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export class DBClusterNode extends DBResourceNode {
152152
}
153153

154154
getLogger().debug(`Get Status: status ${cluster.Status} for cluster ${this.arn}`)
155+
155156
this.cluster.Status = cluster.Status
156157
return cluster.Status
157158
}

packages/core/src/docdb/explorer/dbElasticClusterNode.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,17 @@ export class DBElasticClusterNode extends DBResourceNode {
100100
await copyToClipboard(this.cluster.clusterEndpoint!, this.name)
101101
}
102102

103+
override clearTimer(): void {
104+
this.pollingSet.delete(this.arn)
105+
this.pollingSet.clearTimer()
106+
}
107+
103108
override refreshTree(): void {
104109
getLogger().debug(`(DBElasticClusterNode) Refreshing tree for instance: ${this.arn}`)
105110
this.refresh()
106111
this.parent.refresh()
107112
}
108113

109-
override clearTimer(): void {
110-
this.pollingSet.delete(this.arn)
111-
this.pollingSet.clearTimer()
112-
}
113-
114114
public override [inspect.custom](): string {
115115
return 'DBElasticClusterNode'
116116
}

packages/core/src/docdb/wizards/elasticClusterWizard.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ function createShardCapacityPrompter(title: string): Prompter<number> {
118118

119119
function instanceCountItems(defaultCount: number, max: number = 16): DataQuickPickItem<number>[] {
120120
const items = []
121-
122-
for (let index = 1; index <= max; index++) {
121+
for (let i = 1; i <= max; i++) {
123122
const item: DataQuickPickItem<number> = {
124-
label: index.toString(),
125-
data: index,
126-
description: index === defaultCount ? '(recommended)' : undefined,
123+
label: i.toString(),
124+
data: i,
125+
description: i === defaultCount ? '(recommended)' : undefined,
127126
}
127+
128128
items.push(item)
129129
}
130130

packages/core/src/test/docdb/commands/addRegion.test.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,30 @@ describe('addRegionCommand', function () {
4848

4949
cluster.DBClusterMembers = [{ IsClusterWriter: true }]
5050
const parentNode = new DocumentDBNode(docdb)
51+
5152
node = new DBClusterNode(parentNode, cluster, docdb)
5253
})
53-
5454
afterEach(function () {
5555
sandbox.restore()
5656
getTestWindow().dispose()
5757
})
58-
5958
function setupWizard() {
6059
getTestWindow().onDidShowInputBox((input) => {
61-
let value: string
60+
let val: string
61+
6262
if (input.prompt?.includes('global')) {
63-
value = globalClusterName
63+
val = globalClusterName
6464
} else if (input.prompt?.includes('cluster name')) {
65-
value = clusterName
65+
val = clusterName
6666
} else {
67-
value = ''
67+
val = ''
6868
}
69-
input.acceptValue(value)
69+
input.acceptValue(val)
7070
})
7171

72-
getTestWindow().onDidShowQuickPick(async (picker) => {
73-
await picker.untilReady()
74-
picker.acceptItem(picker.items[0])
72+
getTestWindow().onDidShowQuickPick(async (testQuickPicker) => {
73+
await testQuickPicker.untilReady()
74+
testQuickPicker.acceptItem(testQuickPicker.items[0])
7575
})
7676
}
7777

@@ -83,10 +83,11 @@ describe('addRegionCommand', function () {
8383
const createClusterStub = sinon.stub().resolves({
8484
DBClusterIdentifier: clusterName,
8585
})
86-
const createInstanceStub = sinon.stub().resolves()
86+
const createInstanceSinonStub = sinon.stub().resolves()
8787
docdb.createGlobalCluster = createGlobalClusterStub
8888
docdb.createCluster = createClusterStub
89-
docdb.createInstance = createInstanceStub
89+
docdb.createInstance = createInstanceSinonStub
90+
9091
setupWizard()
9192

9293
// act
@@ -110,9 +111,8 @@ describe('addRegionCommand', function () {
110111
})
111112
)
112113
)
113-
114114
assert(
115-
createInstanceStub.calledOnceWith(
115+
createInstanceSinonStub.calledOnceWith(
116116
sinon.match({
117117
Engine: 'docdb',
118118
DBClusterIdentifier: clusterName,
@@ -132,13 +132,13 @@ describe('addRegionCommand', function () {
132132
const createGlobalClusterStub = sinon.stub().resolves({
133133
GlobalClusterIdentifier: globalClusterName,
134134
})
135-
const createClusterStub = sinon.stub().resolves({
135+
const createClusterSinonStub = sinon.stub().resolves({
136136
DBClusterIdentifier: clusterName,
137137
})
138-
const createInstanceStub = sinon.stub().resolves()
138+
const createInstanceSinonStub = sinon.stub().resolves()
139139
docdb.createGlobalCluster = createGlobalClusterStub
140-
docdb.createCluster = createClusterStub
141-
docdb.createInstance = createInstanceStub
140+
docdb.createCluster = createClusterSinonStub
141+
docdb.createInstance = createInstanceSinonStub
142142
setupWizard()
143143

144144
const globalCluster: GlobalCluster = {
@@ -157,7 +157,7 @@ describe('addRegionCommand', function () {
157157
assert(createGlobalClusterStub.notCalled)
158158

159159
assert(
160-
createClusterStub.calledOnceWith(
160+
createClusterSinonStub.calledOnceWith(
161161
sinon.match({
162162
DBClusterIdentifier: clusterName,
163163
GlobalClusterIdentifier: globalClusterName,
@@ -166,7 +166,7 @@ describe('addRegionCommand', function () {
166166
)
167167

168168
assert(
169-
createInstanceStub.calledOnceWith(
169+
createInstanceSinonStub.calledOnceWith(
170170
sinon.match({
171171
Engine: 'docdb',
172172
DBClusterIdentifier: clusterName,
@@ -175,7 +175,6 @@ describe('addRegionCommand', function () {
175175
})
176176
)
177177
)
178-
179178
sandbox.assert.calledWith(spyExecuteCommand, 'aws.refreshAwsExplorerNode', node)
180179

181180
assertTelemetry('docdb_addRegion', { result: 'Succeeded' })

packages/core/src/test/docdb/commands/createCluster.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import { createCluster } from '../../../docdb/commands/createCluster'
1414

1515
describe('createClusterCommand', function () {
1616
const clusterName = 'docdb-1234'
17-
const username = 'testuser'
18-
const password = 'test-password'
17+
const testUser = 'testuser'
18+
const testPassword = 'test-password'
1919
let docdb: DocumentDBClient
2020
let node: DocumentDBNode
2121
let sandbox: sinon.SinonSandbox
@@ -43,17 +43,16 @@ describe('createClusterCommand', function () {
4343
getTestWindow().onDidShowInputBox((input) => {
4444
let value: string
4545
if (input.prompt?.includes('username')) {
46-
value = username
46+
value = testUser
4747
} else if (input.prompt?.includes('password')) {
48-
value = password
48+
value = testPassword
4949
} else if (input.prompt?.includes('cluster name')) {
5050
value = clusterName
5151
} else {
5252
value = ''
5353
}
5454
input.acceptValue(value)
5555
})
56-
5756
getTestWindow().onDidShowQuickPick(async (picker) => {
5857
await picker.untilReady()
5958
picker.acceptItem(picker.items[0])
@@ -85,8 +84,8 @@ describe('createClusterCommand', function () {
8584
Engine: 'docdb',
8685
EngineVersion: 'test-version',
8786
DBClusterIdentifier: clusterName,
88-
MasterUsername: username,
89-
MasterUserPassword: password,
87+
MasterUsername: testUser,
88+
MasterUserPassword: testPassword,
9089
StorageEncrypted: true,
9190
DBInstanceCount: 1,
9291
DBInstanceClass: 'db.t3.medium',

packages/core/src/test/docdb/commands/createInstance.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ describe('createInstanceCommand', function () {
2020
let docdb: DocumentDBClient
2121
let cluster: DBCluster
2222
let node: DBClusterNode
23-
let sandbox: sinon.SinonSandbox
2423
let spyExecuteCommand: sinon.SinonSpy
24+
let sandbox: sinon.SinonSandbox
2525

2626
beforeEach(function () {
2727
sandbox = sinon.createSandbox()
2828
spyExecuteCommand = sandbox.spy(vscode.commands, 'executeCommand')
2929

3030
docdb = { regionCode: 'us-east-1' } as DocumentDBClient
31+
3132
docdb.listInstances = sinon.stub().resolves([])
33+
3234
docdb.listInstanceClassOptions = sinon
3335
.stub()
3436
.resolves([{ DBInstanceClass: 'db.t3.medium', StorageType: DBStorageType.Standard }])
@@ -42,7 +44,6 @@ describe('createInstanceCommand', function () {
4244
sandbox.restore()
4345
getTestWindow().dispose()
4446
})
45-
4647
function setupWizard() {
4748
getTestWindow().onDidShowInputBox((input) => {
4849
input.acceptValue(instanceName)

packages/core/src/test/docdb/commands/deleteCluster.test.ts

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,17 @@ import { deleteCluster } from '../../../docdb/commands/deleteCluster'
1818
describe('deleteClusterCommand', function () {
1919
const clusterName = 'test-cluster'
2020
let docdb: DocumentDBClient
21-
let sandbox: sinon.SinonSandbox
21+
let sinonSandbox: sinon.SinonSandbox
2222
let spyExecuteCommand: sinon.SinonSpy
2323

2424
beforeEach(function () {
25-
sandbox = sinon.createSandbox()
26-
spyExecuteCommand = sandbox.spy(vscode.commands, 'executeCommand')
25+
sinonSandbox = sinon.createSandbox()
26+
spyExecuteCommand = sinonSandbox.spy(vscode.commands, 'executeCommand')
2727
})
28-
2928
afterEach(function () {
30-
sandbox.restore()
29+
sinonSandbox.restore()
3130
getTestWindow().dispose()
3231
})
33-
3432
function setupWizard() {
3533
getTestWindow().onDidShowInputBox((input) => {
3634
input.acceptValue(input.placeholder!)
@@ -85,42 +83,33 @@ describe('deleteClusterCommand', function () {
8583

8684
assert(deleteClusterStub.calledOnceWithExactly(sinon.match({ DBClusterIdentifier: clusterName })))
8785
assert(deleteInstanceStub.calledTwice)
88-
sandbox.assert.calledWith(spyExecuteCommand, 'aws.refreshAwsExplorerNode', node.parent)
86+
sinonSandbox.assert.calledWith(spyExecuteCommand, 'aws.refreshAwsExplorerNode', node.parent)
8987

9088
assertTelemetry('docdb_deleteCluster', {
9189
result: 'Succeeded',
9290
})
9391
})
9492

9593
it('does nothing when prompt is cancelled', async function () {
96-
// arrange
9794
const deleteClusterStub = sinon.stub()
9895
docdb.deleteCluster = deleteClusterStub
9996
getTestWindow().onDidShowQuickPick((picker) => picker.hide())
10097
getTestWindow().onDidShowInputBox((input) => input.hide())
10198

102-
// act
10399
await assert.rejects(deleteCluster(node))
104-
105-
// assert
106100
assert(deleteClusterStub.notCalled)
107-
108101
assertTelemetry('docdb_deleteCluster', {
109102
result: 'Cancelled',
110103
})
111104
})
112105

113106
it('shows a warning when the cluster is stopped', async function () {
114-
// arrange
115107
cluster.Status = 'stopped'
116108
const deleteClusterStub = sinon.stub()
117109
docdb.deleteCluster = deleteClusterStub
118110
setupWizard()
119111

120-
// act
121112
await assert.rejects(deleteCluster(node))
122-
123-
// assert
124113
getTestWindow()
125114
.getFirstMessage()
126115
.assertMessage(/Cluster must be running/)
@@ -131,15 +120,12 @@ describe('deleteClusterCommand', function () {
131120
})
132121

133122
it('shows an error when cluster deletion fails', async function () {
134-
// arrange
135123
const deleteClusterStub = sinon.stub().rejects()
136124
docdb.deleteCluster = deleteClusterStub
137125
setupWizard()
138126

139-
// act
140127
await assert.rejects(deleteCluster(node))
141128

142-
// assert
143129
getTestWindow()
144130
.getFirstMessage()
145131
.assertError(/Failed to delete cluster: test-cluster/)
@@ -156,7 +142,6 @@ describe('deleteClusterCommand', function () {
156142

157143
beforeEach(function () {
158144
cluster = { clusterName, clusterArn: 'arn:test-cluster', status: 'ACTIVE' }
159-
160145
docdb = { regionCode: 'us-east-1' } as DocumentDBClient
161146
docdb.listElasticClusters = sinon.stub().resolves([cluster])
162147

@@ -187,7 +172,7 @@ describe('deleteClusterCommand', function () {
187172

188173
assert(createSnapshotStub.calledOnceWithExactly(sinon.match({ clusterArn: cluster.clusterArn })))
189174
assert(deleteClusterStub.calledOnceWithExactly(cluster.clusterArn))
190-
sandbox.assert.calledWith(spyExecuteCommand, 'aws.refreshAwsExplorerNode', node.parent)
175+
sinonSandbox.assert.calledWith(spyExecuteCommand, 'aws.refreshAwsExplorerNode', node.parent)
191176

192177
assertTelemetry('docdb_deleteCluster', {
193178
result: 'Succeeded',

packages/core/src/test/docdb/commands/deleteInstance.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@ describe('deleteInstanceCommand', function () {
2121
let instance: DBInstance
2222
let parentNode: DBClusterNode
2323
let node: DBInstanceNode
24-
let sandbox: sinon.SinonSandbox
2524
let spyExecuteCommand: sinon.SinonSpy
25+
let sandbox: sinon.SinonSandbox
2626

2727
beforeEach(function () {
2828
sandbox = sinon.createSandbox()
2929
spyExecuteCommand = sandbox.spy(vscode.commands, 'executeCommand')
30-
3130
docdb = { regionCode: 'us-east-1' } as DocumentDBClient
32-
3331
cluster = { Status: 'available' }
3432
instance = {
3533
DBInstanceIdentifier: instanceName,
@@ -39,12 +37,10 @@ describe('deleteInstanceCommand', function () {
3937
parentNode = new DBClusterNode(undefined!, cluster, docdb)
4038
node = new DBInstanceNode(parentNode, instance)
4139
})
42-
4340
afterEach(function () {
4441
sandbox.restore()
4542
getTestWindow().dispose()
4643
})
47-
4844
function setupWizard() {
4945
getTestWindow().onDidShowInputBox((input) => {
5046
input.acceptValue(instanceName)

packages/core/src/test/docdb/commands/modifyInstance.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ describe('modifyInstanceCommand', function () {
2222
let cluster: DBCluster
2323
let instance: DBInstance
2424
let node: DBInstanceNode
25-
let sandbox: sinon.SinonSandbox
2625
let spyExecuteCommand: sinon.SinonSpy
27-
26+
let sandbox: sinon.SinonSandbox
2827
beforeEach(function () {
2928
sandbox = sinon.createSandbox()
3029
spyExecuteCommand = sandbox.spy(vscode.commands, 'executeCommand')
31-
3230
docdb = { regionCode: 'us-east-1' } as DocumentDBClient
3331
docdb.listInstanceClassOptions = sinon
3432
.stub()

packages/core/src/test/docdb/commands/renameCluster.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ describe('renameClusterCommand', function () {
1818
const clusterName = 'test-cluster'
1919
const newClusterName = 'new-cluster-name'
2020
let docdb: DocumentDBClient
21+
let spyExecuteCommand: sinon.SinonSpy
2122
let cluster: DBCluster
2223
let node: DBClusterNode
2324
let sandbox: sinon.SinonSandbox
24-
let spyExecuteCommand: sinon.SinonSpy
2525

2626
beforeEach(function () {
2727
sandbox = sinon.createSandbox()

0 commit comments

Comments
 (0)