Skip to content

Commit

Permalink
sdk fixes in all scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
Tan108 committed Mar 8, 2024
1 parent 2086939 commit 5f8b078
Show file tree
Hide file tree
Showing 11 changed files with 333 additions and 378 deletions.
81 changes: 0 additions & 81 deletions src/main/kotlin/com/featurevisor/cli/AssertionHelper.kt

This file was deleted.

198 changes: 0 additions & 198 deletions src/main/kotlin/com/featurevisor/cli/TestFeature.kt

This file was deleted.

34 changes: 24 additions & 10 deletions src/main/kotlin/com/featurevisor/sdk/Instance+Evaluation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ fun FeaturevisorInstance.evaluateFlag(featureKey: FeatureKey, context: Context =

// required
if (feature.required.isNullOrEmpty().not()) {
val requiredFeaturesAreEnabled = feature.required!!.all { item ->
var requiredKey: FeatureKey
var requiredVariation: VariationValue?
val requiredFeaturesAreEnabled = feature.required?.all { item ->
var requiredKey: FeatureKey? = null
var requiredVariation: VariationValue? = null
when (item) {
is Required.FeatureKey -> {
requiredKey = item.required
Expand All @@ -307,12 +307,16 @@ fun FeaturevisorInstance.evaluateFlag(featureKey: FeatureKey, context: Context =
return@all false
}

val requiredVariationValue = getVariation(requiredKey, finalContext)
if (requiredVariation != null){
val requiredVariationValue = getVariation(requiredKey, finalContext)

return@all requiredVariationValue == requiredVariation
return@all requiredVariationValue == requiredVariation
}

return@all true
}

if (requiredFeaturesAreEnabled.not()) {
if ((requiredFeaturesAreEnabled == false)) {
evaluation = Evaluation(
featureKey = feature.key,
reason = REQUIRED,
Expand Down Expand Up @@ -482,9 +486,11 @@ fun FeaturevisorInstance.evaluateVariable(
val finalContext = interceptContext?.invoke(context) ?: context

// forced
findForceFromFeature(feature, context, datafileReader)?.let { force ->
if (force.variables?.containsKey(variableKey) == true) {
val variableValue = force.variables[variableKey]
val force = findForceFromFeature(feature, context, datafileReader)

force?.let {
if (it.variables?.containsKey(variableKey) == true) {
val variableValue = it.variables[variableKey]
evaluation = Evaluation(
featureKey = feature.key,
reason = FORCED,
Expand All @@ -500,6 +506,7 @@ fun FeaturevisorInstance.evaluateVariable(

// bucketing
val bucketValue = getBucketValue(feature, finalContext)

val matchedTrafficAndAllocation = getMatchedTrafficAndAllocation(
traffic = feature.traffic,
context = finalContext,
Expand Down Expand Up @@ -528,8 +535,15 @@ fun FeaturevisorInstance.evaluateVariable(

// regular allocation
matchedTrafficAndAllocation.matchedAllocation?.let { matchedAllocation ->

val variationValue: String = if (force?.variation != null) {
force.variation
} else {
matchedAllocation.variation
}

val variation = feature.variations?.firstOrNull { variation ->
variation.value == matchedAllocation.variation
variation.value == variationValue
}

val variableFromVariation = variation?.variables?.firstOrNull { variable ->
Expand Down
Loading

0 comments on commit 5f8b078

Please sign in to comment.