Skip to content

Commit 5d9b52d

Browse files
[ISSUE-922] - un-restrict user attribute type definition, add tests...
1 parent 75418da commit 5d9b52d

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

lib/shared_types.tests.ts

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { UserAttributes } from "./shared_types";
2+
import { assert } from "chai";
3+
4+
describe("shared_types", () => {
5+
describe("UserAttributes", () => {
6+
it("allows any attribute to be defined", () => {
7+
const booleanValue: UserAttributes = {
8+
fixed: true,
9+
broken: false
10+
};
11+
const numberValue: UserAttributes = {
12+
first: 1,
13+
last: 999
14+
};
15+
const stringValue: UserAttributes = {
16+
name: "Rick Sanchez",
17+
dimension: "c137"
18+
};
19+
const nullValue: UserAttributes = {
20+
no: null,
21+
empty: null
22+
};
23+
const custom = {
24+
sidekick1: "Morty Smith",
25+
sidekick2: "Summer Smith"
26+
}
27+
const objectValue: UserAttributes = {
28+
custom
29+
};
30+
assert.isBoolean(booleanValue.fixed);
31+
assert.equal(booleanValue.broken, false);
32+
assert.isNumber(numberValue.last)
33+
assert.equal(numberValue.last, 999);
34+
assert.isString(stringValue.name);
35+
assert.equal(stringValue.dimension, "c137");
36+
assert.isNull(nullValue.no);
37+
assert.equal(nullValue.empty, null);
38+
assert.isObject(objectValue.custom);
39+
assert.equal(objectValue.custom.sidekick1, "Morty Smith");
40+
assert.deepEqual(objectValue.custom, custom);
41+
});
42+
});
43+
})

lib/shared_types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ export interface DecisionResponse<T> {
5757
readonly reasons: (string | number)[][];
5858
}
5959

60-
export type UserAttributeValue = string | number | boolean | null;
60+
/** Purposely allow any here. The definition of an attribute should allow any type. **/
61+
export type UserAttributeValue = any;
6162

6263
export type UserAttributes = {
6364
[name: string]: UserAttributeValue;

0 commit comments

Comments
 (0)