@@ -10,9 +10,11 @@ describe('context-transformer', () => {
1010
1111 const user = {
1212 identifier : context [ 'targetingKey' ] ,
13- country : undefined ,
14- custom : { } ,
1513 email : undefined ,
14+ country : undefined ,
15+ custom : {
16+ targetingKey : context [ 'targetingKey' ]
17+ } ,
1618 } ;
1719
1820 expect ( transformContext ( context ) ) . toEqual ( user ) ;
@@ -29,7 +31,11 @@ describe('context-transformer', () => {
2931 identifier : context [ 'targetingKey' ] ,
3032 email : context [ 'email' ] ,
3133 country : context [ 'country' ] ,
32- custom : { } ,
34+ custom : {
35+ targetingKey : context [ 'targetingKey' ] ,
36+ email : context [ 'email' ] ,
37+ country : context [ 'country' ] ,
38+ } ,
3339 } ;
3440
3541 expect ( transformContext ( context ) ) . toEqual ( user ) ;
@@ -44,14 +50,15 @@ describe('context-transformer', () => {
4450 const user = {
4551 identifier : context [ 'targetingKey' ] ,
4652 custom : {
53+ targetingKey : context [ 'targetingKey' ] ,
4754 customString : context [ 'customString' ] ,
4855 } ,
4956 } ;
5057
5158 expect ( transformContext ( context ) ) . toEqual ( user ) ;
5259 } ) ;
5360
54- it ( 'map custom property with number to number ' , ( ) => {
61+ it ( 'map custom property with number' , ( ) => {
5562 const context : EvaluationContext = {
5663 targetingKey : 'test' ,
5764 customNumber : 1 ,
@@ -60,14 +67,15 @@ describe('context-transformer', () => {
6067 const user = {
6168 identifier : context [ 'targetingKey' ] ,
6269 custom : {
63- customNumber : 1 ,
70+ targetingKey : context [ 'targetingKey' ] ,
71+ customNumber : context [ 'customNumber' ] ,
6472 } ,
6573 } ;
6674
6775 expect ( transformContext ( context ) ) . toEqual ( user ) ;
6876 } ) ;
6977
70- it ( 'map custom property with boolean to string ' , ( ) => {
78+ it ( 'map custom property with boolean' , ( ) => {
7179 const context : EvaluationContext = {
7280 targetingKey : 'test' ,
7381 customBoolean : true ,
@@ -76,7 +84,8 @@ describe('context-transformer', () => {
7684 const user = {
7785 identifier : context [ 'targetingKey' ] ,
7886 custom : {
79- customBoolean : 'true' ,
87+ targetingKey : context [ 'targetingKey' ] ,
88+ customBoolean : context [ 'customBoolean' ] ,
8089 } ,
8190 } ;
8291
@@ -95,6 +104,7 @@ describe('context-transformer', () => {
95104 const user = {
96105 identifier : context [ 'targetingKey' ] ,
97106 custom : {
107+ targetingKey : context [ 'targetingKey' ] ,
98108 customObject : JSON . stringify ( context [ 'customObject' ] ) ,
99109 } ,
100110 } ;
@@ -111,7 +121,8 @@ describe('context-transformer', () => {
111121 const user = {
112122 identifier : context [ 'targetingKey' ] ,
113123 custom : {
114- customArray : [ 'one' , 'two' , 'three' ] ,
124+ targetingKey : context [ 'targetingKey' ] ,
125+ customArray : context [ 'customArray' ] ,
115126 } ,
116127 } ;
117128
@@ -127,6 +138,7 @@ describe('context-transformer', () => {
127138 const user = {
128139 identifier : context [ 'targetingKey' ] ,
129140 custom : {
141+ targetingKey : context [ 'targetingKey' ] ,
130142 customArray : JSON . stringify ( context [ 'customArray' ] ) ,
131143 } ,
132144 } ;
@@ -154,11 +166,29 @@ describe('context-transformer', () => {
154166 email : 'email' ,
155167 country : 'country' ,
156168 custom : {
157- customString : 'customString' ,
158- customBoolean : 'true' ,
159- customNumber : 1 ,
160- customObject : '{"prop1":"1","prop2":2}' ,
161- customArray : '[1,"2",false]' ,
169+ targetingKey : context [ 'targetingKey' ] ,
170+ email : context [ 'email' ] ,
171+ country : context [ 'country' ] ,
172+ customString : context [ 'customString' ] ,
173+ customBoolean : context [ 'customBoolean' ] ,
174+ customNumber : context [ 'customNumber' ] ,
175+ customObject : JSON . stringify ( context [ 'customObject' ] ) ,
176+ customArray : JSON . stringify ( context [ 'customArray' ] ) ,
177+ } ,
178+ } ;
179+
180+ expect ( transformContext ( context ) ) . toEqual ( user ) ;
181+ } ) ;
182+
183+ it ( 'map identifier if targetingKey is not present' , ( ) => {
184+ const context : EvaluationContext = {
185+ identifier : 'test' ,
186+ } ;
187+
188+ const user = {
189+ identifier : 'test' ,
190+ custom : {
191+ identifier : context [ 'identifier' ] ,
162192 } ,
163193 } ;
164194
0 commit comments