Skip to content

Commit

Permalink
fix: Missing operator in and notIn for string attribute and value…
Browse files Browse the repository at this point in the history
… s condition (#56)
  • Loading branch information
polok authored Nov 10, 2023
1 parent 5e19a20 commit 891910f
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Sources/FeaturevisorSDK/Conditions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ public func conditionIsMatched(condition: PlainCondition, context: Context) -> B
return false
}

// string, [strings]
case (.string(let valueInAttribute), .array(let valuesInCondition)):
switch op {
case .in:
return valuesInCondition.contains(valueInAttribute)
case .notIn:
return !valuesInCondition.contains(valueInAttribute)
default:
return false
}

// date, string
case (.date(let valueInAttributes), .string(let valueInCondition)):
switch op {
Expand Down
64 changes: 64 additions & 0 deletions Tests/FeaturevisorSDKTests/ConditionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,70 @@ class ConditionsTests: XCTestCase {
XCTAssertTrue(conditionIsMatched(condition: condition, context: context))
}

func testStringInArrayShouldReturnTrue() {
//Given
let condition = PlainCondition(
attribute: "text",
operator: .in,
value: .array(["test-1", "test-2"])
)
var context = Context()

//When
context["text"] = .string("test-1")

//Then
XCTAssertTrue(conditionIsMatched(condition: condition, context: context))
}

func testStringInArrayShouldReturnFalse() {
//Given
let condition = PlainCondition(
attribute: "text",
operator: .in,
value: .array(["test-1", "test-2"])
)
var context = Context()

//When
context["text"] = .string("test-3")

//Then
XCTAssertFalse(conditionIsMatched(condition: condition, context: context))
}

func testStringNotInArrayShouldReturnTrue() {
//Given
let condition = PlainCondition(
attribute: "text",
operator: .notIn,
value: .array(["test-1", "test-2"])
)
var context = Context()

//When
context["text"] = .string("test-3")

//Then
XCTAssertTrue(conditionIsMatched(condition: condition, context: context))
}

func testStringNotInArrayShouldReturnFalse() {
//Given
let condition = PlainCondition(
attribute: "text",
operator: .notIn,
value: .array(["test-1", "test-2"])
)
var context = Context()

//When
context["text"] = .string("test-2")

//Then
XCTAssertFalse(conditionIsMatched(condition: condition, context: context))
}

func testDateBefore() {

//Given
Expand Down

0 comments on commit 891910f

Please sign in to comment.