Improved metrics for updating application (#5607)

This commit is contained in:
Janne Savolainen authored and GitHub committed 2022-06-16 09:05:00 -04:00
1 parent 7b0521f3b2
commit 5c049ecca0
15 files changed
+373 -32

No files matched your search

@@ -0,0 +1,225 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import electronUpdaterIsActiveInjectable from "../../main/electron-app/features/electron-updater-is-active.injectable";
import publishIsConfiguredInjectable from "../../main/application-update/publish-is-configured.injectable";
import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest";
import type { CheckForPlatformUpdates } from "../../main/application-update/check-for-platform-updates/check-for-platform-updates.injectable";
import checkForPlatformUpdatesInjectable from "../../main/application-update/check-for-platform-updates/check-for-platform-updates.injectable";
import appEventBusInjectable from "../../common/app-event-bus/app-event-bus.injectable";
import type { DiContainer } from "@ogre-tools/injectable";
import processCheckingForUpdatesInjectable from "../../main/application-update/check-for-updates/process-checking-for-updates.injectable";
import type { DownloadPlatformUpdate } from "../../main/application-update/download-platform-update/download-platform-update.injectable";
import downloadPlatformUpdateInjectable from "../../main/application-update/download-platform-update/download-platform-update.injectable";
import quitAndInstallUpdateInjectable from "../../main/application-update/quit-and-install-update.injectable";
import appVersionInjectable from "../../common/get-configuration-file-model/app-version/app-version.injectable";
import periodicalCheckForUpdatesInjectable from "../../main/application-update/periodical-check-for-updates/periodical-check-for-updates.injectable";
describe("analytics for installing update", () => {
let applicationBuilder: ApplicationBuilder;
let checkForPlatformUpdatesMock: AsyncFnMock<CheckForPlatformUpdates>;
let downloadPlatformUpdateMock: AsyncFnMock<DownloadPlatformUpdate>;
let analyticsListenerMock: jest.Mock;
let mainDi: DiContainer;
beforeEach(async () => {
jest.useFakeTimers();
global.Date.now = () => new Date("2015-10-21T07:28:00Z").getTime();
applicationBuilder = getApplicationBuilder();
analyticsListenerMock = jest.fn();
applicationBuilder.beforeApplicationStart(({ mainDi }) => {
mainDi.override(appVersionInjectable, () => "42.0.0");
checkForPlatformUpdatesMock = asyncFn();
mainDi.override(
checkForPlatformUpdatesInjectable,
() => checkForPlatformUpdatesMock,
);
downloadPlatformUpdateMock = asyncFn();
mainDi.override(downloadPlatformUpdateInjectable, () => downloadPlatformUpdateMock);
mainDi.override(electronUpdaterIsActiveInjectable, () => true);
mainDi.override(publishIsConfiguredInjectable, () => true);
const eventBus = mainDi.inject(appEventBusInjectable);
eventBus.addListener(analyticsListenerMock);
});
mainDi = applicationBuilder.dis.mainDi;
});
describe("given application is started and checking updates periodically", () => {
beforeEach(async () => {
mainDi.unoverride(periodicalCheckForUpdatesInjectable);
mainDi.permitSideEffects(periodicalCheckForUpdatesInjectable);
await applicationBuilder.render();
});
it("sends event to analytics for being checked periodically", () => {
expect(analyticsListenerMock).toHaveBeenCalledWith({
name: "app",
action: "checking-for-updates",
params: {
currentDateTime: "2015-10-21T07:28:00Z",
source: "periodic",
},
});
});
it("when enough time passes to check for updates again, sends event to analytics for being checked periodically", () => {
analyticsListenerMock.mockClear();
jest.advanceTimersByTime(1000 * 60 * 60 * 2);
expect(analyticsListenerMock).toHaveBeenCalledWith({
name: "app",
action: "checking-for-updates",
params: {
currentDateTime: "2015-10-21T07:28:00Z",
source: "periodic",
},
});
});
});
describe("when application is started", () => {
beforeEach(async () => {
analyticsListenerMock.mockClear();
await applicationBuilder.render();
});
it("sends event to analytics about the current version", () => {
expect(analyticsListenerMock).toHaveBeenCalledWith({
name: "app",
action: "current-version",
params: {
version: "42.0.0",
currentDateTime: "2015-10-21T07:28:00Z",
},
});
});
it("when checking for updates using tray, sends event to analytics for being checked from tray", async () => {
analyticsListenerMock.mockClear();
applicationBuilder.tray.click("check-for-updates");
expect(analyticsListenerMock.mock.calls).toEqual([
[
{
name: "app",
action: "checking-for-updates",
params: {
currentDateTime: "2015-10-21T07:28:00Z",
source: "tray",
},
},
],
]);
});
it("when checking for updates using application menu, sends event to analytics for being checked from application menu", async () => {
analyticsListenerMock.mockClear();
applicationBuilder.applicationMenu.click("root.check-for-updates");
expect(analyticsListenerMock.mock.calls).toEqual([
[
{
name: "app",
action: "checking-for-updates",
params: {
currentDateTime: "2015-10-21T07:28:00Z",
source: "application-menu",
},
},
],
]);
});
describe("given checking for updates, when check for updates resolves with new update being available", () => {
beforeEach(async () => {
const processCheckingForUpdates = mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates("irrelevant");
analyticsListenerMock.mockClear();
await checkForPlatformUpdatesMock.resolve({
updateWasDiscovered: true,
version: "43.0.0",
});
});
it("sends event to analytics about new update being available", () => {
expect(analyticsListenerMock.mock.calls).toEqual([
[
{
name: "app",
action: "update-was-discovered",
params: {
version: "43.0.0",
currentDateTime: "2015-10-21T07:28:00Z",
},
},
],
]);
});
describe("given update is downloaded", () => {
beforeEach(async () => {
analyticsListenerMock.mockClear();
await downloadPlatformUpdateMock.resolve({ downloadWasSuccessful: true });
});
it("does not send event to analytics about update downloaded being successful", () => {
expect(analyticsListenerMock).not.toHaveBeenCalled();
});
it("when installing the update, sends event to analytics about installing the update", () => {
const quitAndInstallUpdate = mainDi.inject(quitAndInstallUpdateInjectable);
quitAndInstallUpdate();
expect(analyticsListenerMock.mock.calls).toEqual([
[
{
name: "app",
action: "start-installing-update",
params: {
version: "43.0.0",
currentDateTime: "2015-10-21T07:28:00Z",
updateChannel: "latest",
},
},
],
]);
});
});
});
});
});
@@ -22,8 +22,6 @@ describe("downgrading version update", () => {
let mainDi: DiContainer;
beforeEach(() => {
jest.useFakeTimers();
applicationBuilder = getApplicationBuilder();
applicationBuilder.beforeApplicationStart(({ mainDi }) => {
@@ -79,7 +77,7 @@ describe("downgrading version update", () => {
const processCheckingForUpdates = mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates();
processCheckingForUpdates("irrelevant");
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(expect.any(Object), { allowDowngrade: downgradeIsAllowed });
});
@@ -4,7 +4,7 @@
*/
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import quitAndInstallUpdateInjectable from "../../main/electron-app/features/quit-and-install-update.injectable";
import quitAndInstallUpdateInjectable from "../../main/application-update/quit-and-install-update.injectable";
import type { RenderResult } from "@testing-library/react";
import electronUpdaterIsActiveInjectable from "../../main/electron-app/features/electron-updater-is-active.injectable";
import publishIsConfiguredInjectable from "../../main/application-update/publish-is-configured.injectable";
@@ -67,7 +67,7 @@ describe("installing update", () => {
describe("when started", () => {
let rendered: RenderResult;
let processCheckingForUpdates: () => Promise<void>;
let processCheckingForUpdates: (source: string) => Promise<void>;
beforeEach(async () => {
rendered = await applicationBuilder.render();
@@ -83,7 +83,7 @@ describe("installing update", () => {
let processCheckingForUpdatesPromise: Promise<void>;
beforeEach(async () => {
processCheckingForUpdatesPromise = processCheckingForUpdates();
processCheckingForUpdatesPromise = processCheckingForUpdates("irrelevant");
});
it("checks for updates", () => {
@@ -4,7 +4,7 @@
*/
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import quitAndInstallUpdateInjectable from "../../main/electron-app/features/quit-and-install-update.injectable";
import quitAndInstallUpdateInjectable from "../../main/application-update/quit-and-install-update.injectable";
import type { RenderResult } from "@testing-library/react";
import electronUpdaterIsActiveInjectable from "../../main/electron-app/features/electron-updater-is-active.injectable";
import publishIsConfiguredInjectable from "../../main/application-update/publish-is-configured.injectable";
@@ -72,7 +72,7 @@ describe("selection of update stability", () => {
describe("when started", () => {
let rendered: RenderResult;
let processCheckingForUpdates: () => Promise<void>;
let processCheckingForUpdates: (source: string) => Promise<void>;
beforeEach(async () => {
rendered = await applicationBuilder.render();
@@ -97,7 +97,7 @@ describe("selection of update stability", () => {
selectedUpdateChannel.setValue(updateChannels.alpha.id);
processCheckingForUpdates();
processCheckingForUpdates("irrelevant");
});
it('checks updates from update channel "alpha"', () => {
@@ -191,7 +191,7 @@ describe("selection of update stability", () => {
describe("when checking for updates", () => {
beforeEach(() => {
processCheckingForUpdates();
processCheckingForUpdates("irrelevant");
});
describe('when update from "beta" channel is discovered', () => {
@@ -241,7 +241,7 @@ describe("selection of update stability", () => {
const processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates();
processCheckingForUpdates("irrelevant");
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(updateChannels.beta, expect.any(Object));
});
@@ -259,7 +259,7 @@ describe("selection of update stability", () => {
const processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates();
processCheckingForUpdates("irrelevant");
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(updateChannels.latest, expect.any(Object));
});
@@ -273,7 +273,7 @@ describe("selection of update stability", () => {
const processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates();
processCheckingForUpdates("irrelevant");
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(
updateChannels.latest,
@@ -290,7 +290,7 @@ describe("selection of update stability", () => {
const processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates();
processCheckingForUpdates("irrelevant");
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(updateChannels.alpha, expect.any(Object));
});
@@ -304,7 +304,7 @@ describe("selection of update stability", () => {
const processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates();
processCheckingForUpdates("irrelevant");
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(updateChannels.beta, expect.any(Object));
});
@@ -324,7 +324,7 @@ describe("selection of update stability", () => {
const processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates();
processCheckingForUpdates("irrelevant");
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(updateChannels.beta, expect.any(Object));
});