Skip to content

Commit

Permalink
fix: wrong negation under allGroupSegmentsAreMatched for 'not' operator
Browse files Browse the repository at this point in the history
  • Loading branch information
polok committed Feb 22, 2024
1 parent 6e6b411 commit a4651c4
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/FeaturevisorSDK/Instance+Segments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ extension FeaturevisorInstance {
}

case .not(let notGroupSegment):
return !notGroupSegment.not.allSatisfy { groupSegment in
allGroupSegmentsAreMatched(
return notGroupSegment.not.allSatisfy { groupSegment in
!allGroupSegmentsAreMatched(
groupSegments: groupSegment,
context: context,
datafileReader: datafileReader
Expand Down
114 changes: 114 additions & 0 deletions Tests/FeaturevisorSDKTests/InstanceTests+Segments.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import Foundation
import XCTest

@testable import FeaturevisorSDK
@testable import FeaturevisorTypes

extension FeaturevisorInstanceTests {

func testShouldMatchWithMultipleConditionsInsideNOT() {

// GIVEN
var options: InstanceOptions = .default
options.datafile = DatafileContent(
schemaVersion: "1",
revision: "1.0",
attributes: [
.init(key: "userId", type: "string", capture: true),
.init(key: "country", type: "string"),
.init(key: "device_os", type: "string"),
],
segments: [
.init(
key: "CountryDE",
conditions: .plain(
.init(attribute: "country", operator: .equals, value: .string("de"))
)
),
.init(
key: "CountryAT",
conditions: .plain(
.init(attribute: "country", operator: .equals, value: .string("at"))
)
),
.init(
key: "CountryCH",
conditions: .plain(
.init(attribute: "country", operator: .equals, value: .string("ch"))
)
),
.init(
key: "OsIOS",
conditions: .plain(
.init(
attribute: "device_os",
operator: .in,
value: .array(["iOS", "iPadOS"])
)
)
),
],

features: [
.init(
key: "feature_test_key",
bucketBy: .single("userId"),
variablesSchema: [],
traffic: [
.init(
key: "1",
segments: .multiple([
.and(
.init(and: [
.plain("OsIOS"),
.not(
.init(not: [
.plain("CountryAT"),
.plain("CountryDE"),
.plain("CountryCH"),
])
),
])
)
]),
percentage: 100000,
allocation: [],
variables: [:]
),
.init(
key: "2",
segments: .plain("*"),
percentage: 0,
allocation: []
),
]
)
]
)

let sdk = try! createInstance(options: options)

// WHEN
// THEN
XCTAssertFalse(
sdk.isEnabled(
featureKey: "feature_test_key",
context: [
"device_os": AttributeValue.string("iOS"),
"country": AttributeValue.string("de"),
]
)
)

XCTAssertTrue(
sdk.isEnabled(
featureKey: "feature_test_key",
context: [
"device_os": AttributeValue.string("iOS"),
"country": AttributeValue.string("pl"),
]
)
)
}

}

0 comments on commit a4651c4

Please sign in to comment.