Skip to content
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

fix: move to next condition if parsing fails #2

Merged
merged 1 commit into from
Mar 18, 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
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"dependencies": {
"@dazn/kopytko-framework": "^3.0.0",
"@dazn/kopytko-utils": "^2.6.0",
"compare-versions-roku": "^1.0.0",
"compare-versions-roku": "^1.0.1",
"murmurhash-roku": "^1.0.0"
},
"devDependencies": {
Expand Down
8 changes: 7 additions & 1 deletion src/components/libs/featurevisor/FeaturevisorConditions.brs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ function featurevisorAllConditionsAreMatched(condition as Object, context as Obj
return conditions.count() = filtered.count()
end if

if (conditions.doesExist("attribute")) then return m._conditionIsMatched(conditions, context)
if (conditions.doesExist("attribute"))
try
return m._conditionIsMatched(conditions, context)
catch _error
return false
end try
end if

if (conditions.doesExist("and") AND getType(conditions["and"]) = "roArray")
filtered = m._arrayUtils.filter(conditions["and"], function (item as Object, context as Object) as Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,52 @@ function TestSuite__FeaturevisorInstance() as Object
]
end function)

it("should not fail because of improperly formatted sem version", function (_ts as Object) as Object
' Given
datafile = {
schemaVersion: "1",
revision: "1.0",
features: [
{
key: "test",
bucketBy: "userId",
traffic: [
{ key: "0", segments: ["desktop", "version_gt5"], percentage: 100000 },
{ key: "1", segments: "mobile", percentage: 100000 },
{ key: "2", segments: "*", percentage: 0 },
],
},
],
attributes: [],
segments: [
{
key: "desktop",
conditions: FormatJson([{ attribute: "deviceType", operator: "equals", value: "desktop" }]),
},
{
key: "mobile",
conditions: FormatJson([{ attribute: "deviceType", operator: "equals", value: "mobile" }]),
},
{
key: "version_gt5",
conditions: FormatJson([{ attribute: "version", operator: "semverGreaterThan", value: "5.0" }]),
},
],
}

' When
initialize({ datafile: datafile })

' Then
return [
expect(isEnabled("test", { deviceType: "desktop", version: "1.2.3" })).toBeFalse(),
expect(isEnabled("test", { deviceType: "desktop", version: "5.5.0" })).toBeTrue(),
expect(isEnabled("test", { deviceType: "mobile", version: "1.2.3" })).toBeTrue(),
expect(isEnabled("test", { deviceType: "mobile", version: "7.0.A101.99gbm.lg" })).toBeTrue(),
expect(isEnabled("test", { deviceType: "tablet", version: "5.5.A101.99gbm.lg" })).toBeFalse(),
]
end function)

return ts
end function

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function TestSuite__FeaturevisorSegments() as Object
{ key: "germanMobileUsers", segments: [{ "and": ["mobileUsers", "germany"] }] },
{ key: "germanNonMobileUsers", segments: [{ "and": ["germany", { "not": ["mobileUsers"] }] }] },
{ key: "notVersion5.5", segments: [{ "not": ["version_5.5"] }] },
{ key: "improperSemver", segments: [{ "and": ["mobileUsers", { "not": ["version_5.5"] }] }] },
]
end sub)

Expand Down Expand Up @@ -292,5 +293,26 @@ function TestSuite__FeaturevisorSegments() as Object
]
end function)

it("should omit segment with improperly formatted sem version", function (_ts as Object) as Object
' Given
group = m.__arrayUtils.find(m.__groups, { key: "improperSemver" })

' Then
return [
expect(featurevisorAllGroupSegmentsAreMatched(group.segments, {
deviceType: "mobile",
version: "asd",
}, m.__datafileReader)).toBeTrue(),
expect(featurevisorAllGroupSegmentsAreMatched(group.segments, {
deviceType: "mobile",
version: "5.5.A101.99gbm.lg",
}, m.__datafileReader)).toBeTrue(),
expect(featurevisorAllGroupSegmentsAreMatched(group.segments, {
deviceType: "unknown",
version: "5.5.A101.99gbm.lg",
}, m.__datafileReader)).toBeFalse(),
]
end function)

return ts
end function