From 7d8135049e445ed5b3d0a832469320af1bdb3cc9 Mon Sep 17 00:00:00 2001 From: PhilippeOberti Date: Mon, 19 Sep 2022 11:46:16 -0500 Subject: [PATCH] [TIP] Code clean --- .../public/modules/indicators/lib/field_value.test.ts | 8 ++++++++ .../public/modules/indicators/lib/field_value.ts | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/threat_intelligence/public/modules/indicators/lib/field_value.test.ts b/x-pack/plugins/threat_intelligence/public/modules/indicators/lib/field_value.test.ts index bd6a36aaf2d5..22e5dafc7394 100644 --- a/x-pack/plugins/threat_intelligence/public/modules/indicators/lib/field_value.test.ts +++ b/x-pack/plugins/threat_intelligence/public/modules/indicators/lib/field_value.test.ts @@ -53,6 +53,14 @@ describe('field_value', () => { expect(result).toEqual(false); }); + it('should return false for empty string value', () => { + const mockField = 'abc'; + const mockValue = ''; + + const result = fieldAndValueValid(mockField, mockValue); + expect(result).toEqual(false); + }); + it(`should return false for ${EMPTY_VALUE} value`, () => { const mockField = 'abc'; const mockValue = EMPTY_VALUE; diff --git a/x-pack/plugins/threat_intelligence/public/modules/indicators/lib/field_value.ts b/x-pack/plugins/threat_intelligence/public/modules/indicators/lib/field_value.ts index 958b33e6a634..6bdfc415fe01 100644 --- a/x-pack/plugins/threat_intelligence/public/modules/indicators/lib/field_value.ts +++ b/x-pack/plugins/threat_intelligence/public/modules/indicators/lib/field_value.ts @@ -38,4 +38,4 @@ export const getIndicatorFieldAndValue = ( * @returns true if correct, false if not */ export const fieldAndValueValid = (field: string | null, value: string | null): boolean => - value != null && value !== '' && value !== EMPTY_VALUE && field != null && field !== ''; + !!value && value !== EMPTY_VALUE && !!field;