Skip to content
Open
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 .github/workflows/sdk-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ permissions:
jobs:
sdk-spec:
# Keep the ref in `uses:` and `spec-ref` in sync.
uses: Flagsmith/sdk-spec/.github/workflows/run-spec.yml@v0.9.0
uses: Flagsmith/sdk-spec/.github/workflows/run-spec.yml@v0.10.0
with:
spec-ref: v0.9.0
spec-ref: v0.10.0
tags: core events local-evaluation
language: ruby
1 change: 1 addition & 0 deletions lib/flagsmith/sdk/models/flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def from_api(json_flag_data)
value: json_flag_data.fetch(:feature_state_value) { json_flag_data[:value] },
feature_name: json_flag_data.dig(:feature, :name),
feature_id: json_flag_data.dig(:feature, :id),
reason: json_flag_data[:reason],
variant: json_flag_data[:variant],
experiment: Experiment.from_api(json_flag_data[:metadata])
)
Expand Down
2 changes: 1 addition & 1 deletion sdk-spec/steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
require 'flagsmith'

def as_spec_flag(flag)
{ feature: flag.feature_name, enabled: flag.enabled, value: flag.value }
{ feature: flag.feature_name, enabled: flag.enabled, value: flag.value, reason: flag.reason }
end

def as_spec_flags(flags)
Expand Down
12 changes: 8 additions & 4 deletions spec/sdk/fixtures/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"enabled": false,
"environment": 2310,
"identity": null,
"feature_segment": null
"feature_segment": null,
"reason": "STATIC"
},
{
"id": 8712,
Expand All @@ -33,7 +34,8 @@
"enabled": true,
"environment": 2310,
"identity": null,
"feature_segment": null
"feature_segment": null,
"reason": "STATIC"
},
{
"id": 8724,
Expand All @@ -51,7 +53,8 @@
"enabled": false,
"environment": 2310,
"identity": null,
"feature_segment": null
"feature_segment": null,
"reason": "STATIC"
},
{
"id": 8766,
Expand All @@ -69,6 +72,7 @@
"enabled": true,
"environment": 2310,
"identity": null,
"feature_segment": 335
"feature_segment": 335,
"reason": "STATIC"
}
]
9 changes: 6 additions & 3 deletions spec/sdk/fixtures/identities.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"enabled": false,
"environment": 2310,
"identity": null,
"feature_segment": null
"feature_segment": null,
"reason": "STATIC"
},
{
"id": 8712,
Expand All @@ -34,7 +35,8 @@
"enabled": true,
"environment": 2310,
"identity": null,
"feature_segment": null
"feature_segment": null,
"reason": "STATIC"
},
{
"id": 8766,
Expand All @@ -52,7 +54,8 @@
"enabled": true,
"environment": 2310,
"identity": null,
"feature_segment": 335
"feature_segment": 335,
"reason": "TARGETING_MATCH; segment=admins"
}
],
"traits": [
Expand Down
31 changes: 31 additions & 0 deletions spec/sdk/flagsmith_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,37 @@
end
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
end

describe 'flag reasons' do
it 'returns the reason Flagsmith evaluated each environment flag to' do
# Given / When
flags = subject.get_environment_flags

# Then
expect(flags.get_flag(:feature_one).reason).to eq('STATIC')
expect(flags.get_flag(:feature_two).reason).to eq('STATIC')
end

it 'returns the reason Flagsmith evaluated each identity flag to' do
# Given / When
flags = subject.get_identity_flags(user_id)

# Then
expect(flags.get_flag(:feature_two).reason).to eq('STATIC')
expect(flags.get_flag(:feature_three).reason).to eq('TARGETING_MATCH; segment=admins')
end

it 'returns a nil reason when Flagsmith does not send one' do
# Given
json_flag_data = { feature: { id: 1, name: 'banner' }, feature_state_value: 'hello', enabled: true }

# When
flag = Flagsmith::Flags::Flag.from_api(json_flag_data)

# Then
expect(flag.reason).to be_nil
end
end

describe '#feature_enabled?' do
it 'checks a specific feature' do
flags = subject.get_environment_flags
Expand Down
Loading