1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Rename a helper for less ambiguity

Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
Iku-turso 2022-06-22 14:25:06 +03:00
parent b627448155
commit 0e9997c384
14 changed files with 112 additions and 112 deletions

View File

@ -6,25 +6,25 @@ import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest";
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import type { ResolveProxy } from "../../common/utils/resolve-proxy/resolve-proxy-injection-token";
import { resolveProxyInjectionToken } from "../../common/utils/resolve-proxy/resolve-proxy-injection-token";
import resolveProxyFromElectronInjectable from "../../main/utils/resolve-proxy/resolve-proxy-from-electron.injectable";
import type { ResolveSystemProxy } from "../../common/utils/resolve-system-proxy/resolve-system-proxy-injection-token";
import { resolveSystemProxyInjectionToken } from "../../common/utils/resolve-system-proxy/resolve-system-proxy-injection-token";
import resolveSystemProxyFromElectronInjectable from "../../main/utils/resolve-system-proxy/resolve-system-proxy-from-electron.injectable";
import { getPromiseStatus } from "../../common/test-utils/get-promise-status";
describe("resolve-proxy", () => {
describe("resolve-system-proxy", () => {
let applicationBuilder: ApplicationBuilder;
let actualPromise: Promise<string>;
let resolveProxyFromElectronMock: AsyncFnMock<ResolveProxy>;
let resolveSystemProxyFromElectronMock: AsyncFnMock<ResolveSystemProxy>;
beforeEach(async () => {
applicationBuilder = getApplicationBuilder();
resolveProxyFromElectronMock = asyncFn();
resolveSystemProxyFromElectronMock = asyncFn();
applicationBuilder.beforeApplicationStart(({ mainDi }) => {
mainDi.override(
resolveProxyFromElectronInjectable,
() => resolveProxyFromElectronMock,
resolveSystemProxyFromElectronInjectable,
() => resolveSystemProxyFromElectronMock,
);
});
@ -33,15 +33,15 @@ describe("resolve-proxy", () => {
describe("given in main, when called with URL", () => {
beforeEach(async () => {
const resolveProxyInMain = applicationBuilder.dis.mainDi.inject(
resolveProxyInjectionToken,
const resolveSystemProxyInMain = applicationBuilder.dis.mainDi.inject(
resolveSystemProxyInjectionToken,
);
actualPromise = resolveProxyInMain("some-url");
actualPromise = resolveSystemProxyInMain("some-url");
});
it("calls for proxy of the URL from Electron", () => {
expect(resolveProxyFromElectronMock).toHaveBeenCalledWith("some-url");
expect(resolveSystemProxyFromElectronMock).toHaveBeenCalledWith("some-url");
});
it("does not resolve yet", async () => {
@ -51,7 +51,7 @@ describe("resolve-proxy", () => {
});
it("when the call for proxy resolves, resolves with the proxy", async () => {
resolveProxyFromElectronMock.resolve("some-proxy");
resolveSystemProxyFromElectronMock.resolve("some-proxy");
expect(await actualPromise).toBe("some-proxy");
});
@ -59,15 +59,15 @@ describe("resolve-proxy", () => {
describe("given in renderer, when called with URL", () => {
beforeEach(async () => {
const resolveProxyInRenderer = applicationBuilder.dis.rendererDi.inject(
resolveProxyInjectionToken,
const resolveSystemProxyInRenderer = applicationBuilder.dis.rendererDi.inject(
resolveSystemProxyInjectionToken,
);
actualPromise = resolveProxyInRenderer("some-url");
actualPromise = resolveSystemProxyInRenderer("some-url");
});
it("calls for proxy of the URL from Electron", () => {
expect(resolveProxyFromElectronMock).toHaveBeenCalledWith("some-url");
expect(resolveSystemProxyFromElectronMock).toHaveBeenCalledWith("some-url");
});
it("does not resolve yet", async () => {
@ -77,7 +77,7 @@ describe("resolve-proxy", () => {
});
it("when the call for proxy resolves, resolves with the proxy", async () => {
resolveProxyFromElectronMock.resolve("some-proxy");
resolveSystemProxyFromElectronMock.resolve("some-proxy");
expect(await actualPromise).toBe("some-proxy");
});

View File

@ -6,16 +6,16 @@ import { getInjectable } from "@ogre-tools/injectable";
import type { RequestChannel } from "../channel/request-channel-injection-token";
import { requestChannelInjectionToken } from "../channel/request-channel-injection-token";
export type ResolveProxyChannel = RequestChannel<string, string>;
export type ResolveSystemProxyChannel = RequestChannel<string, string>;
const resolveProxyChannelInjectable = getInjectable({
id: "resolve-proxy-channel",
const resolveSystemProxyChannelInjectable = getInjectable({
id: "resolve-system-proxy-channel",
instantiate: (): ResolveProxyChannel => ({
id: "resolve-proxy-channel",
instantiate: (): ResolveSystemProxyChannel => ({
id: "resolve-system-proxy-channel",
}),
injectionToken: requestChannelInjectionToken,
});
export default resolveProxyChannelInjectable;
export default resolveSystemProxyChannelInjectable;

View File

@ -5,8 +5,8 @@
import { getInjectionToken } from "@ogre-tools/injectable";
export type ResolveProxy = (url: string) => Promise<string>;
export type ResolveSystemProxy = (url: string) => Promise<string>;
export const resolveProxyInjectionToken = getInjectionToken<ResolveProxy>({
id: "resolve-proxy",
export const resolveSystemProxyInjectionToken = getInjectionToken<ResolveSystemProxy>({
id: "resolve-system-proxy",
});

View File

@ -4,6 +4,6 @@
*/
import { asLegacyGlobalFunctionForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api";
import { resolveProxyInjectionToken } from "../../common/utils/resolve-proxy/resolve-proxy-injection-token";
import { resolveSystemProxyInjectionToken } from "../../common/utils/resolve-system-proxy/resolve-system-proxy-injection-token";
export const resolveProxy = asLegacyGlobalFunctionForExtensionApi(resolveProxyInjectionToken);
export const resolveSystemProxy = asLegacyGlobalFunctionForExtensionApi(resolveSystemProxyInjectionToken);

View File

@ -99,7 +99,7 @@ import rollbackHelmReleaseInjectable from "./helm/helm-service/rollback-helm-rel
import updateHelmReleaseInjectable from "./helm/helm-service/update-helm-release.injectable";
import waitUntilBundledExtensionsAreLoadedInjectable from "./start-main-application/lens-window/application-window/wait-until-bundled-extensions-are-loaded.injectable";
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
import electronInjectable from "./utils/resolve-proxy/electron.injectable";
import electronInjectable from "./utils/resolve-system-proxy/electron.injectable";
export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {}) {
const {

View File

@ -1,21 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import resolveProxyChannelInjectable from "../../../common/utils/resolve-proxy/resolve-proxy-channel.injectable";
import resolveProxyInjectable from "./resolve-proxy.injectable";
import { requestChannelListenerInjectionToken } from "../../../common/utils/channel/request-channel-listener-injection-token";
const resolveProxyChannelResponderInjectable = getInjectable({
id: "resolve-proxy-channel-responder",
instantiate: (di) => ({
channel: di.inject(resolveProxyChannelInjectable),
handler: di.inject(resolveProxyInjectable),
}),
injectionToken: requestChannelListenerInjectionToken,
});
export default resolveProxyChannelResponderInjectable;

View File

@ -1,21 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { resolveProxyInjectionToken } from "../../../common/utils/resolve-proxy/resolve-proxy-injection-token";
import resolveProxyFromElectronInjectable from "./resolve-proxy-from-electron.injectable";
const resolveProxyInjectable = getInjectable({
id: "resolve-proxy-for-main",
instantiate: (di) => {
const resolveProxyFromElectron = di.inject(resolveProxyFromElectronInjectable);
return (url) => resolveProxyFromElectron(url);
},
injectionToken: resolveProxyInjectionToken,
});
export default resolveProxyInjectable;

View File

@ -0,0 +1,21 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import resolveSystemProxyChannelInjectable from "../../../common/utils/resolve-system-proxy/resolve-system-proxy-channel.injectable";
import resolveSystemProxyInjectable from "./resolve-system-proxy.injectable";
import { requestChannelListenerInjectionToken } from "../../../common/utils/channel/request-channel-listener-injection-token";
const resolveSystemProxyChannelResponderInjectable = getInjectable({
id: "resolve-system-proxy-channel-responder",
instantiate: (di) => ({
channel: di.inject(resolveSystemProxyChannelInjectable),
handler: di.inject(resolveSystemProxyInjectable),
}),
injectionToken: requestChannelListenerInjectionToken,
});
export default resolveSystemProxyChannelResponderInjectable;

View File

@ -6,8 +6,8 @@ import { getInjectable } from "@ogre-tools/injectable";
import electronInjectable from "./electron.injectable";
import withErrorLoggingInjectable from "../../../common/utils/with-error-logging/with-error-logging.injectable";
const resolveProxyFromElectronInjectable = getInjectable({
id: "resolve-proxy-from-electron",
const resolveSystemProxyFromElectronInjectable = getInjectable({
id: "resolve-system-proxy-from-electron",
instantiate: (di) => {
const electron = di.inject(electronInjectable);
@ -29,4 +29,4 @@ const resolveProxyFromElectronInjectable = getInjectable({
},
});
export default resolveProxyFromElectronInjectable;
export default resolveSystemProxyFromElectronInjectable;

View File

@ -4,7 +4,7 @@
*/
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
import resolveProxyFromElectronInjectable from "./resolve-proxy-from-electron.injectable";
import resolveSystemProxyFromElectronInjectable from "./resolve-system-proxy-from-electron.injectable";
import electronInjectable from "./electron.injectable";
import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest";
@ -13,8 +13,8 @@ import { getPromiseStatus } from "../../../common/test-utils/get-promise-status"
import logErrorInjectable from "../../../common/log-error.injectable";
import type { DiContainer } from "@ogre-tools/injectable";
describe("technical: resolve-proxy-from-electron", () => {
let resolveProxyMock: AsyncFnMock<(url: string) => Promise<string>>;
describe("technical: resolve-system-proxy-from-electron", () => {
let resolveSystemProxyMock: AsyncFnMock<(url: string) => Promise<string>>;
let logErrorMock: jest.Mock;
let di: DiContainer;
let actualPromise: Promise<string>;
@ -28,7 +28,7 @@ describe("technical: resolve-proxy-from-electron", () => {
describe("given there are non-destroyed Lens windows, when called with URL", () => {
beforeEach(() => {
resolveProxyMock = asyncFn();
resolveSystemProxyMock = asyncFn();
di.override(
electronInjectable,
@ -49,7 +49,7 @@ describe("technical: resolve-proxy-from-electron", () => {
{
isDestroyed: () => false,
session: { resolveProxy: resolveProxyMock },
session: { resolveProxy: resolveSystemProxyMock },
},
{
@ -66,15 +66,15 @@ describe("technical: resolve-proxy-from-electron", () => {
} as unknown as typeof electron),
);
const resolveProxyFromElectron = di.inject(
resolveProxyFromElectronInjectable,
const resolveSystemProxyFromElectron = di.inject(
resolveSystemProxyFromElectronInjectable,
);
actualPromise = resolveProxyFromElectron("some-url");
actualPromise = resolveSystemProxyFromElectron("some-url");
});
it("calls to resolve proxy from the first window", () => {
expect(resolveProxyMock).toHaveBeenCalledWith("some-url");
expect(resolveSystemProxyMock).toHaveBeenCalledWith("some-url");
});
it("does not resolve yet", async () => {
@ -84,7 +84,7 @@ describe("technical: resolve-proxy-from-electron", () => {
});
it("when call for proxy, resolves with the proxy", async () => {
resolveProxyMock.resolve("some-proxy");
resolveSystemProxyMock.resolve("some-proxy");
expect(await actualPromise).toBe("some-proxy");
});
@ -114,14 +114,14 @@ describe("technical: resolve-proxy-from-electron", () => {
} as unknown as typeof electron),
);
resolveProxyMock = asyncFn();
resolveSystemProxyMock = asyncFn();
const resolveProxyFromElectron = di.inject(
resolveProxyFromElectronInjectable,
const resolveSystemProxyFromElectron = di.inject(
resolveSystemProxyFromElectronInjectable,
);
try {
await resolveProxyFromElectron("some-url");
await resolveSystemProxyFromElectron("some-url");
} catch (e) {
error = e;
}

View File

@ -0,0 +1,21 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { resolveSystemProxyInjectionToken } from "../../../common/utils/resolve-system-proxy/resolve-system-proxy-injection-token";
import resolveSystemProxyFromElectronInjectable from "./resolve-system-proxy-from-electron.injectable";
const resolveSystemProxyInjectable = getInjectable({
id: "resolve-system-proxy-for-main",
instantiate: (di) => {
const resolveSystemProxyFromElectron = di.inject(resolveSystemProxyFromElectronInjectable);
return (url) => resolveSystemProxyFromElectron(url);
},
injectionToken: resolveSystemProxyInjectionToken,
});
export default resolveSystemProxyInjectable;

View File

@ -1,23 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { resolveProxyInjectionToken } from "../../../common/utils/resolve-proxy/resolve-proxy-injection-token";
import requestFromChannelInjectable from "../channel/request-from-channel.injectable";
import resolveProxyChannelInjectable from "../../../common/utils/resolve-proxy/resolve-proxy-channel.injectable";
const resolveProxyInjectable = getInjectable({
id: "resolve-proxy-for-renderer",
instantiate: (di) => {
const requestFromChannel = di.inject(requestFromChannelInjectable);
const resolveProxyChannel = di.inject(resolveProxyChannelInjectable);
return async (url) => requestFromChannel(resolveProxyChannel, url);
},
injectionToken: resolveProxyInjectionToken,
});
export default resolveProxyInjectable;

View File

@ -0,0 +1,23 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { resolveSystemProxyInjectionToken } from "../../../common/utils/resolve-system-proxy/resolve-system-proxy-injection-token";
import requestFromChannelInjectable from "../channel/request-from-channel.injectable";
import resolveSystemProxyChannelInjectable from "../../../common/utils/resolve-system-proxy/resolve-system-proxy-channel.injectable";
const resolveSystemProxyInjectable = getInjectable({
id: "resolve-system-proxy-for-renderer",
instantiate: (di) => {
const requestFromChannel = di.inject(requestFromChannelInjectable);
const resolveSystemProxyChannel = di.inject(resolveSystemProxyChannelInjectable);
return async (url) => requestFromChannel(resolveSystemProxyChannel, url);
},
injectionToken: resolveSystemProxyInjectionToken,
});
export default resolveSystemProxyInjectable;