workos 0.10.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -1
  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/client.rb +24 -6
  9. data/lib/workos/connection.rb +12 -1
  10. data/lib/workos/directory.rb +53 -0
  11. data/lib/workos/directory_group.rb +44 -0
  12. data/lib/workos/directory_sync.rb +63 -7
  13. data/lib/workos/directory_user.rb +63 -0
  14. data/lib/workos/organizations.rb +150 -0
  15. data/lib/workos/passwordless.rb +4 -0
  16. data/lib/workos/portal.rb +1 -81
  17. data/lib/workos/profile.rb +9 -12
  18. data/lib/workos/profile_and_token.rb +28 -0
  19. data/lib/workos/sso.rb +56 -104
  20. data/lib/workos/types/connection_struct.rb +3 -0
  21. data/lib/workos/types/directory_group_struct.rb +13 -0
  22. data/lib/workos/types/directory_struct.rb +16 -0
  23. data/lib/workos/types/directory_user_struct.rb +19 -0
  24. data/lib/workos/types/intent_enum.rb +1 -0
  25. data/lib/workos/types.rb +3 -0
  26. data/lib/workos/version.rb +1 -1
  27. data/lib/workos.rb +5 -0
  28. data/sorbet/rbi/gems/addressable.rbi +199 -0
  29. data/sorbet/rbi/gems/ast.rbi +49 -0
  30. data/sorbet/rbi/gems/codecov.rbi +37 -0
  31. data/sorbet/rbi/gems/crack.rbi +62 -0
  32. data/sorbet/rbi/gems/docile.rbi +36 -0
  33. data/sorbet/rbi/gems/hashdiff.rbi +66 -0
  34. data/sorbet/rbi/gems/parallel.rbi +83 -0
  35. data/sorbet/rbi/gems/parser.rbi +1429 -0
  36. data/sorbet/rbi/gems/public_suffix.rbi +104 -0
  37. data/sorbet/rbi/gems/rainbow.rbi +118 -0
  38. data/sorbet/rbi/gems/rake.rbi +644 -0
  39. data/sorbet/rbi/gems/regexp_parser.rbi +926 -0
  40. data/sorbet/rbi/gems/rexml.rbi +628 -0
  41. data/sorbet/rbi/gems/rspec-core.rbi +1898 -0
  42. data/sorbet/rbi/gems/rspec-expectations.rbi +1127 -0
  43. data/sorbet/rbi/gems/rspec-mocks.rbi +1099 -0
  44. data/sorbet/rbi/gems/rspec-support.rbi +280 -0
  45. data/sorbet/rbi/gems/rspec.rbi +15 -0
  46. data/sorbet/rbi/gems/rubocop-ast.rbi +1355 -0
  47. data/sorbet/rbi/gems/rubocop.rbi +7253 -0
  48. data/sorbet/rbi/gems/ruby-progressbar.rbi +304 -0
  49. data/sorbet/rbi/gems/simplecov-html.rbi +35 -0
  50. data/sorbet/rbi/gems/simplecov.rbi +406 -0
  51. data/sorbet/rbi/gems/unicode-display_width.rbi +17 -0
  52. data/sorbet/rbi/gems/vcr.rbi +572 -0
  53. data/sorbet/rbi/gems/webmock.rbi +556 -0
  54. data/sorbet/rbi/gems/yard.rbi +1165 -0
  55. data/sorbet/rbi/sorbet-typed/lib/rake/all/rake.rbi +645 -0
  56. data/sorbet/rbi/sorbet-typed/lib/rspec-core/all/rspec-core.rbi +1891 -0
  57. data/sorbet/rbi/sorbet-typed/lib/rubocop/~>0.85/rubocop.rbi +2072 -0
  58. data/sorbet/rbi/sorbet-typed/lib/yard/all/yard.rbi +1214 -0
  59. data/sorbet/rbi/todo.rbi +1 -3
  60. data/spec/lib/workos/audit_trail_spec.rb +0 -8
  61. data/spec/lib/workos/directory_sync_spec.rb +347 -40
  62. data/spec/lib/workos/organizations_spec.rb +164 -0
  63. data/spec/lib/workos/passwordless_spec.rb +0 -8
  64. data/spec/lib/workos/portal_spec.rb +17 -123
  65. data/spec/lib/workos/sso_spec.rb +172 -173
  66. data/spec/spec_helper.rb +2 -1
  67. data/spec/support/fixtures/vcr_cassettes/directory_sync/delete_directory.yml +72 -0
  68. data/spec/support/fixtures/vcr_cassettes/{sso/list_connections.yml → directory_sync/list_directories/with_after.yml} +7 -7
  69. data/spec/support/fixtures/vcr_cassettes/{sso/list_connections_with_limit_param.yml → directory_sync/list_directories/with_before.yml} +8 -8
  70. data/spec/support/fixtures/vcr_cassettes/{sso/list_connections_with_connection_type_param.yml → directory_sync/list_directories/with_domain.yml} +11 -10
  71. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_limit.yml +74 -0
  72. data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_directories.yml → list_directories/with_no_options.yml} +1 -1
  73. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_search.yml +73 -0
  74. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_after.yml +76 -0
  75. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_before.yml +74 -0
  76. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_directory.yml +78 -0
  77. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_limit.yml +74 -0
  78. data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_groups.yml → list_groups/with_no_options.yml} +16 -6
  79. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_user.yml +72 -0
  80. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_after.yml +86 -0
  81. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_before.yml +75 -0
  82. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_directory.yml +93 -0
  83. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_group.yml +76 -0
  84. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_limit.yml +75 -0
  85. data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_users.yml → list_users/with_no_options.yml} +16 -6
  86. data/spec/support/fixtures/vcr_cassettes/organization/get.yml +73 -0
  87. data/spec/support/fixtures/vcr_cassettes/organization/get_invalid.yml +72 -0
  88. data/spec/support/fixtures/vcr_cassettes/organization/update.yml +73 -0
  89. data/spec/support/fixtures/vcr_cassettes/organization/update_invalid.yml +73 -0
  90. data/spec/support/fixtures/vcr_cassettes/portal/generate_link_dsync.yml +72 -0
  91. data/spec/support/fixtures/vcr_cassettes/portal/{generate_link.yml → generate_link_sso.yml} +1 -1
  92. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_after.yml +73 -0
  93. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_before.yml +73 -0
  94. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_connection_type.yml +73 -0
  95. data/spec/support/fixtures/vcr_cassettes/sso/{list_connections_with_domain_param.yml → list_connections/with_domain.yml} +6 -6
  96. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_limit.yml +74 -0
  97. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_no_options.yml +73 -0
  98. data/spec/support/fixtures/vcr_cassettes/sso/{list_connections_with_before_param.yml → list_connections/with_organization_id.yml} +7 -8
  99. data/spec/support/fixtures/vcr_cassettes/sso/profile.yml +74 -0
  100. data/workos.gemspec +2 -0
  101. metadata +114 -43
  102. data/sorbet/rbi/hidden-definitions/errors.txt +0 -24896
  103. data/sorbet/rbi/hidden-definitions/hidden.rbi +0 -38411
  104. data/sorbet/rbi/sorbet-typed/lib/bundler/all/bundler.rbi +0 -8684
  105. data/sorbet/rbi/sorbet-typed/lib/ruby/all/gem.rbi +0 -4222
  106. data/sorbet/rbi/sorbet-typed/lib/ruby/all/open3.rbi +0 -111
  107. data/sorbet/rbi/sorbet-typed/lib/ruby/all/resolv.rbi +0 -543
  108. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories_with_domain_param.yml +0 -63
  109. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups_with_directory_param.yml +0 -62
  110. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users_with_directory_param.yml +0 -62
  111. data/spec/support/fixtures/vcr_cassettes/sso/create_connection_with_invalid_source.yml +0 -58
  112. data/spec/support/fixtures/vcr_cassettes/sso/create_connection_with_valid_source.yml +0 -63
  113. data/spec/support/fixtures/vcr_cassettes/sso/list_connections_with_after_param.yml +0 -72
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
@@ -2,14 +2,6 @@
2
2
  # typed: false
