Commit f04fcfb
Changed files (3)
lib
scim
spec
scim
lib/scim/kit/v2/meta.rb
@@ -31,7 +31,7 @@ module Scim
end
def self.parse_date(date)
- DateTime.parse(date)
+ DateTime.parse(date).to_time
rescue StandardError
nil
end
lib/scim/kit/v2/service_provider_configuration.rb
@@ -6,11 +6,10 @@ module Scim
# Represents a scim Service Provider Configuration
class ServiceProviderConfiguration
include Templatable
- attr_reader :location
- attr_accessor :documentation_uri
+ attr_accessor :meta, :documentation_uri
attr_reader :authentication_schemes
+ attr_reader :bulk, :filter#, :location
attr_reader :etag, :sort, :change_password, :patch
- attr_reader :bulk, :filter, :meta
def initialize(location:)
@meta = Meta.new('ServiceProviderConfig', location)
@@ -28,6 +27,25 @@ module Scim
yield scheme if block_given?
@authentication_schemes << scheme
end
+
+ class << self
+ def parse(json)
+ hash = JSON.parse(json, symbolize_names: true)
+ x = new(location: hash[:location])
+ x.meta = Meta.from(hash[:meta])
+ x.documentation_uri = hash[:documentationUri]
+ x.bulk.supported = hash[:bulk][:supported]
+ x.bulk.max_operations = hash[:bulk][:maxOperations]
+ x.bulk.max_payload_size = hash[:bulk][:maxPayloadSize]
+ x.filter.supported = hash[:filter][:supported]
+ x.filter.max_results = hash[:filter][:maxResults]
+ x.patch.supported = hash[:patch][:supported]
+ x.change_password.supported = hash[:changePassword][:supported]
+ x.sort.supported = hash[:sort][:supported]
+ x.etag.supported = hash[:etag][:supported]
+ x
+ end
+ end
end
end
end
spec/scim/kit/v2/service_provider_configuration_spec.rb
@@ -135,4 +135,30 @@ RSpec.describe Scim::Kit::V2::ServiceProviderConfiguration do
specify { expect(result[:filter][:maxResults]).to be(200) }
end
end
+
+ describe ".parse" do
+ let(:result) { described_class.parse(subject.to_json) }
+
+ before do
+ #subject.add_authentication(:oauthbearertoken)
+ subject.bulk.max_operations = 1000
+ subject.bulk.max_payload_size = 1_048_576
+ subject.bulk.supported = true
+ subject.change_password.supported = true
+ subject.documentation_uri = FFaker::Internet.uri('https')
+ subject.etag.supported = true
+ subject.filter.max_results = 200
+ subject.filter.supported = true
+ subject.patch.supported = true
+ subject.sort.supported = true
+ end
+
+ specify { expect(result.meta.created.to_i).to eql(subject.meta.created.to_i) }
+ specify { expect(result.meta.last_modified.to_i).to eql(subject.meta.last_modified.to_i) }
+ specify { expect(result.meta.version).to eql(subject.meta.version) }
+ specify { expect(result.meta.location).to eql(subject.meta.location) }
+ specify { expect(result.meta.resource_type).to eql(subject.meta.resource_type) }
+ specify { expect(result.to_json).to eql(subject.to_json) }
+ specify { expect(result.to_h).to eql(subject.to_h) }
+ end
end