Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/CMAB/CmabService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class DefaultCmabService: CmabService {
let cmabAttributeIds = cmab.attributeIds
for attributeId in cmabAttributeIds {
if let attribute = config.getAttribute(id: attributeId), let value = userAttributes[attribute.key] {
filteredUserAttributes[attribute.key] = value
filteredUserAttributes[attribute.id] = value
}
}
return filteredUserAttributes
Expand Down
31 changes: 15 additions & 16 deletions Tests/OptimizelyTests-Common/CmabServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fileprivate class MockProjectConfig: ProjectConfig {
attributeIdMap["attr1"] = attribute1
attributeIdMap["attr2"] = attribute2
attributeKeyMap["age"] = attribute1
attributeIdMap["location"] = attribute2
attributeKeyMap["location"] = attribute2
}

}
Expand Down Expand Up @@ -172,7 +172,7 @@ class DefaultCmabServiceTests: XCTestCase {
completion: { _ in
// Check that only the relevant attributes were passed to the client
XCTAssertEqual(self.cmabClient.lastAttributes?.count, 1) // Only 'age' is found in the config
XCTAssertEqual(self.cmabClient.lastAttributes?["age"] as? Int, 25)
XCTAssertEqual(self.cmabClient.lastAttributes?["attr1"] as? Int, 25)
XCTAssertNil(self.cmabClient.lastAttributes?["irrelevant"] ?? nil)

expectation.fulfill()
Expand Down Expand Up @@ -212,10 +212,9 @@ class DefaultCmabServiceTests: XCTestCase {
XCTAssertEqual(decision.variationId, "variation-123")
XCTAssertEqual(self.cmabClient.lastRuleId, "exp-123")
XCTAssertEqual(self.cmabClient.lastUserId, "test-user")
// We expect only the 'age' attribute as that's what's configured in the experiment
XCTAssertEqual(self.cmabClient.lastAttributes?.count, 2)
XCTAssertEqual(self.cmabClient.lastAttributes?["age"] as? Int, 25)
XCTAssertEqual(self.cmabClient.lastAttributes?["location"] as? String, "San Francisco")
XCTAssertEqual(self.cmabClient.lastAttributes?["attr1"] as? Int, 25)
XCTAssertEqual(self.cmabClient.lastAttributes?["attr2"] as? String, "San Francisco")

// Verify it was cached
let cacheKey = "9-test-user-exp-123"
Expand All @@ -233,7 +232,7 @@ class DefaultCmabServiceTests: XCTestCase {

func testCachedDecision() {
// First, put something in the cache
let attributesHash = cmabService.hashAttributes(["age": 25, "location": "San Francisco"])
let attributesHash = cmabService.hashAttributes(["attr1": 25, "attr2": "San Francisco"])
let cacheKey = "9-test-user-exp-123"

let cacheValue = CmabCacheValue(attributesHash: attributesHash,
Expand Down Expand Up @@ -268,7 +267,7 @@ class DefaultCmabServiceTests: XCTestCase {

func testCacheInvalidationWithChangedAttributes() {
// First, put something in the cache
let attributesHash = cmabService.hashAttributes(["age": 25, "location": "San Francisco"])
let attributesHash = cmabService.hashAttributes(["attr1": 25, "attr2": "San Francisco"])
let cacheKey = "9-test-user-exp-123"
let cacheValue = CmabCacheValue(attributesHash: attributesHash,
variationId: "cached-variation",
Expand Down Expand Up @@ -311,7 +310,7 @@ class DefaultCmabServiceTests: XCTestCase {

func testIgnoreCmabCacheOption() {
// First, put something in the cache
let attributesHash = cmabService.hashAttributes(["age": 25, "location": "San Francisco"])
let attributesHash = cmabService.hashAttributes(["attr1": 25, "attr2": "San Francisco"])
let cacheKey = "9-test-user-exp-123"
let cacheValue = CmabCacheValue(attributesHash: attributesHash,
variationId: "cached-variation",
Expand Down Expand Up @@ -345,7 +344,7 @@ class DefaultCmabServiceTests: XCTestCase {

func testResetCmabCacheOption() {
// First, put something in the cache
let attributesHash = cmabService.hashAttributes(["age": 25, "location": "San Francisco"])
let attributesHash = cmabService.hashAttributes(["attr1": 25, "attr2": "San Francisco"])
let cacheKey = "9-test-user-exp-123"
let cacheValue = CmabCacheValue(attributesHash: attributesHash,
variationId: "cached-variation",
Expand Down Expand Up @@ -388,7 +387,7 @@ class DefaultCmabServiceTests: XCTestCase {

func testInvalidateUserCmabCacheOption() {
// First, put something in the cache
let attributesHash = cmabService.hashAttributes(["age": 25, "location": "San Francisco"])
let attributesHash = cmabService.hashAttributes(["attr1": 25, "attr2": "San Francisco"])
let userCacheKey = "9-test-user-exp-123"
let cacheValue = CmabCacheValue(attributesHash: attributesHash,
variationId: "cached-variation",
Expand Down Expand Up @@ -479,8 +478,8 @@ extension DefaultCmabServiceTests {
XCTAssertEqual(self.cmabClient.lastRuleId, "exp-123")
XCTAssertEqual(self.cmabClient.lastUserId, "test-user")
XCTAssertEqual(self.cmabClient.lastAttributes?.count, 2)
XCTAssertEqual(self.cmabClient.lastAttributes?["age"] as? Int, 25)
XCTAssertEqual(self.cmabClient.lastAttributes?["location"] as? String, "San Francisco")
XCTAssertEqual(self.cmabClient.lastAttributes?["attr1"] as? Int, 25)
XCTAssertEqual(self.cmabClient.lastAttributes?["attr2"] as? String, "San Francisco")

// Verify it was cached
let cacheKey = "9-test-user-exp-123"
Expand All @@ -493,7 +492,7 @@ extension DefaultCmabServiceTests {

func testSyncCachedDecision() {
// First, put something in the cache
let attributesHash = cmabService.hashAttributes(["age": 25, "location": "San Francisco"])
let attributesHash = cmabService.hashAttributes(["attr1": 25, "attr2": "San Francisco"])
let cacheKey = "9-test-user-exp-123"
let cacheValue = CmabCacheValue(
attributesHash: attributesHash,
Expand Down Expand Up @@ -546,7 +545,7 @@ extension DefaultCmabServiceTests {

func testSyncIgnoreCmabCacheOption() {
// First, put something in the cache
let attributesHash = cmabService.hashAttributes(["age": 25, "location": "San Francisco"])
let attributesHash = cmabService.hashAttributes(["attr1": 25, "attr2": "San Francisco"])
let cacheKey = "9-test-user-exp-123"
let cacheValue = CmabCacheValue(
attributesHash: attributesHash,
Expand Down Expand Up @@ -576,7 +575,7 @@ extension DefaultCmabServiceTests {

func testSyncResetCmabCacheOption() {
// First, put something in the cache
let attributesHash = cmabService.hashAttributes(["age": 25, "location": "San Francisco"])
let attributesHash = cmabService.hashAttributes(["attr1": 25, "attr2": "San Francisco"])
let cacheKey = "9-test-user-exp-123"
let cacheValue = CmabCacheValue(
attributesHash: attributesHash,
Expand Down Expand Up @@ -616,7 +615,7 @@ extension DefaultCmabServiceTests {

func testSyncInvalidateUserCmabCacheOption() {
// First, put something in the cache
let attributesHash = cmabService.hashAttributes(["age": 25, "location": "San Francisco"])
let attributesHash = cmabService.hashAttributes(["attr1": 25, "attr2": "San Francisco"])
let userCacheKey = "9-test-user-exp-123"
let otherUserCacheKey = "other-user-key"

Expand Down
Loading