Skip to content

Commit b2b639a

Browse files
fix unit tests
Signed-off-by: nkomonen-amazon <[email protected]>
1 parent 022d858 commit b2b639a

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

packages/core/src/shared/telemetry/util.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,14 @@ let _hadClientIdOnStartup = false
217217
/**
218218
* Returns true if the ClientID existed before this session started
219219
*/
220-
export const hadClientIdOnStartup = (globalState: GlobalState) => {
220+
export const hadClientIdOnStartup = (
221+
globalState: GlobalState,
222+
update = (globalState: GlobalState) => {
223+
getClientId(globalState)
224+
}
225+
) => {
221226
// triggers the flow that will update the state, if not done already
222-
getClientId(globalState)
227+
update(globalState)
223228

224229
return _hadClientIdOnStartup
225230
}

packages/core/src/test/credentials/utils.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ import globals from '../../shared/extensionGlobals'
1111

1212
describe('ExtensionUse.isFirstUse()', function () {
1313
let instance: ExtensionUse
14+
const notHasExistingConnections = () => false
1415

1516
beforeEach(async function () {
1617
instance = new ExtensionUse()
17-
await globals.globalState.update(ExtensionUse.instance.isExtensionFirstUseKey, true)
18+
await makeStateValueNotExist()
1819
})
1920

2021
it('is true only on first startup', function () {
21-
assert.strictEqual(instance.isFirstUse(), true, 'Failed on first call.')
22-
assert.strictEqual(instance.isFirstUse(), true, 'Failed on second call.')
22+
assert.strictEqual(instance.isFirstUse(notHasExistingConnections), true, 'Failed on first call.')
23+
assert.strictEqual(instance.isFirstUse(notHasExistingConnections), true, 'Failed on second call.')
2324

2425
const nextStartup = nextExtensionStartup()
25-
assert.strictEqual(nextStartup.isFirstUse(), false, 'Failed on new startup.')
26+
assert.strictEqual(nextStartup.isFirstUse(notHasExistingConnections), false, 'Failed on new startup.')
2627
})
2728

2829
it('true when: (state value not exists + NOT has existing connections)', async function () {
2930
await makeStateValueNotExist()
30-
const notHasExistingConnections = () => false
3131
assert.strictEqual(
3232
instance.isFirstUse(notHasExistingConnections),
3333
true,

packages/core/src/test/shared/telemetry/util.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ describe('getClientId', function () {
141141
}
142142

143143
function setClientIdEnvVar(val: string | undefined) {
144+
if (val === undefined) {
145+
delete process.env[telemetryClientIdEnvKey]
146+
return
147+
}
148+
144149
process.env[telemetryClientIdEnvKey] = val
145150
}
146151

@@ -227,19 +232,19 @@ describe('getClientId', function () {
227232
describe('hadClientIdOnStartup', async function () {
228233
it('returns false when no existing clientId', async function () {
229234
const globalState = new GlobalState(new FakeMemento())
230-
assert.strictEqual(hadClientIdOnStartup(globalState), false)
235+
assert.strictEqual(hadClientIdOnStartup(globalState, testGetClientId), false)
231236
})
232237

233238
it('returns true when existing env var clientId', async function () {
234239
const globalState = new GlobalState(new FakeMemento())
235240
setClientIdEnvVar('aaa-111')
236-
assert.strictEqual(hadClientIdOnStartup(globalState), true)
241+
assert.strictEqual(hadClientIdOnStartup(globalState, testGetClientId), true)
237242
})
238243

239244
it('returns true when existing state clientId', async function () {
240245
const globalState = new GlobalState(new FakeMemento())
241246
await globalState.update('telemetryClientId', 'bbb-222')
242-
assert.strictEqual(hadClientIdOnStartup(globalState), true)
247+
assert.strictEqual(hadClientIdOnStartup(globalState, testGetClientId), true)
243248
})
244249
})
245250
})

0 commit comments

Comments
 (0)