From fe2d99e471e9cca7a97cb06d1769006eb65dc378 Mon Sep 17 00:00:00 2001 From: Mark David Avery Date: Fri, 6 May 2022 09:04:25 -0700 Subject: [PATCH] fix: cleaned up the tests and added in a lowdash 'hasOwn' alternative Signed-off-by: Mark David Avery --- .../parseEntityTransformParams.test.ts | 50 +++++++++++++++---- .../request/parseEntityTransformParams.ts | 2 +- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/plugins/catalog-backend/src/service/request/parseEntityTransformParams.test.ts b/plugins/catalog-backend/src/service/request/parseEntityTransformParams.test.ts index ae1c8855ea..3dce579ae5 100644 --- a/plugins/catalog-backend/src/service/request/parseEntityTransformParams.test.ts +++ b/plugins/catalog-backend/src/service/request/parseEntityTransformParams.test.ts @@ -132,19 +132,49 @@ describe('parseEntityTransformParams', () => { it('does not return a sub key if an incorrect longer key is requested', () => { entity.spec = { ...entity.spec, + strValue: 'st1', + boolValue: true, + numValue: 4, + arrValue: [4, 5], + nullValue: null, + undefValue: undefined, 'field-with.dot': 'fd1', - plain: true, - numLike: 4, - arrayLike: [4, 5], }; expect( - parseEntityTransformParams({ - fields: - 'kind,spec.field-withdot.other.item,kind.other.other,spec.plain.other,spec.numLike.other,spec.arrayLike.other', - })!(entity), - ).toEqual({ - kind: 'k', - }); + parseEntityTransformParams({ fields: 'kind,spec.strValue.other' })!( + entity, + ), + ).toEqual({ kind: 'k' }); + expect( + parseEntityTransformParams({ fields: 'kind,spec.boolValue.other' })!( + entity, + ), + ).toEqual({ kind: 'k' }); + expect( + parseEntityTransformParams({ fields: 'kind,spec.numValue.other' })!( + entity, + ), + ).toEqual({ kind: 'k' }); + expect( + parseEntityTransformParams({ fields: 'kind,spec.arrValue.other' })!( + entity, + ), + ).toEqual({ kind: 'k' }); + expect( + parseEntityTransformParams({ fields: 'kind,spec.nullValue.other' })!( + entity, + ), + ).toEqual({ kind: 'k' }); + expect( + parseEntityTransformParams({ fields: 'kind,spec.undefValue.other' })!( + entity, + ), + ).toEqual({ kind: 'k' }); + expect( + parseEntityTransformParams({ fields: 'kind,spec.field-with.dot.other' })!( + entity, + ), + ).toEqual({ kind: 'k' }); }); }); diff --git a/plugins/catalog-backend/src/service/request/parseEntityTransformParams.ts b/plugins/catalog-backend/src/service/request/parseEntityTransformParams.ts index 5d11ea84b8..cef6e5ef64 100644 --- a/plugins/catalog-backend/src/service/request/parseEntityTransformParams.ts +++ b/plugins/catalog-backend/src/service/request/parseEntityTransformParams.ts @@ -23,7 +23,7 @@ import { parseStringsParam } from './common'; function getPathArrayAndValue(input: Entity, field: string) { return field.split('.').reduce( ([pathArray, inputSubset], pathPart, index, fieldParts) => { - if (inputSubset.hasOwnProperty(pathPart)) { + if (lodash.hasIn(inputSubset, pathPart)) { return [pathArray.concat(pathPart), inputSubset[pathPart]]; } else if (fieldParts[index + 1] !== undefined) { fieldParts[index + 1] = `${pathPart}.${fieldParts[index + 1]}`;