workos 0.10.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/.ruby-version +1 -1
  4. data/.semaphore/semaphore.yml +10 -4
  5. data/Gemfile.lock +49 -36
  6. data/LICENSE +1 -1
  7. data/README.md +13 -230
  8. data/lib/workos.rb +5 -0
  9. data/lib/workos/client.rb +24 -6
  10. data/lib/workos/connection.rb +12 -1
  11. data/lib/workos/directory.rb +53 -0
  12. data/lib/workos/directory_group.rb +44 -0
  13. data/lib/workos/directory_sync.rb +63 -7
  14. data/lib/workos/directory_user.rb +63 -0
  15. data/lib/workos/organizations.rb +150 -0
  16. data/lib/workos/passwordless.rb +4 -0
  17. data/lib/workos/portal.rb +0 -80
  18. data/lib/workos/profile.rb +9 -12
  19. data/lib/workos/profile_and_token.rb +28 -0
  20. data/lib/workos/sso.rb +35 -102
  21. data/lib/workos/types.rb +3 -0
  22. data/lib/workos/types/connection_struct.rb +3 -0
  23. data/lib/workos/types/directory_group_struct.rb +13 -0
  24. data/lib/workos/types/directory_struct.rb +16 -0
  25. data/lib/workos/types/directory_user_struct.rb +19 -0
  26. data/lib/workos/version.rb +1 -1
  27. data/sorbet/rbi/gems/addressable.rbi +199 -0
  28. data/sorbet/rbi/gems/ast.rbi +49 -0
  29. data/sorbet/rbi/gems/codecov.rbi +37 -0
  30. data/sorbet/rbi/gems/crack.rbi +62 -0
  31. data/sorbet/rbi/gems/docile.rbi +36 -0
  32. data/sorbet/rbi/gems/hashdiff.rbi +66 -0
  33. data/sorbet/rbi/gems/parallel.rbi +83 -0
  34. data/sorbet/rbi/gems/parser.rbi +1429 -0
  35. data/sorbet/rbi/gems/public_suffix.rbi +104 -0
  36. data/sorbet/rbi/gems/rainbow.rbi +118 -0
  37. data/sorbet/rbi/gems/rake.rbi +644 -0
  38. data/sorbet/rbi/gems/regexp_parser.rbi +926 -0
  39. data/sorbet/rbi/gems/rexml.rbi +628 -0
  40. data/sorbet/rbi/gems/rspec-core.rbi +1898 -0
  41. data/sorbet/rbi/gems/rspec-expectations.rbi +1127 -0
  42. data/sorbet/rbi/gems/rspec-mocks.rbi +1099 -0
  43. data/sorbet/rbi/gems/rspec-support.rbi +280 -0
  44. data/sorbet/rbi/gems/rspec.rbi +15 -0
  45. data/sorbet/rbi/gems/rubocop-ast.rbi +1355 -0
  46. data/sorbet/rbi/gems/rubocop.rbi +7253 -0
  47. data/sorbet/rbi/gems/ruby-progressbar.rbi +304 -0
  48. data/sorbet/rbi/gems/simplecov-html.rbi +35 -0
  49. data/sorbet/rbi/gems/simplecov.rbi +406 -0
  50. data/sorbet/rbi/gems/unicode-display_width.rbi +17 -0
  51. data/sorbet/rbi/gems/vcr.rbi +572 -0
  52. data/sorbet/rbi/gems/webmock.rbi +556 -0
  53. data/sorbet/rbi/gems/yard.rbi +1165 -0
  54. data/sorbet/rbi/sorbet-typed/lib/rake/all/rake.rbi +645 -0
  55. data/sorbet/rbi/sorbet-typed/lib/rspec-core/all/rspec-core.rbi +1891 -0
  56. data/sorbet/rbi/sorbet-typed/lib/rubocop/~>0.85/rubocop.rbi +2072 -0
  57. data/sorbet/rbi/sorbet-typed/lib/yard/all/yard.rbi +1214 -0
  58. data/sorbet/rbi/todo.rbi +1 -3
  59. data/spec/lib/workos/directory_sync_spec.rb +347 -32
  60. data/spec/lib/workos/organizations_spec.rb +164 -0
  61. data/spec/lib/workos/portal_spec.rb +0 -113
  62. data/spec/lib/workos/sso_spec.rb +137 -142
  63. data/spec/spec_helper.rb +1 -1
  64. data/spec/support/fixtures/vcr_cassettes/directory_sync/delete_directory.yml +72 -0
  65. data/spec/support/fixtures/vcr_cassettes/{sso/list_connections.yml → directory_sync/list_directories/with_after.yml} +7 -7
  66. data/spec/support/fixtures/vcr_cassettes/{sso/list_connections_with_limit_param.yml → directory_sync/list_directories/with_before.yml} +8 -8
  67. data/spec/support/fixtures/vcr_cassettes/{sso/list_connections_with_connection_type_param.yml → directory_sync/list_directories/with_domain.yml} +11 -10
  68. data/spec/support/fixtures/vcr_cassettes/{sso/list_connections_with_after_param.yml → directory_sync/list_directories/with_limit.yml} +12 -10
  69. data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_directories.yml → list_directories/with_no_options.yml} +1 -1
  70. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_search.yml +73 -0
  71. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_after.yml +76 -0
  72. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_before.yml +74 -0
  73. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_directory.yml +78 -0
  74. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_limit.yml +74 -0
  75. data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_groups.yml → list_groups/with_no_options.yml} +16 -6
  76. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_user.yml +72 -0
  77. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_after.yml +86 -0
  78. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_before.yml +75 -0
  79. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_directory.yml +93 -0
  80. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_group.yml +76 -0
  81. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_limit.yml +75 -0
  82. data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_users.yml → list_users/with_no_options.yml} +16 -6
  83. data/spec/support/fixtures/vcr_cassettes/organization/get.yml +73 -0
  84. data/spec/support/fixtures/vcr_cassettes/organization/get_invalid.yml +72 -0
  85. data/spec/support/fixtures/vcr_cassettes/organization/update.yml +73 -0
  86. data/spec/support/fixtures/vcr_cassettes/organization/update_invalid.yml +73 -0
  87. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_after.yml +73 -0
  88. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_before.yml +73 -0
  89. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_connection_type.yml +73 -0
  90. data/spec/support/fixtures/vcr_cassettes/sso/{list_connections_with_domain_param.yml → list_connections/with_domain.yml} +6 -6
  91. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_limit.yml +74 -0
  92. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_no_options.yml +73 -0
  93. data/spec/support/fixtures/vcr_cassettes/sso/{list_connections_with_organization_id_param.yml → list_connections/with_organization_id.yml} +6 -6
  94. data/spec/support/fixtures/vcr_cassettes/sso/profile.yml +74 -0
  95. data/workos.gemspec +2 -0
  96. metadata +110 -43
  97. data/sorbet/rbi/hidden-definitions/errors.txt +0 -24896
  98. data/sorbet/rbi/hidden-definitions/hidden.rbi +0 -38411
  99. data/sorbet/rbi/sorbet-typed/lib/bundler/all/bundler.rbi +0 -8684
  100. data/sorbet/rbi/sorbet-typed/lib/ruby/all/gem.rbi +0 -4222
  101. data/sorbet/rbi/sorbet-typed/lib/ruby/all/open3.rbi +0 -111
  102. data/sorbet/rbi/sorbet-typed/lib/ruby/all/resolv.rbi +0 -543
  103. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories_with_domain_param.yml +0 -63
  104. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups_with_directory_param.yml +0 -62
  105. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users_with_directory_param.yml +0 -62
  106. data/spec/support/fixtures/vcr_cassettes/sso/create_connection_with_invalid_source.yml +0 -58
  107. data/spec/support/fixtures/vcr_cassettes/sso/create_connection_with_valid_source.yml +0 -63
  108. data/spec/support/fixtures/vcr_cassettes/sso/list_connections_with_before_param.yml +0 -73