3
3
 
4
4
  describe WorkOS::AuditTrail do
5
- before(:all) do
6
- WorkOS.key = 'key'
7
- end
8
-
9
- after(:all) do
10
- WorkOS.key = nil
11
- end
12
-
13
5
  describe '.create_event' do
14
6
  context 'with valid event payload' do
15
7
  let(:valid_event) do
@@ -2,32 +2,139 @@
2
2
  # typed: false
3
3
 
4
4
  describe WorkOS::DirectorySync do
5
- before(:all) do
6
- WorkOS.key = 'key'
7
- end
8
-
9
- after(:all) do
10
- WorkOS.key = nil
11
- end
12
-
13
5
  describe '.list_directories' do
14
6
  context 'with no options' do
15
- it 'returns directories' do
16
- VCR.use_cassette('directory_sync/list_directories') do
17
- directories = WorkOS::DirectorySync.list_directories
18
- 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)
19
18
  end
20
19
  end
21
20
  end
22
21
 
23
22
  context 'with domain option' do
24
- it 'returns directories' do
25
- VCR.use_cassette('directory_sync/list_directories_with_domain_param') do
26
- 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(
27
36
  domain: 'foo-corp.com',
28
37
  )
29
38
 
30
- 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)
31
138
  end
32
139
  end
