@@ -359,8 +359,12 @@ func (s *CmabServiceTestSuite) TestGetDecisionWithCache() {
359359 // Setup cache key
360360 cacheKey := s .cmabService .getCacheKey (s .testUserID , s .testRuleID )
361361
362- // Calculate attributes hash using murmur3 as in your implementation
363- attributesJSON , _ := s .cmabService .getAttributesJSON (s .testAttributes )
362+ // Calculate attributes hash using the ID-keyed filtered attributes (matching service behavior)
363+ filteredByID := map [string ]interface {}{
364+ "attr1" : 30 ,
365+ "attr2" : "San Francisco" ,
366+ }
367+ attributesJSON , _ := s .cmabService .getAttributesJSON (filteredByID )
364368 hasher := murmur3 .SeedNew32 (1 )
365369 hasher .Write ([]byte (attributesJSON ))
366370 attributesHash := strconv .FormatUint (uint64 (hasher .Sum32 ()), 10 )
@@ -624,11 +628,11 @@ func (s *CmabServiceTestSuite) TestFilterAttributes() {
624628 // Call filterAttributes directly
625629 filteredAttrs := s .cmabService .filterAttributes (s .mockConfig , userContext , s .testRuleID )
626630
627- // Verify only the configured attributes are included
631+ // Verify only the configured attributes are included, keyed by attribute ID
628632 s .Equal (2 , len (filteredAttrs ))
629- s .Equal (30 , filteredAttrs ["age " ])
630- s .Equal ("San Francisco" , filteredAttrs ["location " ])
631- s .NotContains (filteredAttrs , "extra_key " )
633+ s .Equal (30 , filteredAttrs ["attr1 " ])
634+ s .Equal ("San Francisco" , filteredAttrs ["attr2 " ])
635+ s .NotContains (filteredAttrs , "attr3 " )
632636}
633637
634638func (s * CmabServiceTestSuite ) TestOnlyFilteredAttributesPassedToClient () {
@@ -663,10 +667,10 @@ func (s *CmabServiceTestSuite) TestOnlyFilteredAttributesPassedToClient() {
663667 },
664668 }
665669
666- // Expected filtered attributes
670+ // Expected filtered attributes keyed by attribute ID
667671 expectedFilteredAttrs := map [string ]interface {}{
668- "age" : 30 ,
669- "location " : "San Francisco" ,
672+ "attr1" : 30 ,
673+ "attr2 " : "San Francisco" ,
670674 }
671675
672676 // Setup cache key
@@ -678,14 +682,13 @@ func (s *CmabServiceTestSuite) TestOnlyFilteredAttributesPassedToClient() {
678682 // Setup mock API response with attribute verification
679683 expectedVariationID := "variant-1"
680684 s .mockClient .On ("FetchDecision" , s .testRuleID , s .testUserID , mock .MatchedBy (func (attrs map [string ]interface {}) bool {
681- // Verify only the filtered attributes are passed
682685 if len (attrs ) != 2 {
683686 return false
684687 }
685- if attrs ["age " ] != 30 {
688+ if attrs ["attr1 " ] != 30 {
686689 return false
687690 }
688- if attrs ["location " ] != "San Francisco" {
691+ if attrs ["attr2 " ] != "San Francisco" {
689692 return false
690693 }
691694 if _ , exists := attrs ["extra_key" ]; exists {
0 commit comments