Skip to content
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

Do not opt users out of the insiders program if they have a stable version installed #14091

Merged
merged 3 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/1 Enhancements/14090.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Do not opt users out of the insiders program if they have a stable version installed.
23 changes: 2 additions & 21 deletions src/client/common/insidersBuild/insidersExtensionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class InsidersExtensionService implements IExtensionSingleActivationServi
const channel = this.extensionChannelService.getChannel();
const isDefault = this.extensionChannelService.isChannelUsingDefaultConfiguration;

const alreadyHandled = await this.handleEdgeCases(channel, isDefault);
const alreadyHandled = await this.handleEdgeCases(isDefault);
if (!alreadyHandled) {
this.handleChannel(channel).ignoreErrors();
}
Expand All @@ -84,14 +84,12 @@ export class InsidersExtensionService implements IExtensionSingleActivationServi
* Choose what to do in miscellaneous situations
* @returns `true` if install channel is handled in these miscellaneous cases, `false` if install channel needs further handling
*/
public async handleEdgeCases(installChannel: ExtensionChannels, isDefault: boolean): Promise<boolean> {
public async handleEdgeCases(isDefault: boolean): Promise<boolean> {
// When running UI Tests we might want to disable these prompts.
if (process.env.UITEST_DISABLE_INSIDERS) {
return true;
} else if (await this.promptToInstallInsidersIfApplicable(isDefault)) {
return true;
} else if (await this.setInsidersChannelToOffIfApplicable(installChannel)) {
return true;
} else {
return false;
}
Expand All @@ -115,21 +113,4 @@ export class InsidersExtensionService implements IExtensionSingleActivationServi
await this.insidersPrompt.promptToInstallInsiders();
return true;
}

/**
* When install channel is not in sync with what is installed, resolve discrepency by setting channel to "off"
* @returns `true` if channel is set to off, `false` otherwise
*/
private async setInsidersChannelToOffIfApplicable(installChannel: ExtensionChannels): Promise<boolean> {
if (installChannel === 'off') {
return false;
}
if (this.appEnvironment.extensionChannel !== 'stable') {
return false;
}

// Install channel is set to "weekly" or "daily" but stable version of extension is installed. Switch channel to "off" to use the installed version
await this.extensionChannelService.updateChannel('off');
return true;
}
}
137 changes: 24 additions & 113 deletions src/test/common/insidersBuild/insidersExtensionService.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ suite('Insiders Extension Service - Activation', () => {
verify(extensionChannelService.isChannelUsingDefaultConfiguration).once();
assert.ok(registerCommandsAndHandlers.calledOnce);
assert.ok(handleEdgeCases.calledOnce);
assert.ok(handleEdgeCases.calledWith('daily', false));
assert.ok(handleEdgeCases.calledWith(false));
assert.ok(handleChannel.notCalled);
});

Expand All @@ -176,7 +176,7 @@ suite('Insiders Extension Service - Activation', () => {
verify(extensionChannelService.isChannelUsingDefaultConfiguration).once();
assert.ok(registerCommandsAndHandlers.calledOnce);
assert.ok(handleEdgeCases.calledOnce);
assert.ok(handleEdgeCases.calledWith('daily', false));
assert.ok(handleEdgeCases.calledWith(false));
assert.ok(handleChannel.calledOnce);
});

Expand Down Expand Up @@ -210,7 +210,7 @@ suite('Insiders Extension Service - Activation', () => {
assert.ok(registerCommandsAndHandlers.calledOnce);
assert.ok(handleEdgeCases.calledOnce);
assert.ok(handleChannel.calledOnce);
assert.ok(handleEdgeCases.calledWith('daily', false));
assert.ok(handleEdgeCases.calledWith(false));
});
});