data/sorbet/rbi/todo.rbi CHANGED
@@ -2,6 +2,4 @@
2
2
  # srb rbi todo
3
3
 
4
4
  # typed: strong
5
- module T::CompatibilityPatches::RecorderExtensions; end
6
- module T::Private::Methods::MethodHooks; end
7
- module T::Private::Methods::SingletonMethodHooks; end
5
+ module ::VCR; end
@@ -4,22 +4,137 @@
4
4
  describe WorkOS::DirectorySync do
5
5
  describe '.list_directories' do
6
6
  context 'with no options' do
7
- it 'returns directories' do
8
- VCR.use_cassette('directory_sync/list_directories') do
9
- directories = WorkOS::DirectorySync.list_directories
10
- expect(directories.size).to eq(1)
7
+ it 'returns directories and metadata' do
8
+ expected_metadata = {
9
+ 'after' => nil,
10
+ 'before' => 'before-id',
11
+ }
12
+
13
+ VCR.use_cassette 'directory_sync/list_directories/with_no_options' do
14
+ directories = described_class.list_directories
15
+
16
+ expect(directories.data.size).to eq(3)
17
+ expect(directories.list_metadata).to eq(expected_metadata)
11
18
  end
12
19
  end
13
20
  end
14
21
 
15
22
  context 'with domain option' do
