Commit 2a5c9f4

mokha <mokha@cisco.com>
2019-02-13 00:52:24
load remote resource types
1 parent 44a88c7
Changed files (3)
lib/scim/kit/v2/configuration.rb
@@ -58,6 +58,12 @@ module Scim
             schema = Schema.from(schema_hash)
             schemas[schema.id] = schema
           end
+          response = client.get(URI.join(base_url, 'ResourceTypes'))
+          resource_types_hashes = JSON.parse(response.body, symbolize_names: true)
+          resource_types_hashes.each do |resource_type_hash|
+            resource_type = ResourceType.from(resource_type_hash)
+            resource_types[resource_type.id] = resource_type
+          end
         end
 
         private
lib/scim/kit/v2/resource_type.rb
@@ -32,7 +32,7 @@ module Scim
             item
           end
 
-          def parse(json, hash = JSON.parse(json, symbolize_names: true))
+          def from(hash)
             x = new(location: hash[:location])
             x.meta = Meta.from(hash[:meta])
             %i[id name description endpoint schema].each do |key|
@@ -43,6 +43,10 @@ module Scim
             end
             x
           end
+
+          def parse(json)
+            from(JSON.parse(json, symbolize_names: true))
+          end
         end
       end
     end
spec/scim/kit/v2/configuration_spec.rb
@@ -46,6 +46,11 @@ RSpec.describe Scim::Kit::V2::Configuration do
     let(:schema) do
       Scim::Kit::V2::Schema.new(id: 'User', name: 'User', location: FFaker::Internet.uri('https'))
     end
+    let(:resource_type) do
+      x = Scim::Kit::V2::ResourceType.new(location: FFaker::Internet.uri('https'))
+      x.id = 'User'
+      x
+    end
 
     before do
       stub_request(:get, "#{base_url}/ServiceProviderConfig")
@@ -54,10 +59,14 @@ RSpec.describe Scim::Kit::V2::Configuration do
       stub_request(:get, "#{base_url}/Schemas")
         .to_return(status: 200, body: [schema.to_h].to_json)
 
+      stub_request(:get, "#{base_url}/ResourceTypes")
+        .to_return(status: 200, body: [resource_type.to_h].to_json)
+
       subject.load_from(base_url)
     end
 
     specify { expect(subject.service_provider_configuration.to_h).to eql(service_provider_configuration.to_h) }
     specify { expect(subject.schemas[schema.id].to_h).to eql(schema.to_h) }
+    specify { expect(subject.resource_types[resource_type.id].to_h).to eql(resource_type.to_h) }
   end
 end