File tree Expand file tree Collapse file tree
src/components/ga4/EventBuilder/ValidateEvent/schemas Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -43,4 +43,31 @@ describe("customSchema", () => {
4343
4444 expect ( validator . isValid ( validInput ) ) . toEqual ( false )
4545 } )
46+
47+ test ( "allows session_id to exceed 100 characters" , ( ) => {
48+ const longString = "a" . repeat ( 101 )
49+ const validInput = { session_id : longString }
50+
51+ let validator = new Validator ( customSchema )
52+
53+ expect ( validator . isValid ( validInput ) ) . toEqual ( true )
54+ } )
55+
56+ test ( "allows session_number to exceed 100 characters" , ( ) => {
57+ const longString = "a" . repeat ( 101 )
58+ const validInput = { session_number : longString }
59+
60+ let validator = new Validator ( customSchema )
61+
62+ expect ( validator . isValid ( validInput ) ) . toEqual ( true )
63+ } )
64+
65+ test ( "does not allow other properties to exceed 100 characters" , ( ) => {
66+ const longString = "a" . repeat ( 101 )
67+ const invalidInput = { other_param : longString }
68+
69+ let validator = new Validator ( customSchema )
70+
71+ expect ( validator . isValid ( invalidInput ) ) . toEqual ( false )
72+ } )
4673} )
Original file line number Diff line number Diff line change @@ -14,7 +14,8 @@ export const customSchema = {
1414 "required" : [ ] ,
1515 "maxProperties" : 25 ,
1616 "patternProperties" : {
17- "." : {
17+ "^(session_id|session_number)$" : { } ,
18+ "^(?!(session_id|session_number)$).*$" : {
1819 "maxLength" : 100
1920 }
2021 } ,
Original file line number Diff line number Diff line change 1+ import "jest"
2+ import { Validator } from "../validator"
3+ import { buildEvents } from "./schemaBuilder"
4+
5+ describe ( "schemaBuilder" , ( ) => {
6+ const schema = {
7+ allOf : buildEvents ( ) ,
8+ }
9+
10+ const longString = "a" . repeat ( 101 )
11+
12+ it ( "allows session_id to exceed 100 characters for recommended events" , ( ) => {
13+ const validator = new Validator ( schema )
14+ const event = {
15+ name : "login" ,
16+ params : {
17+ session_id : longString ,
18+ } ,
19+ }
20+ expect ( validator . isValid ( event ) ) . toBe ( true )
21+ } )
22+
23+ it ( "allows session_number to exceed 100 characters for recommended events" , ( ) => {
24+ const validator = new Validator ( schema )
25+ const event = {
26+ name : "login" ,
27+ params : {
28+ session_number : longString ,
29+ } ,
30+ }
31+ expect ( validator . isValid ( event ) ) . toBe ( true )
32+ } )
33+
34+ it ( "does not allow other properties to exceed 100 characters for recommended events" , ( ) => {
35+ const validator = new Validator ( schema )
36+ const event = {
37+ name : "login" ,
38+ params : {
39+ method : longString ,
40+ } ,
41+ }
42+ expect ( validator . isValid ( event ) ) . toBe ( false )
43+ } )
44+
45+ it ( "validates a correct payload" , ( ) => {
46+ const validator = new Validator ( schema )
47+ const event = {
48+ name : "login" ,
49+ params : {
50+ method : "google" ,
51+ } ,
52+ }
53+ expect ( validator . isValid ( event ) ) . toBe ( true )
54+ } )
55+ } )
Original file line number Diff line number Diff line change @@ -39,7 +39,8 @@ export const buildEvents = () => {
3939 40
4040 } ,
4141 "patternProperties" : {
42- "." : {
42+ "^(session_id|session_number)$" : { } ,
43+ "^(?!(session_id|session_number)$).*$" : {
4344 "maxLength" : 100
4445 }
4546 }
You can’t perform that action at this time.
0 commit comments