diff --git a/x-pack/legacy/plugins/uptime/public/lib/helper/observability_integration/__tests__/get_infra_href.test.ts b/x-pack/legacy/plugins/uptime/public/lib/helper/observability_integration/__tests__/get_infra_href.test.ts index 2848b884f17ded..c2360c321da8fd 100644 --- a/x-pack/legacy/plugins/uptime/public/lib/helper/observability_integration/__tests__/get_infra_href.test.ts +++ b/x-pack/legacy/plugins/uptime/public/lib/helper/observability_integration/__tests__/get_infra_href.test.ts @@ -147,6 +147,11 @@ describe('getInfraHref', () => { expect(getInfraKubernetesHref(summary, '')).toBeUndefined(); }); + it('getInfraKubernetesHref returns undefined when checks are null', () => { + summary.state.checks![0]!.kubernetes!.pod!.uid = null; + expect(getInfraKubernetesHref(summary, '')).toBeUndefined(); + }); + it('getInfraIpHref creates a link for valid parameters', () => { const result = getInfraIpHref(summary, 'bar'); expect(result).toMatchSnapshot(); @@ -161,6 +166,11 @@ describe('getInfraHref', () => { expect(getInfraIpHref(summary, 'foo')).toBeUndefined(); }); + it('getInfraIpHref returns undefined when ip is null', () => { + summary.state.checks![0].monitor.ip = null; + expect(getInfraIpHref(summary, 'foo')).toBeUndefined(); + }); + it('getInfraIpHref returns a url for ors between multiple ips', () => { summary.state.checks = [ { diff --git a/x-pack/legacy/plugins/uptime/public/lib/helper/observability_integration/__tests__/get_logging_href.test.ts b/x-pack/legacy/plugins/uptime/public/lib/helper/observability_integration/__tests__/get_logging_href.test.ts index 1a0276b3d4424d..1117fa14299621 100644 --- a/x-pack/legacy/plugins/uptime/public/lib/helper/observability_integration/__tests__/get_logging_href.test.ts +++ b/x-pack/legacy/plugins/uptime/public/lib/helper/observability_integration/__tests__/get_logging_href.test.ts @@ -82,13 +82,28 @@ describe('getLoggingHref', () => { expect(getLoggingContainerHref(summary, '')).toBeUndefined(); }); + it('returns undefined if necessary container is null', () => { + summary.state.checks![0].container!.id = null; + expect(getLoggingContainerHref(summary, '')).toBeUndefined(); + }); + it('returns undefined if necessary pod is not present', () => { delete summary.state.checks; expect(getLoggingKubernetesHref(summary, '')).toBeUndefined(); }); + it('returns undefined if necessary pod is null', () => { + summary.state.checks![0].kubernetes!.pod!.uid = null; + expect(getLoggingKubernetesHref(summary, '')).toBeUndefined(); + }); + it('returns undefined ip href if ip is not present', () => { delete summary.state.checks; expect(getLoggingIpHref(summary, '')).toBeUndefined(); }); + + it('returns undefined ip href if ip is null', () => { + summary.state.checks![0].monitor.ip = null; + expect(getLoggingIpHref(summary, '')).toBeUndefined(); + }); }); diff --git a/x-pack/legacy/plugins/uptime/public/lib/helper/observability_integration/get_infra_href.ts b/x-pack/legacy/plugins/uptime/public/lib/helper/observability_integration/get_infra_href.ts index 04b1fa3228cb65..12b51bbad00746 100644 --- a/x-pack/legacy/plugins/uptime/public/lib/helper/observability_integration/get_infra_href.ts +++ b/x-pack/legacy/plugins/uptime/public/lib/helper/observability_integration/get_infra_href.ts @@ -13,8 +13,8 @@ export const getInfraContainerHref = ( basePath: string ): string | undefined => { const getHref = (value: string | string[] | undefined) => { - if (value === undefined) { - return value; + if (!value) { + return undefined; } const ret = !Array.isArray(value) ? value : value[0]; return addBasePath(basePath, `/app/infra#/link-to/container-detail/${encodeURIComponent(ret)}`); @@ -27,8 +27,8 @@ export const getInfraKubernetesHref = ( basePath: string ): string | undefined => { const getHref = (value: string | string[] | undefined) => { - if (value === undefined) { - return value; + if (!value) { + return undefined; } const ret = !Array.isArray(value) ? value : value[0]; return addBasePath(basePath, `/app/infra#/link-to/pod-detail/${encodeURIComponent(ret)}`); @@ -39,8 +39,8 @@ export const getInfraKubernetesHref = ( export const getInfraIpHref = (summary: MonitorSummary, basePath: string) => { const getHref = (value: string | string[] | undefined) => { - if (value === undefined) { - return value; + if (!value) { + return undefined; } if (!Array.isArray(value)) { const expression = encodeURIComponent(`host.ip : ${value}`); diff --git a/x-pack/legacy/plugins/uptime/public/lib/helper/observability_integration/get_logging_href.ts b/x-pack/legacy/plugins/uptime/public/lib/helper/observability_integration/get_logging_href.ts index 5073e99e30dc3f..b2235231028fca 100644 --- a/x-pack/legacy/plugins/uptime/public/lib/helper/observability_integration/get_logging_href.ts +++ b/x-pack/legacy/plugins/uptime/public/lib/helper/observability_integration/get_logging_href.ts @@ -13,8 +13,8 @@ export const getLoggingContainerHref = ( basePath: string ): string | undefined => { const getHref = (value: string | string[] | undefined) => { - if (value === undefined) { - return value; + if (!value) { + return undefined; } const ret = !Array.isArray(value) ? value : value[0]; return addBasePath( @@ -27,8 +27,8 @@ export const getLoggingContainerHref = ( export const getLoggingKubernetesHref = (summary: MonitorSummary, basePath: string) => { const getHref = (value: string | string[] | undefined) => { - if (value === undefined) { - return value; + if (!value) { + return undefined; } const ret = !Array.isArray(value) ? value : value[0]; return addBasePath( @@ -41,8 +41,8 @@ export const getLoggingKubernetesHref = (summary: MonitorSummary, basePath: stri export const getLoggingIpHref = (summary: MonitorSummary, basePath: string) => { const getHref = (value: string | string[] | undefined) => { - if (value === undefined) { - return value; + if (!value) { + return undefined; } const ret = !Array.isArray(value) ? value : value[0]; return addBasePath(