Skip to content

Commit

Permalink
Support custom_attributes for directory users (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
blairlunceford authored Aug 13, 2021
1 parent 062a969 commit 41dd500
Show file tree
Hide file tree
Showing 9 changed files with 618 additions and 152 deletions.
5 changes: 4 additions & 1 deletion lib/workos/directory_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DirectoryUser
extend T::Sig

attr_accessor :id, :idp_id, :emails, :first_name, :last_name, :username, :state,
:groups, :raw_attributes
:groups, :custom_attributes, :raw_attributes

# rubocop:disable Metrics/AbcSize
sig { params(json: String).void }
Expand All @@ -24,6 +24,7 @@ def initialize(json)
@username = raw.username
@state = raw.state
@groups = T.let(raw.groups, Array)
@custom_attributes = raw.custom_attributes
@raw_attributes = raw.raw_attributes
end
# rubocop:enable Metrics/AbcSize
Expand All @@ -38,6 +39,7 @@ def to_json(*)
username: username,
state: state,
groups: groups,
custom_attributes: custom_attributes,
raw_attributes: raw_attributes,
}
end
Expand All @@ -61,6 +63,7 @@ def parse_json(json_string)
username: hash[:username],
state: hash[:state],
groups: hash[:groups],
custom_attributes: hash[:custom_attributes],
raw_attributes: hash[:raw_attributes],
)
end
Expand Down
1 change: 1 addition & 0 deletions lib/workos/types/directory_user_struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class DirectoryUserStruct < T::Struct
const :username, T.nilable(String)
const :state, T.nilable(String)
const :groups, T::Array[T.untyped]
const :custom_attributes, T::Hash[Symbol, T.untyped]
const :raw_attributes, T::Hash[Symbol, Object]
end
end
Expand Down
38 changes: 19 additions & 19 deletions spec/lib/workos/directory_sync_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
context 'with directory option' do
it 'forms the proper request to the API' do
request_args = [
'/directory_users?directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
'/directory_users?directory=directory_01FAZYMST676QMTFN1DDJZZX87',
'Content-Type' => 'application/json'
]

Expand All @@ -293,18 +293,18 @@

VCR.use_cassette 'directory_sync/list_users/with_directory' do
users = described_class.list_users(
directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
directory: 'directory_01FAZYMST676QMTFN1DDJZZX87',
)

expect(users.data.size).to eq(10)
expect(users.data.size).to eq(4)
end
end
end

context 'with group option' do
it 'forms the proper request to the API' do
request_args = [
'/directory_users?group=directory_group_01EQ7V7C6Y4RPMCH3KNB9853FF',
'/directory_users?group=directory_group_01FBXGP79EJAYKW0WS9JCK1V6E',
'Content-Type' => 'application/json'
]

Expand All @@ -315,19 +315,19 @@

VCR.use_cassette 'directory_sync/list_users/with_group' do
users = described_class.list_users(
group: 'directory_group_01EQ7V7C6Y4RPMCH3KNB9853FF',
group: 'directory_group_01FBXGP79EJAYKW0WS9JCK1V6E',
)

expect(users.data.size).to eq(2)
expect(users.data.size).to eq(1)
end
end
end

context 'with the before option' do
it 'forms the proper request to the API' do
request_args = [
'/directory_users?before=before-id&'\
'directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
'/directory_users?before=directory_user_01FAZYNPC8TJBP7Y2ERT51MGDF&'\
'directory=directory_01FAZYMST676QMTFN1DDJZZX87',
'Content-Type' => 'application/json'
]

Expand All @@ -338,8 +338,8 @@

VCR.use_cassette 'directory_sync/list_users/with_before' do
users = described_class.list_users(
before: 'before-id',
directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
before: 'directory_user_01FAZYNPC8TJBP7Y2ERT51MGDF',
directory: 'directory_01FAZYMST676QMTFN1DDJZZX87',
)

expect(users.data.size).to eq(2)
Expand All @@ -350,8 +350,8 @@
context 'with the after option' do
it 'forms the proper request to the API' do
request_args = [
'/directory_users?after=after-id&' \
'directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
'/directory_users?after=directory_user_01FAZYNPC8TJBP7Y2ERT51MGDF&' \
'directory=directory_01FAZYMST676QMTFN1DDJZZX87',
'Content-Type' => 'application/json'
]

Expand All @@ -362,11 +362,11 @@

VCR.use_cassette 'directory_sync/list_users/with_after' do
users = described_class.list_users(
after: 'after-id',
directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
after: 'directory_user_01FAZYNPC8TJBP7Y2ERT51MGDF',
directory: 'directory_01FAZYMST676QMTFN1DDJZZX87',
)

expect(users.data.size).to eq(10)
expect(users.data.size).to eq(1)
end
end
end
Expand All @@ -375,7 +375,7 @@
it 'forms the proper request to the API' do
request_args = [
'/directory_users?limit=2&' \
'directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
'directory=directory_01FAZYMST676QMTFN1DDJZZX87',
'Content-Type' => 'application/json'
]

Expand All @@ -387,7 +387,7 @@
VCR.use_cassette 'directory_sync/list_users/with_limit' do
users = described_class.list_users(
limit: 2,
directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
directory: 'directory_01FAZYMST676QMTFN1DDJZZX87',
)

expect(users.data.size).to eq(2)
Expand Down Expand Up @@ -425,10 +425,10 @@
it 'returns a user' do
VCR.use_cassette('directory_sync/get_user') do
user = WorkOS::DirectorySync.get_user(
'directory_usr_01E64QS50EAY48S0XJ1AA4WX4D',
'directory_user_01FAZYNPC8M0HRYTKFP2GNX852',
)

expect(user['first_name']).to eq('Mark')
expect(user['first_name']).to eq('Logan')
end
end
end
Expand Down
56 changes: 40 additions & 16 deletions spec/support/fixtures/vcr_cassettes/directory_sync/get_user.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 41dd500

Please sign in to comment.