From 761981749f04022605197268f41f49da050cca4a Mon Sep 17 00:00:00 2001 From: StiefelJackal Date: Tue, 13 Jan 2026 17:05:32 -0500 Subject: [PATCH] fix(serialize): add true as an accepted value for bool --- .../internal/serializeProperties.test.ts | 54 ++++++++++--------- src/utils/internal/serializeProperties.ts | 6 ++- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/utils/internal/serializeProperties.test.ts b/src/utils/internal/serializeProperties.test.ts index 71652b6..6930b6b 100644 --- a/src/utils/internal/serializeProperties.test.ts +++ b/src/utils/internal/serializeProperties.test.ts @@ -114,28 +114,34 @@ describe("Util: serializeProperties", () => { }); }); - it("can be instructed to map values of certain keys to booleans", () => { - // ARRANGE - const originalObject = { - UserName: "xelnia", - HardcoreMode: "0", - Metadata: { - IsCoolGuy: "1", - }, - }; - - // ACT - const sanitizedObject = serializeProperties(originalObject, { - shouldMapToBooleans: ["HardcoreMode", "IsCoolGuy"], - }); - - // ASSERT - expect(sanitizedObject).toEqual({ - userName: "xelnia", - hardcoreMode: false, - metadata: { - isCoolGuy: true, - }, - }); - }); + it.each([ + { hardcoreMode: "0", isCoolGuy: "1" }, + { hardcoreMode: false, isCoolGuy: true }, + ])( + "can be instructed to map values of certain keys to booleans such as the value '$hardcoreMode' and '$isCoolGuy'", + ({ hardcoreMode, isCoolGuy }) => { + // ARRANGE + const originalObject = { + UserName: "xelnia", + HardcoreMode: hardcoreMode, + Metadata: { + IsCoolGuy: isCoolGuy, + }, + }; + + // ACT + const sanitizedObject = serializeProperties(originalObject, { + shouldMapToBooleans: ["HardcoreMode", "IsCoolGuy"], + }); + + // ASSERT + expect(sanitizedObject).toEqual({ + userName: "xelnia", + hardcoreMode: false, + metadata: { + isCoolGuy: true, + }, + }); + } + ); }); diff --git a/src/utils/internal/serializeProperties.ts b/src/utils/internal/serializeProperties.ts index 80120a5..0955a70 100644 --- a/src/utils/internal/serializeProperties.ts +++ b/src/utils/internal/serializeProperties.ts @@ -33,7 +33,11 @@ export const serializeProperties = ( if (originalValue === null) { sanitizedValue = null; } else { - sanitizedValue = String(originalValue) === "1" ? true : false; + const originalValueAsString = String(originalValue); + sanitizedValue = + originalValueAsString === "1" || originalValueAsString === "true" + ? true + : false; } }