Skip to content

Commit

Permalink
Apply changes introduced by internal RFC-3
Browse files Browse the repository at this point in the history
  • Loading branch information
amorimjuliana authored Sep 23, 2020
1 parent 9124a2a commit 9e5361c
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 9 deletions.
52 changes: 52 additions & 0 deletions src/schema/userSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,32 @@ export const userProfileSchema = new ObjectType({
new StringType({
maxLength: 100,
}),
new ArrayType({
maxItems: 10,
items: new UnionType(
new BooleanType(),
new NullType(),
new NumberType(),
new StringType({
maxLength: 100,
}),
),
}),
new ObjectType({
propertyNames: new StringType({
maxLength: 50,
format: 'identifier',
}),
maxProperties: 10,
additionalProperties: new UnionType(
new BooleanType(),
new NullType(),
new NumberType(),
new StringType({
maxLength: 100,
}),
),
}),
),
}),
new ObjectType({
Expand All @@ -133,6 +159,32 @@ export const userProfileSchema = new ObjectType({
new StringType({
maxLength: 100,
}),
new ArrayType({
maxItems: 10,
items: new UnionType(
new BooleanType(),
new NullType(),
new NumberType(),
new StringType({
maxLength: 100,
}),
),
}),
new ObjectType({
propertyNames: new StringType({
maxLength: 50,
format: 'identifier',
}),
maxProperties: 10,
additionalProperties: new UnionType(
new BooleanType(),
new NullType(),
new NumberType(),
new StringType({
maxLength: 100,
}),
),
}),
),
}),
),
Expand Down
5 changes: 4 additions & 1 deletion src/trackingEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ export interface UserProfileChanged extends BaseEvent {
type Primitive = null | string | number | boolean;
type PrimitiveMap = {[member: string]: Primitive};
type PrimitiveArray = Primitive[];
type TwoLevelMap = {[member: string]: Primitive | PrimitiveMap | PrimitiveArray};
type TwoLevelArray = PrimitiveArray | PrimitiveMap[] | PrimitiveArray[];
type CustomAttribute = Primitive | TwoLevelMap | TwoLevelArray;

type UserProfile = {
firstName?: string,
Expand All @@ -163,7 +166,7 @@ type UserProfile = {
interests?: string[],
activities?: string[],
custom?: {
[member: string]: Primitive | PrimitiveMap | PrimitiveArray,
[member: string]: CustomAttribute,
},
};

Expand Down
32 changes: 32 additions & 0 deletions test/facade/trackerFacade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,38 @@ describe('A tracker facade', () => {
},
},
],
[
{
type: 'userSignedUp',
userId: '1ed2fd65-a027-4f3a-a35f-c6dd97537392',
profile: {
custom: {
nestedArrayInArray: [[1, 1.2, null, true, false, '', 'x'.repeat(100)]],
nestedMapInArray: [{
integer: 1,
number: 1.2,
null: null,
true: true,
false: false,
emptyString: '',
longString: 'x'.repeat(100),
}],
nestedArrayInMap: {foo: [1, 1.2, null, true, false, '', 'x'.repeat(100)]},
nestedMapInMap: {
foo: {
integer: 1,
number: 1.2,
null: null,
true: true,
false: false,
emptyString: '',
longString: 'x'.repeat(100),
},
},
},
},
},
],
[
{
type: 'testGroupAssigned',
Expand Down
20 changes: 12 additions & 8 deletions test/schemas/userSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ describe('The user profile schema', () => {
},
},
}],
[{custom: {nestedArrayInArray: [[1, 2, 3]]}}],
[{custom: {nestedArrayInMap: {foo: [1, 2, 3]}}}],
[{custom: {nestedMapInArray: [{foo: 'bar'}]}}],
[{custom: {nestedMapInMap: {foo: {bar: 'baz'}}}}],
])('should allow %s', (value: object) => {
function validate(): void {
userProfileSchema.validate(value);
Expand Down Expand Up @@ -212,24 +216,24 @@ describe('The user profile schema', () => {
'Invalid identifier format at path \'/custom/map/@foo\'.',
],
[
{custom: {nestedArrayInArray: [[1, 2, 3]]}},
{custom: {nestedArrayInNestedArray: [[[1, 2, 3]]]}},
'Expected value of type boolean, null, number or string at path '
+ '\'/custom/nestedArrayInArray/0\', actual array.',
+ '\'/custom/nestedArrayInNestedArray/0/0\', actual array.',
],
[
{custom: {nestedArrayInMap: {foo: [1, 2, 3]}}},
{custom: {nestedArrayInNestedMap: {foo: {bar: [1, 2, 3]}}}},
'Expected value of type boolean, null, number or string at path '
+ '\'/custom/nestedArrayInMap/foo\', actual array.',
+ '\'/custom/nestedArrayInNestedMap/foo/bar\', actual array.',
],
[
{custom: {nestedMapInArray: [{foo: 'bar'}]}},
{custom: {nestedMapInNestedArray: [[{foo: 'bar'}]]}},
'Expected value of type boolean, null, number or string at path '
+ '\'/custom/nestedMapInArray/0\', actual Object.',
+ '\'/custom/nestedMapInNestedArray/0/0\', actual Object.',
],
[
{custom: {nestedMapInMap: {foo: {bar: 'baz'}}}},
{custom: {nestedMapInNestedMap: {foo: {bar: {baz: 1}}}}},
'Expected value of type boolean, null, number or string at path '
+ '\'/custom/nestedMapInMap/foo\', actual Object.',
+ '\'/custom/nestedMapInNestedMap/foo/bar\', actual Object.',
],
[
{
Expand Down
44 changes: 44 additions & 0 deletions test/tracker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,28 @@ describe('A tracker', () => {
emptyString: '',
longString: 'x'.repeat(100),
},
nestedArrayInArray: [[1, 1.2, null, true, false, '', 'x'.repeat(100)]],
nestedMapInArray: [{
integer: 1,
number: 1.2,
null: null,
true: true,
false: false,
emptyString: '',
longString: 'x'.repeat(100),
}],
nestedArrayInMap: {foo: [1, 1.2, null, true, false, '', 'x'.repeat(100)]},
nestedMapInMap: {
foo: {
integer: 1,
number: 1.2,
null: null,
true: true,
false: false,
emptyString: '',
longString: 'x'.repeat(100),
},
},
},
},
},
Expand Down Expand Up @@ -1023,6 +1045,28 @@ describe('A tracker', () => {
emptyString: '',
longString: 'x'.repeat(100),
},
nestedArrayInArray: [[1, 1.2, null, true, false, '', 'x'.repeat(100)]],
nestedMapInArray: [{
integer: 1,
number: 1.2,
null: null,
true: true,
false: false,
emptyString: '',
longString: 'x'.repeat(100),
}],
nestedArrayInMap: {foo: [1, 1.2, null, true, false, '', 'x'.repeat(100)]},
nestedMapInMap: {
foo: {
integer: 1,
number: 1.2,
null: null,
true: true,
false: false,
emptyString: '',
longString: 'x'.repeat(100),
},
},
},
},
},
Expand Down

0 comments on commit 9e5361c

Please sign in to comment.