@@ -207,9 +207,8 @@ describe('given a TestData instance', () => {
207207 expect ( builtFlag . fallthrough ) . toEqual ( { variation : 1 } ) ;
208208 expect ( builtFlag . offVariation ) . toEqual ( 0 ) ;
209209 expect ( builtFlag . variations ) . toEqual ( [ true , false ] ) ;
210- expect ( builtFlag . contextTargets ) . toEqual ( [
211- { contextKind : 'user' , values : [ 'billy' ] , variation : 0 } ,
212- ] ) ;
210+ expect ( builtFlag . contextTargets ) . toEqual ( [ { contextKind : 'user' , values : [ ] , variation : 0 } ] ) ;
211+ expect ( builtFlag . targets ) . toEqual ( [ { values : [ 'billy' ] , variation : 0 } ] ) ;
213212 expect ( builtFlag . rules ) . toEqual ( flagRules ) ;
214213 } ) ;
215214
@@ -249,16 +248,32 @@ describe('given a TestData instance', () => {
249248 it ( 'can set boolean values for a specific user target' , ( ) => {
250249 const flag = td . flag ( 'test-flag' ) . variationForContext ( 'user' , 'potato' , false ) ;
251250 const flag2 = td . flag ( 'test-flag' ) . variationForUser ( 'potato' , true ) ;
252- expect ( flag . build ( 0 ) . contextTargets ) . toEqual ( [
251+ const builtFlag1 = flag . build ( 0 ) ;
252+ const builtFlag2 = flag2 . build ( 0 ) ;
253+ // User targets order by the context targets, but use values from
254+ // the legacy targets.
255+ expect ( builtFlag1 . contextTargets ) . toEqual ( [
253256 {
254257 contextKind : 'user' ,
258+ variation : 1 ,
259+ values : [ ] ,
260+ } ,
261+ ] ) ;
262+ expect ( builtFlag1 . targets ) . toEqual ( [
263+ {
255264 variation : 1 ,
256265 values : [ 'potato' ] ,
257266 } ,
258267 ] ) ;
259- expect ( flag2 . build ( 0 ) . contextTargets ) . toEqual ( [
268+ expect ( builtFlag2 . contextTargets ) . toEqual ( [
260269 {
261270 contextKind : 'user' ,
271+ variation : 0 ,
272+ values : [ ] ,
273+ } ,
274+ ] ) ;
275+ expect ( builtFlag2 . targets ) . toEqual ( [
276+ {
262277 variation : 0 ,
263278 values : [ 'potato' ] ,
264279 } ,
@@ -347,13 +362,32 @@ describe('given a TestData instance', () => {
347362 it ( 'can move a targeted context from one variation to another' , ( ) => {
348363 const flag = td
349364 . flag ( 'test-flag' )
350- . variationForContext ( 'user' , 'ben' , false )
351- . variationForContext ( 'user' , 'ben' , true ) ;
365+ . variationForContext ( 'org' , 'ben' , false )
366+ . variationForContext ( 'org' , 'ben' , true ) ;
367+ // Because there was only one target in the first variation there will be only
368+ // a single variation after that target is removed.
369+ expect ( flag . build ( 1 ) . contextTargets ) . toEqual ( [
370+ {
371+ contextKind : 'org' ,
372+ variation : 0 ,
373+ values : [ 'ben' ] ,
374+ } ,
375+ ] ) ;
376+ } ) ;
377+
378+ it ( 'can move a targeted user from one variation to another' , ( ) => {
379+ const flag = td . flag ( 'test-flag' ) . variationForUser ( 'ben' , false ) . variationForUser ( 'ben' , true ) ;
352380 // Because there was only one target in the first variation there will be only
353381 // a single variation after that target is removed.
354382 expect ( flag . build ( 1 ) . contextTargets ) . toEqual ( [
355383 {
356384 contextKind : 'user' ,
385+ variation : 0 ,
386+ values : [ ] ,
387+ } ,
388+ ] ) ;
389+ expect ( flag . build ( 1 ) . targets ) . toEqual ( [
390+ {
357391 variation : 0 ,
358392 values : [ 'ben' ] ,
359393 } ,
@@ -363,19 +397,51 @@ describe('given a TestData instance', () => {
363397 it ( 'if a targeted context is moved from one variation to another, then other targets remain for that variation' , ( ) => {
364398 const flag = td
365399 . flag ( 'test-flag' )
366- . variationForContext ( 'user' , 'ben' , false )
367- . variationForContext ( 'user' , 'joe' , false )
368- . variationForContext ( 'user' , 'ben' , true ) ;
400+ . variationForUser ( 'ben' , false )
401+ . variationForUser ( 'joe' , false )
402+ . variationForUser ( 'ben' , true ) ;
369403
370404 expect ( flag . build ( 1 ) . contextTargets ) . toEqual ( [
371405 {
372406 contextKind : 'user' ,
373407 variation : 0 ,
374- values : [ 'ben' ] ,
408+ values : [ ] ,
375409 } ,
376410 {
377411 contextKind : 'user' ,
378412 variation : 1 ,
413+ values : [ ] ,
414+ } ,
415+ ] ) ;
416+
417+ expect ( flag . build ( 1 ) . targets ) . toEqual ( [
418+ {
419+ variation : 0 ,
420+ values : [ 'ben' ] ,
421+ } ,
422+ {
423+ variation : 1 ,
424+ values : [ 'joe' ] ,
425+ } ,
426+ ] ) ;
427+ } ) ;
428+
429+ it ( 'if a targeted user is moved from one variation to another, then other targets remain for that variation' , ( ) => {
430+ const flag = td
431+ . flag ( 'test-flag' )
432+ . variationForContext ( 'org' , 'ben' , false )
433+ . variationForContext ( 'org' , 'joe' , false )
434+ . variationForContext ( 'org' , 'ben' , true ) ;
435+
436+ expect ( flag . build ( 1 ) . contextTargets ) . toEqual ( [
437+ {
438+ contextKind : 'org' ,
439+ variation : 0 ,
440+ values : [ 'ben' ] ,
441+ } ,
442+ {
443+ contextKind : 'org' ,
444+ variation : 1 ,
379445 values : [ 'joe' ] ,
380446 } ,
381447 ] ) ;
@@ -393,13 +459,14 @@ describe('given a TestData instance', () => {
393459 {
394460 contextKind : 'user' ,
395461 variation : 1 ,
396- values : [ 'ben' ] ,
462+ values : [ ] ,
397463 } ,
398464 {
399465 contextKind : 'potato' ,
400466 variation : 1 ,
401467 values : [ 'russet' , 'yukon' ] ,
402468 } ,
403469 ] ) ;
470+ expect ( flag . build ( 0 ) . targets ) . toEqual ( [ { variation : 1 , values : [ 'ben' ] } ] ) ;
404471 } ) ;
405472} ) ;
0 commit comments