Skip to content

Commit b57b897

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

File tree

11 files changed

+36
-52
lines changed

11 files changed

+36
-52
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ export class DBClusterNode extends DBResourceNode {
150150
getLogger().warn(`No cluster found for ARN: ${this.arn}`)
151151
return undefined
152152
}
153-
154153
getLogger().debug(`Get Status: status ${cluster.Status} for cluster ${this.arn}`)
154+
155155
this.cluster.Status = cluster.Status
156156
return cluster.Status
157157
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,14 @@ export class DBElasticClusterNode extends DBResourceNode {
102102

103103
override refreshTree(): void {
104104
getLogger().debug(`(DBElasticClusterNode) Refreshing tree for instance: ${this.arn}`)
105+
105106
this.refresh()
106107
this.parent.refresh()
107108
}
108-
109109
override clearTimer(): void {
110110
this.pollingSet.delete(this.arn)
111111
this.pollingSet.clearTimer()
112112
}
113-
114113
public override [inspect.custom](): string {
115114
return 'DBElasticClusterNode'
116115
}

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

Lines changed: 1 addition & 1 deletion
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-
122121
for (let index = 1; index <= max; index++) {
123122
const item: DataQuickPickItem<number> = {
124123
label: index.toString(),
125124
data: index,
126125
description: index === defaultCount ? '(recommended)' : undefined,
127126
}
127+
128128
items.push(item)
129129
}
130130

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,16 @@ describe('addRegionCommand', function () {
8080
const createGlobalClusterStub = sinon.stub().resolves({
8181
GlobalClusterIdentifier: globalClusterName,
8282
})
83+
8384
const createClusterStub = sinon.stub().resolves({
8485
DBClusterIdentifier: clusterName,
8586
})
87+
8688
const createInstanceStub = sinon.stub().resolves()
8789
docdb.createGlobalCluster = createGlobalClusterStub
8890
docdb.createCluster = createClusterStub
8991
docdb.createInstance = createInstanceStub
92+
9093
setupWizard()
9194

9295
// act
@@ -110,7 +113,6 @@ describe('addRegionCommand', function () {
110113
})
111114
)
112115
)
113-
114116
assert(
115117
createInstanceStub.calledOnceWith(
116118
sinon.match({
@@ -175,7 +177,6 @@ describe('addRegionCommand', function () {
175177
})
176178
)
177179
)
178-
179180
sandbox.assert.calledWith(spyExecuteCommand, 'aws.refreshAwsExplorerNode', node)
180181

181182
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: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ describe('deleteClusterCommand', function () {
2525
sandbox = sinon.createSandbox()
2626
spyExecuteCommand = sandbox.spy(vscode.commands, 'executeCommand')
2727
})
28-
2928
afterEach(function () {
3029
sandbox.restore()
3130
getTestWindow().dispose()
3231
})
33-
3432
function setupWizard() {
3533
getTestWindow().onDidShowInputBox((input) => {
3634
input.acceptValue(input.placeholder!)
@@ -93,34 +91,25 @@ describe('deleteClusterCommand', function () {
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

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/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()

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,30 +80,33 @@ describe('DBClusterNode', function () {
8080
trackChangesSpy.restore()
8181
})
8282

83-
it('does not start tracking changes when status does not require polling', function () {
84-
const clusterStatus = { ...cluster, Status: 'available' }
83+
function assertNodeDoesNotPoll(clusterStatus: any, message: string) {
8584
const trackChangesSpy = sinon.spy(DBClusterNode.prototype, 'trackChanges')
8685
const node = new DBClusterNode(parentNode, clusterStatus, mockClient)
8786
const requiresPolling = node.isStatusRequiringPolling()
8887

89-
assert.strictEqual(requiresPolling, false, 'isStatusRequiringPolling should return false for available status')
90-
assert.ok(trackChangesSpy.notCalled, 'trackChanges should not be called when polling is not required')
91-
assert.strictEqual(node.isPolling, false, 'Node should not be in polling state')
88+
assert.strictEqual(
89+
requiresPolling,
90+
false,
91+
`${message}: isStatusRequiringPolling should return false for available status`
92+
)
93+
assert.ok(
94+
trackChangesSpy.notCalled,
95+
`${message}: trackChanges should not be called when polling is not required`
96+
)
97+
assert.strictEqual(node.isPolling, false, `${message}: Node should not be in polling state`)
9298

9399
trackChangesSpy.restore()
100+
}
101+
102+
it('does not start tracking changes when status does not require polling', function () {
103+
const clusterStatus = { ...cluster, Status: 'available' }
104+
assertNodeDoesNotPoll(clusterStatus, 'does not start tracking changes')
94105
})
95106

96107
it('does not poll when status is available', function () {
97108
const clusterStatus = { ...cluster, Status: 'available' }
98-
const trackChangesSpy = sinon.spy(DBClusterNode.prototype, 'trackChanges')
99-
const node = new DBClusterNode(parentNode, clusterStatus, mockClient)
100-
const requiresPolling = node.isStatusRequiringPolling()
101-
102-
assert.strictEqual(requiresPolling, false, 'isStatusRequiringPolling should return false for available status')
103-
assert.ok(trackChangesSpy.notCalled, 'trackChanges should not be called when polling is not required')
104-
assert.strictEqual(node.isPolling, false, 'Node should not be in polling state')
105-
106-
trackChangesSpy.restore()
109+
assertNodeDoesNotPoll(clusterStatus, 'does not poll')
107110
})
108111

109112
it('has isPolling set to false and getStatus returns available when status is available', async function () {

0 commit comments

Comments
 (0)