33
140
  end
@@ -35,27 +142,127 @@ describe WorkOS::DirectorySync do
35
142
 
36
143
  describe '.list_groups' do
37
144
  context 'with no options' do
38
- it 'returns groups' do
39
- 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
40
147
  expect do
41
148
  WorkOS::DirectorySync.list_groups
42
- end.to raise_error(
43
- WorkOS::InvalidRequestError,
44
- /Status 422, Validation failed/,
45
- )
149
+ end.to raise_error(WorkOS::InvalidRequestError)
46
150
  end
47
151
  end
48
152
  end
49
153
 
50
154
  context 'with directory option' do
51
- it 'returns groups' do
52
- VCR.use_cassette('directory_sync/list_groups_with_directory_param') do
53
- groups = WorkOS::DirectorySync.list_groups(
54
- 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',
55
191
  )
56
192
 
57
- expect(groups.size).to eq(2)
58
- 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)
59
266
  end
60
267
  end
61
268
  end
@@ -63,27 +270,127 @@ describe WorkOS::DirectorySync do
63
270
 
64
271
  describe '.list_users' do
65
272
  context 'with no options' do
66
- it 'returns users' do
67
- 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
68
275
  expect do
69
276
  WorkOS::DirectorySync.list_users
70
- end.to raise_error(
71
- WorkOS::InvalidRequestError,
72
- /Status 422, Validation failed/,
73
- )
277
+ end.to raise_error(WorkOS::InvalidRequestError)
74
278
  end
75
279
  end
76
280
  end
77
281
 
78
282
  context 'with directory option' do
79
- it 'returns users' do
80
- VCR.use_cassette('directory_sync/list_users_with_directory_param') do
81
- users = WorkOS::DirectorySync.list_users(
82
- 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',
83
391
  )
84
392
 
85
- expect(users.size).to eq(1)
86
- expect(users.first['last_name']).to eq('Tran')
393
+ expect(users.data.size).to eq(2)
87
394
  end
88
395
  end
89
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
@@ -2,14 +2,6 @@
2
2
  # typed: false
3
3
 
4
4
  describe WorkOS::Passwordless do
5
- before(:all) do
6
- WorkOS.key = 'key'
7
- end
8
-
9
- after(:all) do
10
- WorkOS.key = nil
11
- end
12
-
13
5
  describe '.create_session' do
14
6
  context 'with valid options payload' do
15
7
  let(:valid_options) do