Commit ac4f3c52 authored by James Lopez's avatar James Lopez

Add params parser and spec

parent a09e572b
# frozen_string_literal: true
module EE
module Gitlab
module Scim
class ParamsParser
FILTER_OPERATORS = %w[eq]
OPERATIONS_OPERATORS = %w[Replace Add]
ATTRIBUTE_MAP = {
id: :extern_uid,
'name.formatted': :name,
'emails[type eq "work".value': :mail
}.with_indifferent_access
def initialize(params)
@filter = params[:filter]
@operations = params[:operations]
@hash = {}
end
def to_hash
process_filter
process_operations
@hash
end
private
def process_filter
return unless @filter
attribute, operator, value = @filter.split
return unless FILTER_OPERATORS.include?(operator)
return unless ATTRIBUTE_MAP[attribute]
@hash[ATTRIBUTE_MAP[attribute]] = value.tr('\"', '')
end
def process_operations
return unless @operations
@operations.each do |operation|
next unless OPERATIONS_OPERATORS.contains?(operation[:op])
attribute = ATTRIBUTE_MAP[operation[:path]]
@hash[attribute] = operation[:value] if attribute
end
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe EE::Gitlab::Scim::ParamsParser do
describe '#to_hash' do
it 'returns the correct filter attributes' do
filter = 'id eq "6ba81b08-77da"'
expect(described_class.new(filter: filter).to_hash).to eq(extern_uid: '6ba81b08-77da')
end
end
end
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