-
Notifications
You must be signed in to change notification settings - Fork 793
fix(cloudformation): handle telemetry setting in upgrade path case where setting is not registered #8343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
fix(cloudformation): handle telemetry setting in upgrade path case where setting is not registered #8343
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d301575
fix(cloudformation): handle telemetry setting in upgrade path case wh…
e91d6ae
refactor
914a08b
More edge cases
8635518
Merge branch 'master' into fix/settings
atennak1 8d3701d
changelog
2a9c4b7
use globals
d69c5ed
Merge branch 'master' into fix/settings
atennak1 5df70c4
Merge branch 'master' into fix/settings
manodnyab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
packages/core/src/test/awsService/cloudformation/telemetryOptIn.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /*! | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import assert from 'assert' | ||
| import * as sinon from 'sinon' | ||
| import { ExtensionContext } from 'vscode' | ||
| import { handleTelemetryOptIn } from '../../../awsService/cloudformation/telemetryOptIn' | ||
| import { CloudFormationTelemetrySettings } from '../../../awsService/cloudformation/extensionConfig' | ||
| import { commandKey } from '../../../awsService/cloudformation/utils' | ||
|
|
||
| describe('telemetryOptIn', function () { | ||
| let mockContext: ExtensionContext | ||
| let mockSettings: CloudFormationTelemetrySettings | ||
| let globalState: Map<string, any> | ||
|
|
||
| beforeEach(function () { | ||
| globalState = new Map() | ||
|
|
||
| mockContext = { | ||
| globalState: { | ||
| get: (key: string, defaultValue?: any) => globalState.get(key) ?? defaultValue, | ||
| update: async (key: string, value: any) => { | ||
| globalState.set(key, value) | ||
| }, | ||
| }, | ||
| } as any | ||
|
|
||
| mockSettings = { | ||
| get: sinon.stub().returns(false), | ||
| update: sinon.stub().resolves(), | ||
| } as any | ||
| }) | ||
|
|
||
| describe('promptTelemetryOptIn - automation mode', function () { | ||
| it('should return current setting without prompting in automation mode', async function () { | ||
| sinon.stub(require('../../../shared/vscode/env'), 'isAutomation').returns(true) | ||
| ;(mockSettings.get as sinon.SinonStub).returns(true) | ||
|
|
||
| const result = await handleTelemetryOptIn(mockContext, mockSettings) | ||
|
|
||
| assert.strictEqual(result, true) | ||
| }) | ||
| }) | ||
|
|
||
| describe('promptTelemetryOptIn - user has responded', function () { | ||
| it('should return current setting if user has permanently responded', async function () { | ||
| globalState.set(commandKey('telemetry.hasResponded'), true) | ||
| ;(mockSettings.get as sinon.SinonStub).returns(true) | ||
|
|
||
| const result = await handleTelemetryOptIn(mockContext, mockSettings) | ||
|
|
||
| assert.strictEqual(result, true) | ||
| }) | ||
| }) | ||
|
|
||
| describe('promptTelemetryOptIn - prompt timing', function () { | ||
| it('should not prompt if less than 30 days since last prompt', async function () { | ||
| const now = Date.now() | ||
| const twentyDaysAgo = now - 20 * 24 * 60 * 60 * 1000 | ||
| globalState.set(commandKey('telemetry.lastPromptDate'), twentyDaysAgo) | ||
|
|
||
| const result = await handleTelemetryOptIn(mockContext, mockSettings) | ||
|
|
||
| assert.strictEqual(result, false) | ||
| }) | ||
| }) | ||
|
|
||
| describe('promptTelemetryOptIn - unpersisted response', function () { | ||
| it('should persist unpersisted Allow response', async function () { | ||
| globalState.set(commandKey('telemetry.unpersistedResponse'), 'Yes, Allow') | ||
|
|
||
| const result = await handleTelemetryOptIn(mockContext, mockSettings) | ||
|
|
||
| assert.strictEqual(result, true) | ||
| assert.ok((mockSettings.update as sinon.SinonStub).calledWith('enabled', true)) | ||
| assert.strictEqual(globalState.get(commandKey('telemetry.unpersistedResponse')), undefined) | ||
| }) | ||
|
|
||
| it('should persist unpersisted Never response', async function () { | ||
| globalState.set(commandKey('telemetry.unpersistedResponse'), 'Never') | ||
| ;(mockSettings.update as sinon.SinonStub).resolves(true) | ||
|
|
||
| const result = await handleTelemetryOptIn(mockContext, mockSettings) | ||
|
|
||
| assert.strictEqual(result, false) | ||
| assert.ok((mockSettings.update as sinon.SinonStub).calledWith('enabled', false)) | ||
| assert.strictEqual(globalState.get(commandKey('telemetry.unpersistedResponse')), undefined) | ||
| }) | ||
|
|
||
| it('should persist unpersisted Later response', async function () { | ||
| const lastPromptDate = Date.now() - 1000 | ||
| globalState.set(commandKey('telemetry.unpersistedResponse'), 'Not Now') | ||
| globalState.set(commandKey('telemetry.lastPromptDate'), lastPromptDate) | ||
| ;(mockSettings.update as sinon.SinonStub).resolves(true) | ||
|
|
||
| const result = await handleTelemetryOptIn(mockContext, mockSettings) | ||
|
|
||
| assert.strictEqual(result, false) | ||
| assert.ok((mockSettings.update as sinon.SinonStub).calledWith('enabled', false)) | ||
| assert.strictEqual(globalState.get(commandKey('telemetry.lastPromptDate')), lastPromptDate) | ||
| assert.strictEqual(globalState.get(commandKey('telemetry.unpersistedResponse')), undefined) | ||
| }) | ||
|
|
||
| it('should clear all state if setting save fails', async function () { | ||
| globalState.set(commandKey('telemetry.unpersistedResponse'), 'Yes, Allow') | ||
| globalState.set(commandKey('telemetry.hasResponded'), true) | ||
| globalState.set(commandKey('telemetry.lastPromptDate'), Date.now()) | ||
| ;(mockSettings.update as sinon.SinonStub).resolves(false) | ||
|
|
||
| const result = await handleTelemetryOptIn(mockContext, mockSettings) | ||
|
|
||
| assert.strictEqual(result, true) | ||
| assert.strictEqual(globalState.get(commandKey('telemetry.unpersistedResponse')), undefined) | ||
| assert.strictEqual(globalState.get(commandKey('telemetry.hasResponded')), undefined) | ||
| assert.strictEqual(globalState.get(commandKey('telemetry.lastPromptDate')), undefined) | ||
| }) | ||
| }) | ||
| }) |
4 changes: 4 additions & 0 deletions
4
packages/toolkit/.changes/next-release/Bug Fix-6113ced5-5e07-4662-a641-db4588ddf8de.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "type": "Bug Fix", | ||
| "description": "CloudFormation: Handle telemetry setting in upgrade path case where setting is not registered" | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.