Expand Down Expand Up @@ -252,6 +252,10 @@ suite('Insiders Extension Service - Function handleEdgeCases()', () => {
.verifiable(TypeMoq.Times.atLeast(0));
}

setup(() => {
setupCommon();
});

function verifyAll() {
// the most important ones:
insidersPrompt.verifyAll();
Expand All @@ -265,23 +269,16 @@ suite('Insiders Extension Service - Function handleEdgeCases()', () => {

type TestInfo = {
vscodeChannel?: Channel;
extensionChannel?: Channel;
installChannel: ExtensionChannels;
installChannel?: ExtensionChannels;
isChannelUsingDefaultConfiguration?: boolean;
hasUserBeenNotified?: boolean;
};

function setState(info: TestInfo, checkPromptEnroll: boolean, checkDisable: boolean) {
function setState(info: TestInfo, checkPromptEnroll: boolean) {
if (info.vscodeChannel) {
appEnvironment.setup((e) => e.channel).returns(() => info.vscodeChannel!);
}
if (info.extensionChannel) {
appEnvironment.setup((e) => e.extensionChannel).returns(() => info.extensionChannel!);
}

if (checkDisable) {
extensionChannelService.setup((ec) => ec.updateChannel('off')).returns(() => Promise.resolve());
}
if (info.hasUserBeenNotified !== undefined) {
when(hasUserBeenNotifiedState.value).thenReturn(info.hasUserBeenNotified!);
}
Expand All @@ -290,125 +287,42 @@ suite('Insiders Extension Service - Function handleEdgeCases()', () => {
}
}

suite('Case II - Verify Insiders Install Prompt is displayed when conditions are met', async () => {
const testsForHandleEdgeCaseII: TestInfo[] = [
test(`Insiders Install Prompt is displayed when vscode channel = 'insiders', user has not been notified to install insiders, isChannelUsingDefaultConfiguration = true`, async () => {
setState(
{
installChannel: 'daily',
// prompt to enroll
vscodeChannel: 'insiders',
hasUserBeenNotified: false,
isChannelUsingDefaultConfiguration: true
},
{
installChannel: 'off',
// prompt to enroll
vscodeChannel: 'insiders',
hasUserBeenNotified: false,
isChannelUsingDefaultConfiguration: true
}
];

setup(() => {
setupCommon();
});

testsForHandleEdgeCaseII.forEach((testParams) => {
const testName = `Insiders Install Prompt is displayed when vscode channel = '${
testParams.vscodeChannel
}', extension channel = '${testParams.extensionChannel}', install channel = '${
testParams.installChannel
}', ${
!testParams.hasUserBeenNotified
? 'user has not been notified to install insiders'
: 'user has already been notified to install insiders'
}, isChannelUsingDefaultConfiguration = ${testParams.isChannelUsingDefaultConfiguration}`;
test(testName, async () => {
setState(testParams, true, false);

await insidersExtensionService.handleEdgeCases(
testParams.installChannel,
testParams.isChannelUsingDefaultConfiguration!
);

verifyAll();
verify(hasUserBeenNotifiedState.value).once();
});
});
});

suite('Case III - Verify Insiders channel is set to off when conditions are met', async () => {
const testsForHandleEdgeCaseIII: TestInfo[] = [
{
installChannel: 'daily',
// skip enroll
vscodeChannel: 'stable',
// disable
// with installChannel from above
extensionChannel: 'stable'
},
{
installChannel: 'weekly',
// skip enroll
vscodeChannel: 'stable',
// disable
// with installChannel from above
extensionChannel: 'stable'
}
];

setup(() => {
setupCommon();
});
true
);

testsForHandleEdgeCaseIII.forEach((testParams) => {
const testName = `Insiders channel is set to off when vscode channel = '${
testParams.vscodeChannel
}', extension channel = '${testParams.extensionChannel}', install channel = '${
testParams.installChannel
}', ${
!testParams.hasUserBeenNotified
? 'user has not been notified to install insiders'
: 'user has already been notified to install insiders'
}, isChannelUsingDefaultConfiguration = ${testParams.isChannelUsingDefaultConfiguration}`;
test(testName, async () => {
setState(testParams, false, true);
await insidersExtensionService.handleEdgeCases(true);

await insidersExtensionService.handleEdgeCases(
testParams.installChannel,
false // isDefault
);

verifyAll();
verify(hasUserBeenNotifiedState.value).never();
});
});
verifyAll();
verify(hasUserBeenNotifiedState.value).once();
});

suite('Case IV - Verify no operation is performed if none of the case conditions are met', async () => {
const testsForHandleEdgeCaseIV: TestInfo[] = [
suite('Verify no operation is performed if none of the case conditions are met', async () => {
const testsForHandleEdgeCases: TestInfo[] = [
{
installChannel: 'daily',
// skip enroll
vscodeChannel: 'insiders',
hasUserBeenNotified: true,
// skip disable
extensionChannel: 'insiders'
hasUserBeenNotified: true
},
{
installChannel: 'daily',
// skip enroll
vscodeChannel: 'insiders',
hasUserBeenNotified: false,
isChannelUsingDefaultConfiguration: false,
// skip disable
extensionChannel: 'insiders'
isChannelUsingDefaultConfiguration: false
},
{
installChannel: 'daily',
// skip enroll
vscodeChannel: 'stable',
// skip disable
extensionChannel: 'insiders'
vscodeChannel: 'stable'
},
{
installChannel: 'off',
Expand Down Expand Up @@ -436,21 +350,18 @@ suite('Insiders Extension Service - Function handleEdgeCases()', () => {
setupCommon();
});

testsForHandleEdgeCaseIV.forEach((testParams) => {
testsForHandleEdgeCases.forEach((testParams) => {
const testName = `No operation is performed when vscode channel = '${
testParams.vscodeChannel
}', extension channel = '${testParams.extensionChannel}', install channel = '${
testParams.installChannel
}', ${
}', install channel = '${testParams.installChannel}', ${
!testParams.hasUserBeenNotified
? 'user has not been notified to install insiders'
: 'user has already been notified to install insiders'
}, isChannelUsingDefaultConfiguration = ${testParams.isChannelUsingDefaultConfiguration}`;
test(testName, async () => {
setState(testParams, false, false);
setState(testParams, false);

await insidersExtensionService.handleEdgeCases(
testParams.installChannel,
testParams.isChannelUsingDefaultConfiguration || testParams.installChannel === 'off'
);

Expand Down