@@ -14,6 +14,7 @@ import {
14
14
validateTestAssignments ,
15
15
} from '../../test/testHelpers' ;
16
16
import { IAssignmentLogger } from '../assignment-logger' ;
17
+ import { AssignmentCache } from '../cache/abstract-assignment-cache' ;
17
18
import {
18
19
IConfigurationWire ,
19
20
IObfuscatedPrecomputedConfigurationResponse ,
@@ -1029,6 +1030,11 @@ describe('EppoClient E2E test', () => {
1029
1030
} ) ;
1030
1031
1031
1032
it ( 'does not update assignment cache when override is applied' , ( ) => {
1033
+ const mockAssignmentCache = td . object < AssignmentCache > ( ) ;
1034
+ td . when ( mockAssignmentCache . has ( td . matchers . anything ( ) ) ) . thenReturn ( false ) ;
1035
+ td . when ( mockAssignmentCache . set ( td . matchers . anything ( ) ) ) . thenReturn ( ) ;
1036
+ client . useCustomAssignmentCache ( mockAssignmentCache ) ;
1037
+
1032
1038
overrideStore . setEntries ( {
1033
1039
[ flagKey ] : {
1034
1040
key : 'override-variation' ,
@@ -1039,17 +1045,17 @@ describe('EppoClient E2E test', () => {
1039
1045
// First call with override
1040
1046
client . getStringAssignment ( flagKey , 'subject-10' , { } , 'default' ) ;
1041
1047
1048
+ // Verify cache was not used at all
1049
+ expect ( td . explain ( mockAssignmentCache . set ) . callCount ) . toBe ( 0 ) ;
1050
+
1042
1051
// Remove override
1043
1052
overrideStore . setEntries ( { } ) ;
1044
1053
1045
- // Second call without override should trigger logging since cache wasn't updated
1054
+ // Second call without override
1046
1055
client . getStringAssignment ( flagKey , 'subject-10' , { } , 'default' ) ;
1047
1056
1048
- expect ( td . explain ( mockLogger . logAssignment ) . callCount ) . toBe ( 1 ) ;
1049
- expect ( td . explain ( mockLogger . logAssignment ) . calls [ 0 ] . args [ 0 ] ) . toMatchObject ( {
1050
- featureFlag : flagKey ,
1051
- subject : 'subject-10' ,
1052
- } ) ;
1057
+ // Now cache should be used
1058
+ expect ( td . explain ( mockAssignmentCache . set ) . callCount ) . toBe ( 1 ) ;
1053
1059
} ) ;
1054
1060
1055
1061
it ( 'uses normal assignment when no override exists for flag' , ( ) => {
@@ -1086,5 +1092,47 @@ describe('EppoClient E2E test', () => {
1086
1092
expect ( result ) . toBe ( variationA . value ) ;
1087
1093
expect ( td . explain ( mockLogger . logAssignment ) . callCount ) . toBe ( 1 ) ;
1088
1094
} ) ;
1095
+
1096
+ it ( 'respects override after initial assignment without override' , ( ) => {
1097
+ // First call without override
1098
+ const initialAssignment = client . getStringAssignment ( flagKey , 'subject-10' , { } , 'default' ) ;
1099
+ expect ( initialAssignment ) . toBe ( variationA . value ) ;
1100
+ expect ( td . explain ( mockLogger . logAssignment ) . callCount ) . toBe ( 1 ) ;
1101
+
1102
+ // Set override and make second call
1103
+ overrideStore . setEntries ( {
1104
+ [ flagKey ] : {
1105
+ key : 'override-variation' ,
1106
+ value : 'override-value' ,
1107
+ } ,
1108
+ } ) ;
1109
+
1110
+ const overriddenAssignment = client . getStringAssignment ( flagKey , 'subject-10' , { } , 'default' ) ;
1111
+ expect ( overriddenAssignment ) . toBe ( 'override-value' ) ;
1112
+ // No additional logging should occur when using override
1113
+ expect ( td . explain ( mockLogger . logAssignment ) . callCount ) . toBe ( 1 ) ;
1114
+ } ) ;
1115
+
1116
+ it ( 'reverts to normal assignment after removing override' , ( ) => {
1117
+ // Set initial override
1118
+ overrideStore . setEntries ( {
1119
+ [ flagKey ] : {
1120
+ key : 'override-variation' ,
1121
+ value : 'override-value' ,
1122
+ } ,
1123
+ } ) ;
1124
+
1125
+ const overriddenAssignment = client . getStringAssignment ( flagKey , 'subject-10' , { } , 'default' ) ;
1126
+ expect ( overriddenAssignment ) . toBe ( 'override-value' ) ;
1127
+ expect ( td . explain ( mockLogger . logAssignment ) . callCount ) . toBe ( 0 ) ;
1128
+
1129
+ // Remove override and make second call
1130
+ overrideStore . setEntries ( { } ) ;
1131
+
1132
+ const normalAssignment = client . getStringAssignment ( flagKey , 'subject-10' , { } , 'default' ) ;
1133
+ expect ( normalAssignment ) . toBe ( variationA . value ) ;
1134
+ // Should log the normal assignment
1135
+ expect ( td . explain ( mockLogger . logAssignment ) . callCount ) . toBe ( 1 ) ;
1136
+ } ) ;
1089
1137
} ) ;
1090
1138
} ) ;
0 commit comments