From 0b48f482a9b257d491f2e40e244d8893867ff8c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Suwi=C5=84ski?= Date: Fri, 17 May 2024 08:04:38 +0200 Subject: [PATCH] cover react-admin undefined meta param --- src/hydra/dataProvider.test.ts | 1 + src/hydra/dataProvider.ts | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hydra/dataProvider.test.ts b/src/hydra/dataProvider.test.ts index 287e5d75..d081010a 100644 --- a/src/hydra/dataProvider.test.ts +++ b/src/hydra/dataProvider.test.ts @@ -333,6 +333,7 @@ describe('Transform a React Admin request to an Hydra request', () => { previousData: { id: '/entrypoint/resource/1', }, + meta: undefined, }); const url = mockFetchHydra.mock.calls?.[0]?.[0] ?? new URL('https://foo'); expect(url).toBeInstanceOf(URL); diff --git a/src/hydra/dataProvider.ts b/src/hydra/dataProvider.ts index a721b534..1d09f69e 100644 --- a/src/hydra/dataProvider.ts +++ b/src/hydra/dataProvider.ts @@ -351,10 +351,10 @@ function dataProvider( } }); let extraInformation: { hasFileField?: boolean } = {}; - if ('meta' in params) { + if (typeof params.meta === 'object') { extraInformation = params.meta; } - const updateHttpMethod = extraInformation?.hasFileField ? 'POST' : 'PUT'; + const updateHttpMethod = extraInformation.hasFileField ? 'POST' : 'PUT'; switch (type) { case CREATE: