Skip to content

fix: wrong negation under allGroupSegmentsAreMatched for 'not' operator #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2024
Merged
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
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(
Copy link
Member

@fahad19 fahad19 Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"),
]
)
)
}

}