16
- it 'returns directories' do
17
- VCR.use_cassette('directory_sync/list_directories_with_domain_param') do
18
- directories = WorkOS::DirectorySync.list_directories(
23
+ it 'forms the proper request to the API' do
24
+ request_args = [
25
+ '/directories?domain=foo-corp.com',
26
+ 'Content-Type' => 'application/json'
27
+ ]
28
+
29
+ expected_request = Net::HTTP::Get.new(*request_args)
30
+
31
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
32
+ and_return(expected_request)
33
+
34
+ VCR.use_cassette 'directory_sync/list_directories/with_domain' do
35
+ directories = described_class.list_directories(
19
36
  domain: 'foo-corp.com',
20
37
  )
21
38
 
22
- expect(directories.first['domain']).to eq('foo-corp.com')
39
+ expect(directories.data.size).to eq(1)
40
+ end
41
+ end
42
+ end
43
+
44
+ context 'with search option' do
45
+ it 'forms the proper request to the API' do
46
+ request_args = [
47
+ '/directories?search=Foo',
48
+ 'Content-Type' => 'application/json'
49
+ ]
50
+
51
+ expected_request = Net::HTTP::Get.new(*request_args)
52
+
53
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
54
+ and_return(expected_request)
55
+
56
+ VCR.use_cassette 'directory_sync/list_directories/with_search' do
57
+ directories = described_class.list_directories(
58
+ search: 'Foo',
59
+ )
60
+
61
+ expect(directories.data.size).to eq(1)
62
+ end
63
+ end
64
+ end
65
+
66
+ context 'with the before option' do
67
+ it 'forms the proper request to the API' do
68
+ request_args = [
69
+ '/directories?before=before-id',
70
+ 'Content-Type' => 'application/json'
71
+ ]
72
+
73
+ expected_request = Net::HTTP::Get.new(*request_args)
74
+
75
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
76
+ and_return(expected_request)
77
+
78
+ VCR.use_cassette 'directory_sync/list_directories/with_before' do
79
+ directories = described_class.list_directories(
80
+ before: 'before-id',
81
+ )
82
+
83
+ expect(directories.data.size).to eq(3)
84
+ end
85
+ end
86
+ end
87
+
88
+ context 'with the after option' do
89
+ it 'forms the proper request to the API' do
90
+ request_args = [
91
+ '/directories?after=after-id',
92
+ 'Content-Type' => 'application/json'
93
+ ]
94
+
95
+ expected_request = Net::HTTP::Get.new(*request_args)
96
+
97
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
98
+ and_return(expected_request)
99
+
100
+ VCR.use_cassette 'directory_sync/list_directories/with_after' do
101
+ directories = described_class.list_directories(after: 'after-id')
102
+
103
+ expect(directories.data.size).to eq(3)
104
+ end
105
+ end
106
+ end
107
+
108
+ context 'with the limit option' do
109
+ it 'forms the proper request to the API' do
110
+ request_args = [
111
+ '/directories?limit=2',
112
+ 'Content-Type' => 'application/json'
113
+ ]
114
+
115
+ expected_request = Net::HTTP::Get.new(*request_args)
116
+
117
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
118
+ and_return(expected_request)
119
+
120
+ VCR.use_cassette 'directory_sync/list_directories/with_limit' do
121
+ directories = described_class.list_directories(limit: 2)
122
+
123
+ expect(directories.data.size).to eq(2)
124
+ end
125
+ end
126
+ end
127
+ end
128
+
129
+ describe '.delete_directory' do
130
+ context 'with valid id' do
131
+ it 'deletes a directory' do
132
+ VCR.use_cassette('directory_sync/delete_directory') do
133
+ response = WorkOS::DirectorySync.delete_directory(
134
+ 'directory_01F2T098SKN5PCTVSJ7CWP70N5',
135
+ )
136
+
137
+ expect(response).to be(true)
23
138
  end
24
139
  end
25
140
  end
@@ -27,27 +142,127 @@ describe WorkOS::DirectorySync do
27
142
 
28
143
  describe '.list_groups' do
29
144
  context 'with no options' do
30
- it 'returns groups' do
31
- VCR.use_cassette('directory_sync/list_groups') do
145
+ it 'raises an error' do
146
+ VCR.use_cassette('directory_sync/list_groups/with_no_options') do
32
147
  expect do
33
148
  WorkOS::DirectorySync.list_groups
34
- end.to raise_error(
35
- WorkOS::InvalidRequestError,
36
- /Status 422, Validation failed/,
37
- )
149
+ end.to raise_error(WorkOS::InvalidRequestError)
38
150
  end
39
151
  end
40
152
  end
41
153
 
42
154
  context 'with directory option' do
43
- it 'returns groups' do
44
- VCR.use_cassette('directory_sync/list_groups_with_directory_param') do
45
- groups = WorkOS::DirectorySync.list_groups(
46
- directory: 'directory_edp_01E64QQVQTCB0DECJ9CFNXEWDW',
155
+ it 'forms the proper request to the API' do
156
+ request_args = [
157
+ '/directory_groups?directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
158
+ 'Content-Type' => 'application/json'
159
+ ]
160
+
161
+ expected_request = Net::HTTP::Get.new(*request_args)
162
+
163
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
164
+ and_return(expected_request)
165
+
166
+ VCR.use_cassette 'directory_sync/list_groups/with_directory' do
167
+ groups = described_class.list_groups(
168
+ directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
169
+ )
170
+
171
+ expect(groups.data.size).to eq(10)
172
+ end
173
+ end
174
+ end
175
+
176
+ context 'with user option' do
177
+ it 'forms the proper request to the API' do
178
+ request_args = [
179
+ '/directory_groups?user=directory_user_01EK2YFBC3R10MPB4W49G5QDXG',
180
+ 'Content-Type' => 'application/json'
181
+ ]
182
+
183
+ expected_request = Net::HTTP::Get.new(*request_args)
184
+
185
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
186
+ and_return(expected_request)
187
+
188
+ VCR.use_cassette 'directory_sync/list_groups/with_user' do
189
+ groups = described_class.list_groups(
190
+ user: 'directory_user_01EK2YFBC3R10MPB4W49G5QDXG',
47
191
  )
48
192
 
49
- expect(groups.size).to eq(2)
50
- expect(groups.first['name']).to eq('Walrus')
193
+ expect(groups.data.size).to eq(3)
194
+ end
195
+ end
196
+ end
197
+
198
+ context 'with the before option' do
199
+ it 'forms the proper request to the API' do
200
+ request_args = [
201
+ '/directory_groups?before=before-id&' \
202
+ 'directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
203
+ 'Content-Type' => 'application/json'
204
+ ]
205
+
206
+ expected_request = Net::HTTP::Get.new(*request_args)
207
+
208
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
209
+ and_return(expected_request)
210
+
211
+ VCR.use_cassette 'directory_sync/list_groups/with_before' do
212
+ groups = described_class.list_groups(
213
+ before: 'before-id',
214
+ directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
215
+ )
216
+
217
+ expect(groups.data.size).to eq(2)
218
+ end
219
+ end
220
+ end
221
+
222
+ context 'with the after option' do
223
+ it 'forms the proper request to the API' do
224
+ request_args = [
225
+ '/directory_groups?after=after-id&' \
226
+ 'directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
227
+ 'Content-Type' => 'application/json'
228
+ ]
229
+
230
+ expected_request = Net::HTTP::Get.new(*request_args)
231
+
232
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
233
+ and_return(expected_request)
234
+
235
+ VCR.use_cassette 'directory_sync/list_groups/with_after' do
236
+ groups = described_class.list_groups(
237
+ after: 'after-id',
238
+ directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
239
+ )
240
+
241
+ expect(groups.data.size).to eq(10)
242
+ end
243
+ end
244
+ end
245
+
246
+ context 'with the limit option' do
247
+ it 'forms the proper request to the API' do
248
+ request_args = [
249
+ '/directory_groups?limit=2&' \
250
+ 'directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
251
+ 'Content-Type' => 'application/json'
252
+ ]
253
+
254
+ expected_request = Net::HTTP::Get.new(*request_args)
255
+
256
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
257
+ and_return(expected_request)
258
+
259
+ VCR.use_cassette 'directory_sync/list_groups/with_limit' do
260
+ groups = described_class.list_groups(
261
+ limit: 2,
262
+ directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
263
+ )
264
+
265
+ expect(groups.data.size).to eq(2)
51
266
  end
52
267
  end
53
268
  end
@@ -55,27 +270,127 @@ describe WorkOS::DirectorySync do
55
270
 
56
271
  describe '.list_users' do
57
272
  context 'with no options' do
58
- it 'returns users' do
59
- VCR.use_cassette('directory_sync/list_users') do
273
+ it 'raises an error' do
274
+ VCR.use_cassette('directory_sync/list_users/with_no_options') do
60
275
  expect do
61
276
  WorkOS::DirectorySync.list_users
62
- end.to raise_error(
63
- WorkOS::InvalidRequestError,
64
- /Status 422, Validation failed/,
65
- )
277
+ end.to raise_error(WorkOS::InvalidRequestError)
66
278
  end
67
279
  end
68
280
  end
69
281
 
70
282
  context 'with directory option' do
71
- it 'returns users' do
72
- VCR.use_cassette('directory_sync/list_users_with_directory_param') do
73
- users = WorkOS::DirectorySync.list_users(
74
- directory: 'directory_edp_01E64QQVQTCB0DECJ9CFNXEWDW',
283
+ it 'forms the proper request to the API' do
284
+ request_args = [
285
+ '/directory_users?directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
286
+ 'Content-Type' => 'application/json'
287
+ ]
288
+
289
+ expected_request = Net::HTTP::Get.new(*request_args)
290
+
291
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
292
+ and_return(expected_request)
293
+
294
+ VCR.use_cassette 'directory_sync/list_users/with_directory' do
295
+ users = described_class.list_users(
296
+ directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
297
+ )
298
+
299
+ expect(users.data.size).to eq(10)
300
+ end
301
+ end
302
+ end
303
+
304
+ context 'with group option' do
305
+ it 'forms the proper request to the API' do
306
+ request_args = [
307
+ '/directory_users?group=directory_group_01EQ7V7C6Y4RPMCH3KNB9853FF',
308
+ 'Content-Type' => 'application/json'
309
+ ]
310
+
311
+ expected_request = Net::HTTP::Get.new(*request_args)
312
+
313
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
314
+ and_return(expected_request)
315
+
316
+ VCR.use_cassette 'directory_sync/list_users/with_group' do
317
+ users = described_class.list_users(
318
+ group: 'directory_group_01EQ7V7C6Y4RPMCH3KNB9853FF',
319
+ )
320
+
321
+ expect(users.data.size).to eq(2)
322
+ end
323
+ end
324
+ end
325
+
326
+ context 'with the before option' do
327
+ it 'forms the proper request to the API' do
328
+ request_args = [
329
+ '/directory_users?before=before-id&'\
330
+ 'directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
331
+ 'Content-Type' => 'application/json'
332
+ ]
333
+
334
+ expected_request = Net::HTTP::Get.new(*request_args)
335
+
336
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
337
+ and_return(expected_request)
338
+
339
+ VCR.use_cassette 'directory_sync/list_users/with_before' do
340
+ users = described_class.list_users(
341
+ before: 'before-id',
342
+ directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
343
+ )
344
+
345
+ expect(users.data.size).to eq(2)
346
+ end
347
+ end
348
+ end
349
+
350
+ context 'with the after option' do
351
+ it 'forms the proper request to the API' do
352
+ request_args = [
353
+ '/directory_users?after=after-id&' \
354
+ 'directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
355
+ 'Content-Type' => 'application/json'
356
+ ]
357
+
358
+ expected_request = Net::HTTP::Get.new(*request_args)
359
+
360
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
361
+ and_return(expected_request)
362
+
363
+ VCR.use_cassette 'directory_sync/list_users/with_after' do
364
+ users = described_class.list_users(
365
+ after: 'after-id',
366
+ directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
367
+ )
368
+
369
+ expect(users.data.size).to eq(10)
370
+ end
371
+ end
372
+ end
373
+
374
+ context 'with the limit option' do
375
+ it 'forms the proper request to the API' do
376
+ request_args = [
377
+ '/directory_users?limit=2&' \
378
+ 'directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
379
+ 'Content-Type' => 'application/json'
380
+ ]
381
+
382
+ expected_request = Net::HTTP::Get.new(*request_args)
383
+
384
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
385
+ and_return(expected_request)
386
+
387
+ VCR.use_cassette 'directory_sync/list_users/with_limit' do
388
+ users = described_class.list_users(
389
+ limit: 2,
390
+ directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
75
391
  )
76
392
 
77
- expect(users.size).to eq(1)
78
- expect(users.first['last_name']).to eq('Tran')
393
+ expect(users.data.size).to eq(2)
79
394
  end
80
395
  end
81
396
  end
@@ -0,0 +1,164 @@
1
+ # frozen_string_literal: true
2
+ # typed: false
3
+
4
+ describe WorkOS::Organizations do
5
+ describe '.create_organization' do
6
+ context 'with valid payload' do
7
+ it 'creates an organization' do
8
+ VCR.use_cassette 'organization/create' do
9
+ organization = described_class.create_organization(
10
+ domains: ['example.com'],
11
+ name: 'Test Organization',
12
+ )
13
+
14
+ expect(organization.id).to eq('org_01EHT88Z8J8795GZNQ4ZP1J81T')
15
+ expect(organization.name).to eq('Test Organization')
16
+ expect(organization.domains.first[:domain]).to eq('example.com')
17
+ end
18
+ end
19
+ end
20
+
21
+ context 'with an invalid payload' do
22
+ it 'returns an error' do
23
+ VCR.use_cassette 'organization/create_invalid' do
24
+ expect do
25
+ described_class.create_organization(
26
+ domains: ['example.com'],
27
+ name: 'Test Organization 2',
28
+ )
29
+ end.to raise_error(
30
+ WorkOS::APIError,
31
+ /An Organization with the domain example.com already exists/,
32
+ )
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ describe '.list_organizations' do
39
+ context 'with no options' do
40
+ it 'returns organizations and metadata' do
41
+ expected_metadata = {
42
+ 'after' => nil,
43
+ 'before' => 'before-id',
44
+ }
45
+
46
+ VCR.use_cassette 'organization/list' do
47
+ organizations = described_class.list_organizations
48
+
49
+ expect(organizations.data.size).to eq(7)
50
+ expect(organizations.list_metadata).to eq(expected_metadata)
51
+ end
52
+ end
53
+ end
54
+
55
+ context 'with the before option' do
56
+ it 'forms the proper request to the API' do
57
+ request_args = [
58
+ '/organizations?before=before-id',
59
+ 'Content-Type' => 'application/json'
60
+ ]
61
+
62
+ expected_request = Net::HTTP::Get.new(*request_args)
63
+
64
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
65
+ and_return(expected_request)
66
+
67
+ VCR.use_cassette 'organization/list', match_requests_on: [:path] do
68
+ organizations = described_class.list_organizations(
69
+ before: 'before-id',
70
+ )
71
+
72
+ expect(organizations.data.size).to eq(7)
73
+ end
74
+ end
75
+ end
76
+
77
+ context 'with the after option' do
78
+ it 'forms the proper request to the API' do
79
+ request_args = [
80
+ '/organizations?after=after-id',
81
+ 'Content-Type' => 'application/json'
82
+ ]
83
+
84
+ expected_request = Net::HTTP::Get.new(*request_args)
85
+
86
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
87
+ and_return(expected_request)
88
+
89
+ VCR.use_cassette 'organization/list', match_requests_on: [:path] do
90
+ organizations = described_class.list_organizations(after: 'after-id')
91
+
92
+ expect(organizations.data.size).to eq(7)
93
+ end
94
+ end
95
+ end
96
+
97
+ context 'with the limit option' do
98
+ it 'forms the proper request to the API' do
99
+ request_args = [
100
+ '/organizations?limit=10',
101
+ 'Content-Type' => 'application/json'
102
+ ]
103
+
104
+ expected_request = Net::HTTP::Get.new(*request_args)
105
+
106
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
107
+ and_return(expected_request)
108
+
109
+ VCR.use_cassette 'organization/list', match_requests_on: [:path] do
110
+ organizations = described_class.list_organizations(limit: 10)
111
+
112
+ expect(organizations.data.size).to eq(7)
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ describe '.get_organization' do
119
+ context 'with a valid id' do
120
+ it 'gets the organization details' do
121
+ VCR.use_cassette('organization/get') do
122
+ organization = described_class.get_organization(
123
+ id: 'org_01EZDF20TZEJXKPSX2BJRN6TV6',
124
+ )
125
+
126
+ expect(organization.id).to eq('org_01EZDF20TZEJXKPSX2BJRN6TV6')
127
+ expect(organization.name).to eq('Foo Corp')
128
+ expect(organization.domains.first[:domain]).to eq('foo-corp.com')
129
+ end
130
+ end
131
+ end
132
+
133
+ context 'with an invalid id' do
134
+ it 'raises an error' do
135
+ VCR.use_cassette('organization/get_invalid') do
136
+ expect do
137
+ described_class.get_organization(id: 'invalid')
138
+ end.to raise_error(
139
+ WorkOS::APIError,
140
+ 'Status 404, Not Found - request ID: ',
141
+ )
142
+ end
143
+ end
144
+ end
145
+ end
146
+
147
+ describe '.update_organization' do
148
+ context 'with valid payload' do
149
+ it 'creates an organization' do
150
+ VCR.use_cassette 'organization/update' do
151
+ organization = described_class.update_organization(
152
+ organization: 'org_01F29YJ068E52HGEB8ZQGC9MJG',
153
+ domains: ['example.me'],
154
+ name: 'Test Organization',
155
+ )
156
+
157
+ expect(organization.id).to eq('org_01F29YJ068E52HGEB8ZQGC9MJG')
158
+ expect(organization.name).to eq('Test Organization')
159
+ expect(organization.domains.first[:domain]).to eq('example.me')
160
+ end
161
+ end
162
+ end
163
+ end
164
+ end