summaryrefslogtreecommitdiff
path: root/spec/models/operations/feature_flags_client_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/operations/feature_flags_client_spec.rb')
-rw-r--r--spec/models/operations/feature_flags_client_spec.rb70
1 files changed, 69 insertions, 1 deletions
diff --git a/spec/models/operations/feature_flags_client_spec.rb b/spec/models/operations/feature_flags_client_spec.rb
index 05988d676f3..2ed3222c65c 100644
--- a/spec/models/operations/feature_flags_client_spec.rb
+++ b/spec/models/operations/feature_flags_client_spec.rb
@@ -3,7 +3,15 @@
require 'spec_helper'
RSpec.describe Operations::FeatureFlagsClient do
- subject { create(:operations_feature_flags_client) }
+ let_it_be(:project) { create(:project) }
+
+ let!(:client) { create(:operations_feature_flags_client, project: project) }
+
+ subject { client }
+
+ before do
+ client.unleash_app_name = 'production'
+ end
describe 'associations' do
it { is_expected.to belong_to(:project) }
@@ -18,4 +26,64 @@ RSpec.describe Operations::FeatureFlagsClient do
expect(subject.token).not_to be_empty
end
end
+
+ describe '.update_last_feature_flag_updated_at!' do
+ subject { described_class.update_last_feature_flag_updated_at!(project) }
+
+ it 'updates the last_feature_flag_updated_at of the project client' do
+ freeze_time do
+ expect { subject }.to change { client.reload.last_feature_flag_updated_at }.from(nil).to(Time.current)
+ end
+ end
+ end
+
+ describe '#unleash_api_version' do
+ subject { client.unleash_api_version }
+
+ it { is_expected.to eq(described_class::DEFAULT_UNLEASH_API_VERSION) }
+ end
+
+ describe '#unleash_api_features' do
+ subject { client.unleash_api_features }
+
+ it 'fetches' do
+ expect(Operations::FeatureFlag).to receive(:for_unleash_client).with(project, 'production').once
+
+ subject
+ end
+
+ context 'when unleash app name is not set' do
+ before do
+ client.unleash_app_name = nil
+ end
+
+ it 'does not fetch' do
+ expect(Operations::FeatureFlag).not_to receive(:for_unleash_client)
+
+ subject
+ end
+ end
+ end
+
+ describe '#unleash_api_cache_key' do
+ subject { client.unleash_api_cache_key }
+
+ it 'constructs the cache key' do
+ is_expected.to eq("api_version:#{client.unleash_api_version}"\
+ ":app_name:#{client.unleash_app_name}"\
+ ":updated_at:#{client.last_feature_flag_updated_at.to_i}")
+ end
+
+ context 'when unleash app name is not set' do
+ before do
+ client.unleash_app_name = nil
+ end
+
+ it 'constructs the cache key without unleash app name' do
+ is_expected.to eq("api_version:#{client.unleash_api_version}"\
+ ":app_name:"\
+ ":updated_at:#{client.last_feature_flag_updated_at.to_i}")
+ end
+ end
+ end
end