mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add unit tests for neglected scenario
Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> Co-authored-by: Gabriel <gaccettola@mirantis.com>
This commit is contained in:
parent
f3ecdddcb5
commit
d47de73555
@ -45,6 +45,19 @@ describe("emit-telemetry-from-specific-function-calls", () => {
|
|||||||
di.override(emitEventInjectable, () => emitEventMock);
|
di.override(emitEventInjectable, () => emitEventMock);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("given injectable that is not a function, when injected, does so", () => {
|
||||||
|
const nonFunctionInjectable = getInjectable({
|
||||||
|
id: "some-non-function-injectable",
|
||||||
|
instantiate: () => "some-non-function-instance",
|
||||||
|
});
|
||||||
|
|
||||||
|
di.register(nonFunctionInjectable);
|
||||||
|
|
||||||
|
const instance = di.inject(nonFunctionInjectable);
|
||||||
|
|
||||||
|
expect(instance).toBe("some-non-function-instance");
|
||||||
|
});
|
||||||
|
|
||||||
describe("given instances of white-listed and non-white-listed functions", () => {
|
describe("given instances of white-listed and non-white-listed functions", () => {
|
||||||
let whiteListedFunctionMock: jest.Mock;
|
let whiteListedFunctionMock: jest.Mock;
|
||||||
let nonWhiteListedFunctionMock: jest.Mock;
|
let nonWhiteListedFunctionMock: jest.Mock;
|
||||||
@ -55,7 +68,7 @@ describe("emit-telemetry-from-specific-function-calls", () => {
|
|||||||
let logErrorMock: jest.Mock;
|
let logErrorMock: jest.Mock;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
whiteListedFunctionMock = jest.fn();
|
whiteListedFunctionMock = jest.fn(() => "some-result");
|
||||||
nonWhiteListedFunctionMock = jest.fn();
|
nonWhiteListedFunctionMock = jest.fn();
|
||||||
logErrorMock = jest.fn();
|
logErrorMock = jest.fn();
|
||||||
|
|
||||||
@ -84,7 +97,7 @@ describe("emit-telemetry-from-specific-function-calls", () => {
|
|||||||
whiteListedInjectable,
|
whiteListedInjectable,
|
||||||
whiteListedInjectableWithArgument,
|
whiteListedInjectableWithArgument,
|
||||||
whiteListedInjectableWithBadConfig,
|
whiteListedInjectableWithBadConfig,
|
||||||
nonWhiteListedInjectable,
|
nonWhiteListedInjectable
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -93,11 +106,11 @@ describe("emit-telemetry-from-specific-function-calls", () => {
|
|||||||
whiteListedFunction = di.inject(whiteListedInjectable);
|
whiteListedFunction = di.inject(whiteListedInjectable);
|
||||||
|
|
||||||
whiteListedFunctionWithArgument = di.inject(
|
whiteListedFunctionWithArgument = di.inject(
|
||||||
whiteListedInjectableWithArgument,
|
whiteListedInjectableWithArgument
|
||||||
);
|
);
|
||||||
|
|
||||||
whiteListedFunctionWithFaultyConfig = di.inject(
|
whiteListedFunctionWithFaultyConfig = di.inject(
|
||||||
whiteListedInjectableWithBadConfig,
|
whiteListedInjectableWithBadConfig
|
||||||
);
|
);
|
||||||
|
|
||||||
nonWhiteListedFunction = di.inject(nonWhiteListedInjectable);
|
nonWhiteListedFunction = di.inject(nonWhiteListedInjectable);
|
||||||
@ -112,8 +125,10 @@ describe("emit-telemetry-from-specific-function-calls", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("when a normal white-listed function is called with arguments", () => {
|
describe("when a normal white-listed function is called with arguments", () => {
|
||||||
|
let actualResult: string;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
whiteListedFunction("some-arg", "some-other-arg");
|
actualResult = whiteListedFunction("some-arg", "some-other-arg");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("telemetry is emitted in event bus without the arguments", () => {
|
it("telemetry is emitted in event bus without the arguments", () => {
|
||||||
@ -123,6 +138,10 @@ describe("emit-telemetry-from-specific-function-calls", () => {
|
|||||||
name: "some-white-listed-function",
|
name: "some-white-listed-function",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("the result of the function call is intact", () => {
|
||||||
|
expect(actualResult).toBe('some-result');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when a white-listed function with a white-listed argument is called with arguments", () => {
|
describe("when a white-listed function with a white-listed argument is called with arguments", () => {
|
||||||
@ -165,14 +184,19 @@ describe("emit-telemetry-from-specific-function-calls", () => {
|
|||||||
action: "telemetry-from-business-action",
|
action: "telemetry-from-business-action",
|
||||||
destination: "auto-capture",
|
destination: "auto-capture",
|
||||||
name: "some-white-listed-function-with-bad-config",
|
name: "some-white-listed-function-with-bad-config",
|
||||||
params: { error: "Tried to produce params for telemetry, but getParams() threw an error" },
|
params: {
|
||||||
|
error:
|
||||||
|
"Tried to produce params for telemetry, but getParams() threw an error",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("logs error", () => {
|
it("logs error", () => {
|
||||||
expect(logErrorMock).toHaveBeenCalledWith(
|
expect(logErrorMock).toHaveBeenCalledWith(
|
||||||
'Tried to produce params for telemetry of "some-white-listed-function-with-bad-config", but getParams() threw an error',
|
'Tried to produce params for telemetry of "some-white-listed-function-with-bad-config", but getParams() threw an error',
|
||||||
expect.objectContaining({ message: "some-error-from-bad-configuration" }),
|
expect.objectContaining({
|
||||||
|
message: "some-error-from-bad-configuration",
|
||||||
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -188,7 +212,7 @@ describe("emit-telemetry-from-specific-function-calls", () => {
|
|||||||
|
|
||||||
whiteListedFunctionWithArgument(
|
whiteListedFunctionWithArgument(
|
||||||
"irrelevant-argument",
|
"irrelevant-argument",
|
||||||
someObservable,
|
someObservable
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user