From 5d9b52d41d3490df8657a05460f6f388eb103bda Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 24 Apr 2024 10:02:03 -0400 Subject: [PATCH] [ISSUE-922] - un-restrict user attribute type definition, add tests... --- lib/shared_types.tests.ts | 43 +++++++++++++++++++++++++++++++++++++++ lib/shared_types.ts | 3 ++- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 lib/shared_types.tests.ts diff --git a/lib/shared_types.tests.ts b/lib/shared_types.tests.ts new file mode 100644 index 000000000..3e0e25865 --- /dev/null +++ b/lib/shared_types.tests.ts @@ -0,0 +1,43 @@ +import { UserAttributes } from "./shared_types"; +import { assert } from "chai"; + +describe("shared_types", () => { + describe("UserAttributes", () => { + it("allows any attribute to be defined", () => { + const booleanValue: UserAttributes = { + fixed: true, + broken: false + }; + const numberValue: UserAttributes = { + first: 1, + last: 999 + }; + const stringValue: UserAttributes = { + name: "Rick Sanchez", + dimension: "c137" + }; + const nullValue: UserAttributes = { + no: null, + empty: null + }; + const custom = { + sidekick1: "Morty Smith", + sidekick2: "Summer Smith" + } + const objectValue: UserAttributes = { + custom + }; + assert.isBoolean(booleanValue.fixed); + assert.equal(booleanValue.broken, false); + assert.isNumber(numberValue.last) + assert.equal(numberValue.last, 999); + assert.isString(stringValue.name); + assert.equal(stringValue.dimension, "c137"); + assert.isNull(nullValue.no); + assert.equal(nullValue.empty, null); + assert.isObject(objectValue.custom); + assert.equal(objectValue.custom.sidekick1, "Morty Smith"); + assert.deepEqual(objectValue.custom, custom); + }); + }); +}) \ No newline at end of file diff --git a/lib/shared_types.ts b/lib/shared_types.ts index 361f293d5..bd5e12805 100644 --- a/lib/shared_types.ts +++ b/lib/shared_types.ts @@ -57,7 +57,8 @@ export interface DecisionResponse { readonly reasons: (string | number)[][]; } -export type UserAttributeValue = string | number | boolean | null; +/** Purposely allow any here. The definition of an attribute should allow any type. **/ +export type UserAttributeValue = any; export type UserAttributes = { [name: string]: UserAttributeValue;