Commit 786336fa authored by Imre Farkas's avatar Imre Farkas

Merge branch 'fixup-ops-ff-specs' into 'master'

Fixup Operations Feature Flag Scope Specs

See merge request gitlab-org/gitlab!24906
parents 86111ba9 29ae3cde
...@@ -63,6 +63,7 @@ describe Operations::FeatureFlagScope do ...@@ -63,6 +63,7 @@ describe Operations::FeatureFlagScope do
it 'validates multiple strategies' do it 'validates multiple strategies' do
feature_flag = create(:operations_feature_flag) feature_flag = create(:operations_feature_flag)
scope = described_class.create(feature_flag: feature_flag, scope = described_class.create(feature_flag: feature_flag,
environment_scope: 'production', active: true,
strategies: [{ name: "default", parameters: {} }, strategies: [{ name: "default", parameters: {} },
{ name: "invalid", parameters: {} }]) { name: "invalid", parameters: {} }])
...@@ -101,7 +102,9 @@ describe Operations::FeatureFlagScope do ...@@ -101,7 +102,9 @@ describe Operations::FeatureFlagScope do
with_them do with_them do
it 'must be one of "default", "gradualRolloutUserId", or "userWithId"' do it 'must be one of "default", "gradualRolloutUserId", or "userWithId"' do
feature_flag = create(:operations_feature_flag) feature_flag = create(:operations_feature_flag)
scope = described_class.create(feature_flag: feature_flag, strategies: [{ name: name, parameters: params }]) scope = described_class.create(feature_flag: feature_flag,
environment_scope: 'production', active: true,
strategies: [{ name: name, parameters: params }])
expect(scope.errors[:strategies]).to eq(expected) expect(scope.errors[:strategies]).to eq(expected)
end end
...@@ -113,6 +116,7 @@ describe Operations::FeatureFlagScope do ...@@ -113,6 +116,7 @@ describe Operations::FeatureFlagScope do
it 'must have parameters' do it 'must have parameters' do
feature_flag = create(:operations_feature_flag) feature_flag = create(:operations_feature_flag)
scope = described_class.create(feature_flag: feature_flag, scope = described_class.create(feature_flag: feature_flag,
environment_scope: 'production', active: true,
strategies: [{ name: 'gradualRolloutUserId' }]) strategies: [{ name: 'gradualRolloutUserId' }])
expect(scope.errors[:strategies]).to eq(['parameters are invalid']) expect(scope.errors[:strategies]).to eq(['parameters are invalid'])
...@@ -126,6 +130,7 @@ describe Operations::FeatureFlagScope do ...@@ -126,6 +130,7 @@ describe Operations::FeatureFlagScope do
it 'must have valid parameters for the strategy' do it 'must have valid parameters for the strategy' do
feature_flag = create(:operations_feature_flag) feature_flag = create(:operations_feature_flag)
scope = described_class.create(feature_flag: feature_flag, scope = described_class.create(feature_flag: feature_flag,
environment_scope: 'production', active: true,
strategies: [{ name: 'gradualRolloutUserId', strategies: [{ name: 'gradualRolloutUserId',
parameters: invalid_parameters }]) parameters: invalid_parameters }])
...@@ -136,6 +141,7 @@ describe Operations::FeatureFlagScope do ...@@ -136,6 +141,7 @@ describe Operations::FeatureFlagScope do
it 'allows the parameters in any order' do it 'allows the parameters in any order' do
feature_flag = create(:operations_feature_flag) feature_flag = create(:operations_feature_flag)
scope = described_class.create(feature_flag: feature_flag, scope = described_class.create(feature_flag: feature_flag,
environment_scope: 'production', active: true,
strategies: [{ name: 'gradualRolloutUserId', strategies: [{ name: 'gradualRolloutUserId',
parameters: { percentage: '10', groupId: 'mygroup' } }]) parameters: { percentage: '10', groupId: 'mygroup' } }])
...@@ -152,6 +158,7 @@ describe Operations::FeatureFlagScope do ...@@ -152,6 +158,7 @@ describe Operations::FeatureFlagScope do
it 'must be a string value between 0 and 100 inclusive and without a percentage sign' do it 'must be a string value between 0 and 100 inclusive and without a percentage sign' do
feature_flag = create(:operations_feature_flag) feature_flag = create(:operations_feature_flag)
scope = described_class.create(feature_flag: feature_flag, scope = described_class.create(feature_flag: feature_flag,
environment_scope: 'production', active: true,
strategies: [{ name: 'gradualRolloutUserId', strategies: [{ name: 'gradualRolloutUserId',
parameters: { groupId: 'mygroup', percentage: invalid_value } }]) parameters: { groupId: 'mygroup', percentage: invalid_value } }])
...@@ -166,6 +173,7 @@ describe Operations::FeatureFlagScope do ...@@ -166,6 +173,7 @@ describe Operations::FeatureFlagScope do
it 'must be a string value between 0 and 100 inclusive and without a percentage sign' do it 'must be a string value between 0 and 100 inclusive and without a percentage sign' do
feature_flag = create(:operations_feature_flag) feature_flag = create(:operations_feature_flag)
scope = described_class.create(feature_flag: feature_flag, scope = described_class.create(feature_flag: feature_flag,
environment_scope: 'production', active: true,
strategies: [{ name: 'gradualRolloutUserId', strategies: [{ name: 'gradualRolloutUserId',
parameters: { groupId: 'mygroup', percentage: valid_value } }]) parameters: { groupId: 'mygroup', percentage: valid_value } }])
...@@ -183,6 +191,7 @@ describe Operations::FeatureFlagScope do ...@@ -183,6 +191,7 @@ describe Operations::FeatureFlagScope do
it 'must be a string value of up to 32 lowercase characters' do it 'must be a string value of up to 32 lowercase characters' do
feature_flag = create(:operations_feature_flag) feature_flag = create(:operations_feature_flag)
scope = described_class.create(feature_flag: feature_flag, scope = described_class.create(feature_flag: feature_flag,
environment_scope: 'production', active: true,
strategies: [{ name: 'gradualRolloutUserId', strategies: [{ name: 'gradualRolloutUserId',
parameters: { groupId: invalid_value, percentage: '40' } }]) parameters: { groupId: invalid_value, percentage: '40' } }])
...@@ -197,6 +206,7 @@ describe Operations::FeatureFlagScope do ...@@ -197,6 +206,7 @@ describe Operations::FeatureFlagScope do
it 'must be a string value of up to 32 lowercase characters' do it 'must be a string value of up to 32 lowercase characters' do
feature_flag = create(:operations_feature_flag) feature_flag = create(:operations_feature_flag)
scope = described_class.create(feature_flag: feature_flag, scope = described_class.create(feature_flag: feature_flag,
environment_scope: 'production', active: true,
strategies: [{ name: 'gradualRolloutUserId', strategies: [{ name: 'gradualRolloutUserId',
parameters: { groupId: valid_value, percentage: '40' } }]) parameters: { groupId: valid_value, percentage: '40' } }])
...@@ -209,7 +219,9 @@ describe Operations::FeatureFlagScope do ...@@ -209,7 +219,9 @@ describe Operations::FeatureFlagScope do
context 'when the strategy name is userWithId' do context 'when the strategy name is userWithId' do
it 'must have parameters' do it 'must have parameters' do
feature_flag = create(:operations_feature_flag) feature_flag = create(:operations_feature_flag)
scope = described_class.create(feature_flag: feature_flag, strategies: [{ name: 'userWithId' }]) scope = described_class.create(feature_flag: feature_flag,
environment_scope: 'production', active: true,
strategies: [{ name: 'userWithId' }])
expect(scope.errors[:strategies]).to eq(['parameters are invalid']) expect(scope.errors[:strategies]).to eq(['parameters are invalid'])
end end
...@@ -220,8 +232,9 @@ describe Operations::FeatureFlagScope do ...@@ -220,8 +232,9 @@ describe Operations::FeatureFlagScope do
with_them do with_them do
it 'must have valid parameters for the strategy' do it 'must have valid parameters for the strategy' do
feature_flag = create(:operations_feature_flag) feature_flag = create(:operations_feature_flag)
scope = described_class.create(feature_flag: feature_flag, strategies: [{ name: 'userWithId', scope = described_class.create(feature_flag: feature_flag,
parameters: invalid_parameters }]) environment_scope: 'production', active: true,
strategies: [{ name: 'userWithId', parameters: invalid_parameters }])
expect(scope.errors[:strategies]).to eq(['parameters are invalid']) expect(scope.errors[:strategies]).to eq(['parameters are invalid'])
end end
...@@ -238,6 +251,7 @@ describe Operations::FeatureFlagScope do ...@@ -238,6 +251,7 @@ describe Operations::FeatureFlagScope do
it 'is valid with a string of comma separated values' do it 'is valid with a string of comma separated values' do
feature_flag = create(:operations_feature_flag) feature_flag = create(:operations_feature_flag)
scope = described_class.create(feature_flag: feature_flag, scope = described_class.create(feature_flag: feature_flag,
environment_scope: 'production', active: true,
strategies: [{ name: 'userWithId', parameters: { userIds: valid_value } }]) strategies: [{ name: 'userWithId', parameters: { userIds: valid_value } }])
expect(scope.errors[:strategies]).to be_empty expect(scope.errors[:strategies]).to be_empty
...@@ -253,6 +267,7 @@ describe Operations::FeatureFlagScope do ...@@ -253,6 +267,7 @@ describe Operations::FeatureFlagScope do
it 'is invalid' do it 'is invalid' do
feature_flag = create(:operations_feature_flag) feature_flag = create(:operations_feature_flag)
scope = described_class.create(feature_flag: feature_flag, scope = described_class.create(feature_flag: feature_flag,
environment_scope: 'production', active: true,
strategies: [{ name: 'userWithId', parameters: { userIds: invalid_value } }]) strategies: [{ name: 'userWithId', parameters: { userIds: invalid_value } }])
expect(scope.errors[:strategies]).to include( expect(scope.errors[:strategies]).to include(
...@@ -266,7 +281,9 @@ describe Operations::FeatureFlagScope do ...@@ -266,7 +281,9 @@ describe Operations::FeatureFlagScope do
context 'when the strategy name is default' do context 'when the strategy name is default' do
it 'must have parameters' do it 'must have parameters' do
feature_flag = create(:operations_feature_flag) feature_flag = create(:operations_feature_flag)
scope = described_class.create(feature_flag: feature_flag, strategies: [{ name: 'default' }]) scope = described_class.create(feature_flag: feature_flag,
environment_scope: 'production', active: true,
strategies: [{ name: 'default' }])
expect(scope.errors[:strategies]).to eq(['parameters are invalid']) expect(scope.errors[:strategies]).to eq(['parameters are invalid'])
end end
...@@ -278,6 +295,7 @@ describe Operations::FeatureFlagScope do ...@@ -278,6 +295,7 @@ describe Operations::FeatureFlagScope do
it 'must be empty' do it 'must be empty' do
feature_flag = create(:operations_feature_flag) feature_flag = create(:operations_feature_flag)
scope = described_class.create(feature_flag: feature_flag, scope = described_class.create(feature_flag: feature_flag,
environment_scope: 'production', active: true,
strategies: [{ name: 'default', strategies: [{ name: 'default',
parameters: invalid_value }]) parameters: invalid_value }])
...@@ -288,6 +306,7 @@ describe Operations::FeatureFlagScope do ...@@ -288,6 +306,7 @@ describe Operations::FeatureFlagScope do
it 'must be empty' do it 'must be empty' do
feature_flag = create(:operations_feature_flag) feature_flag = create(:operations_feature_flag)
scope = described_class.create(feature_flag: feature_flag, scope = described_class.create(feature_flag: feature_flag,
environment_scope: 'production', active: true,
strategies: [{ name: 'default', strategies: [{ name: 'default',
parameters: {} }]) parameters: {} }])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment