Commit ed876ec

mo <mo.khan@gmail.com>
2018-01-13 18:27:31
add user met and emails.
1 parent 2b96a46
Changed files (2)
lib
spec
lib/scim/shady.rb
@@ -1,3 +1,4 @@
+require "time"
 require "scim/shady/version"
 
 module Scim
@@ -5,12 +6,39 @@ module Scim
     class User
       attr_accessor :id
       attr_accessor :external_id
+      attr_accessor :created_at
+      attr_accessor :updated_at
+      attr_accessor :location
+      attr_accessor :version
+      attr_accessor :username
+
+      def initialize
+        @emails = []
+      end
+
+      def add_email(email)
+        @emails << email
+      end
 
       def to_h
         {
           'schemas' => [Schemas::USER],
           'id' => id,
           'externalId' => external_id,
+          'meta' => {
+            'resourceType' => 'User',
+            'created' => created_at.utc.iso8601,
+            'lastModified' => updated_at.utc.iso8601,
+            'location' => location,
+            'version' => version,
+          },
+          'name' => {
+          },
+          'userName' => username,
+          'phoneNumbers' => [],
+          'emails' => @emails.each_with_index.map do |x, i|
+            { 'value' => x, 'type' => 'work', 'primary' => i == 0 }
+          end
         }
       end
 
spec/scim/user_spec.rb
@@ -3,17 +3,39 @@ RSpec.describe Scim::Shady::User do
     subject { described_class }
     let(:id) { SecureRandom.uuid }
     let(:email) { FFaker::Internet.email }
-
+    let(:other_email) { FFaker::Internet.email }
+    let(:created_at) { Time.now }
+    let(:updated_at) { Time.now }
+    let(:user_url) { FFaker::Internet.uri("https") }
+    let(:user_version) { SecureRandom.uuid }
+    let(:username) { FFaker::Internet.user_name }
 
     it 'builds a scim user' do
       result = subject.build do |builder|
         builder.id = id
         builder.external_id = email
+        builder.created_at = created_at
+        builder.updated_at = updated_at
+        builder.location = user_url
+        builder.version = user_version
+        builder.username = username
+        builder.add_email(email)
+        builder.add_email(other_email)
       end.to_h
 
       expect(result['schemas']).to match_array([Scim::Shady::Schemas::USER])
       expect(result['id']).to eql(id)
       expect(result['externalId']).to eql(email)
+      expect(result['meta']['resourceType']).to eql('User')
+      expect(result['meta']['created']).to eql(created_at.utc.iso8601)
+      expect(result['meta']['lastModified']).to eql(updated_at.utc.iso8601)
+      expect(result['meta']['location']).to eql(user_url)
+      expect(result['meta']['version']).to eql(user_version)
+      expect(result['userName']).to eql(username)
+      expect(result['emails']).to match_array([
+        { 'value' => email, 'type' => 'work', 'primary' => true },
+        { 'value' => other_email, 'type' => 'work', 'primary' => false }
+      ])
     end
   end
 end