workosv2 2.15.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 (242) hide show
  1. checksums.yaml +7 -0
  2. data/.github/CODEOWNERS +5 -0
  3. data/.github/pull_request_template.md +11 -0
  4. data/.github/renovate.json +5 -0
  5. data/.gitignore +49 -0
  6. data/.rspec +1 -0
  7. data/.rubocop.yml +24 -0
  8. data/.ruby-version +1 -0
  9. data/.semaphore/rubygems.yml +24 -0
  10. data/.semaphore/semaphore.yml +51 -0
  11. data/Gemfile +5 -0
  12. data/Gemfile.lock +126 -0
  13. data/Gemfile.lock.old +127 -0
  14. data/LICENSE +21 -0
  15. data/README.md +53 -0
  16. data/bin/build +3 -0
  17. data/bin/console +3 -0
  18. data/bin/docs +5 -0
  19. data/bin/publish +3 -0
  20. data/bin/tapioca +29 -0
  21. data/codecov.yml +12 -0
  22. data/docs/WorkOS/APIError.html +160 -0
  23. data/docs/WorkOS/AuditLog.html +235 -0
  24. data/docs/WorkOS/AuditTrail.html +235 -0
  25. data/docs/WorkOS/AuthenticationError.html +160 -0
  26. data/docs/WorkOS/Base.html +287 -0
  27. data/docs/WorkOS/Client.html +504 -0
  28. data/docs/WorkOS/InvalidRequestError.html +160 -0
  29. data/docs/WorkOS/Profile.html +788 -0
  30. data/docs/WorkOS/RequestError.html +135 -0
  31. data/docs/WorkOS/SSO.html +691 -0
  32. data/docs/WorkOS/Types/ProfileStruct.html +135 -0
  33. data/docs/WorkOS/Types/Provider.html +135 -0
  34. data/docs/WorkOS/Types.html +128 -0
  35. data/docs/WorkOS/WorkOSError.html +447 -0
  36. data/docs/WorkOS.html +324 -0
  37. data/docs/class_list.html +51 -0
  38. data/docs/css/common.css +1 -0
  39. data/docs/css/full_list.css +58 -0
  40. data/docs/css/style.css +496 -0
  41. data/docs/file.README.html +252 -0
  42. data/docs/file_list.html +56 -0
  43. data/docs/frames.html +17 -0
  44. data/docs/index.html +250 -0
  45. data/docs/js/app.js +314 -0
  46. data/docs/js/full_list.js +216 -0
  47. data/docs/js/jquery.js +4 -0
  48. data/docs/method_list.html +267 -0
  49. data/docs/top-level-namespace.html +110 -0
  50. data/lib/workosv2/audit_log_export.rb +55 -0
  51. data/lib/workosv2/audit_logs.rb +114 -0
  52. data/lib/workosv2/audit_trail.rb +111 -0
  53. data/lib/workosv2/challenge.rb +55 -0
  54. data/lib/workosv2/client.rb +186 -0
  55. data/lib/workosv2/configuration.rb +17 -0
  56. data/lib/workosv2/connection.rb +66 -0
  57. data/lib/workosv2/deprecated_hash_wrapper.rb +76 -0
  58. data/lib/workosv2/directory.rb +65 -0
  59. data/lib/workosv2/directory_group.rb +68 -0
  60. data/lib/workosv2/directory_sync.rb +218 -0
  61. data/lib/workosv2/directory_user.rb +97 -0
  62. data/lib/workosv2/errors.rb +81 -0
  63. data/lib/workosv2/event.rb +51 -0
  64. data/lib/workosv2/events.rb +52 -0
  65. data/lib/workosv2/factor.rb +54 -0
  66. data/lib/workosv2/hash_provider.rb +19 -0
  67. data/lib/workosv2/mfa.rb +178 -0
  68. data/lib/workosv2/organization.rb +57 -0
  69. data/lib/workosv2/organizations.rb +188 -0
  70. data/lib/workosv2/passwordless.rb +85 -0
  71. data/lib/workosv2/portal.rb +66 -0
  72. data/lib/workosv2/profile.rb +76 -0
  73. data/lib/workosv2/profile_and_token.rb +29 -0
  74. data/lib/workosv2/sso.rb +297 -0
  75. data/lib/workosv2/types/audit_log_export_struct.rb +17 -0
  76. data/lib/workosv2/types/challenge_struct.rb +18 -0
  77. data/lib/workosv2/types/connection_struct.rb +20 -0
  78. data/lib/workosv2/types/directory_group_struct.rb +19 -0
  79. data/lib/workosv2/types/directory_struct.rb +19 -0
  80. data/lib/workosv2/types/directory_user_struct.rb +26 -0
  81. data/lib/workosv2/types/event_struct.rb +15 -0
  82. data/lib/workosv2/types/factor_struct.rb +18 -0
  83. data/lib/workosv2/types/intent_enum.rb +17 -0
  84. data/lib/workosv2/types/list_struct.rb +13 -0
  85. data/lib/workosv2/types/organization_struct.rb +17 -0
  86. data/lib/workosv2/types/passwordless_session_struct.rb +17 -0
  87. data/lib/workosv2/types/profile_struct.rb +21 -0
  88. data/lib/workosv2/types/provider_enum.rb +15 -0
  89. data/lib/workosv2/types/verify_challenge_struct.rb +13 -0
  90. data/lib/workosv2/types/webhook_struct.rb +15 -0
  91. data/lib/workosv2/types.rb +25 -0
  92. data/lib/workosv2/verify_challenge.rb +39 -0
  93. data/lib/workosv2/version.rb +6 -0
  94. data/lib/workosv2/webhook.rb +51 -0
  95. data/lib/workosv2/webhooks.rb +217 -0
  96. data/lib/workosv2.rb +79 -0
  97. data/sorbet/config +2 -0
  98. data/sorbet/rbi/gems/addressable@2.8.0.rbi +290 -0
  99. data/sorbet/rbi/gems/ast@2.4.2.rbi +54 -0
  100. data/sorbet/rbi/gems/codecov@0.2.12.rbi +55 -0
  101. data/sorbet/rbi/gems/coderay@1.1.3.rbi +8 -0
  102. data/sorbet/rbi/gems/crack@0.4.5.rbi +57 -0
  103. data/sorbet/rbi/gems/diff-lcs@1.4.4.rbi +185 -0
  104. data/sorbet/rbi/gems/docile@1.3.5.rbi +54 -0
  105. data/sorbet/rbi/gems/hashdiff@1.0.1.rbi +82 -0
  106. data/sorbet/rbi/gems/json@2.5.1.rbi +109 -0
  107. data/sorbet/rbi/gems/method_source@1.0.0.rbi +8 -0
  108. data/sorbet/rbi/gems/parallel@1.20.1.rbi +113 -0
  109. data/sorbet/rbi/gems/parser@3.0.1.0.rbi +1187 -0
  110. data/sorbet/rbi/gems/pry@0.14.2.rbi +8 -0
  111. data/sorbet/rbi/gems/public_suffix@4.0.6.rbi +146 -0
  112. data/sorbet/rbi/gems/rainbow@3.0.0.rbi +153 -0
  113. data/sorbet/rbi/gems/rake@13.0.3.rbi +807 -0
  114. data/sorbet/rbi/gems/rbi@0.0.16.rbi +2118 -0
  115. data/sorbet/rbi/gems/regexp_parser@2.1.1.rbi +1117 -0
  116. data/sorbet/rbi/gems/rexml@3.2.5.rbi +709 -0
  117. data/sorbet/rbi/gems/rspec-core@3.9.3.rbi +2467 -0
  118. data/sorbet/rbi/gems/rspec-expectations@3.9.4.rbi +1569 -0
  119. data/sorbet/rbi/gems/rspec-mocks@3.9.1.rbi +1493 -0
  120. data/sorbet/rbi/gems/rspec-support@3.9.4.rbi +511 -0
  121. data/sorbet/rbi/gems/rspec@3.9.0.rbi +38 -0
  122. data/sorbet/rbi/gems/rubocop-ast@1.4.1.rbi +1881 -0
  123. data/sorbet/rbi/gems/rubocop@0.93.1.rbi +11497 -0
  124. data/sorbet/rbi/gems/ruby-progressbar@1.11.0.rbi +405 -0
  125. data/sorbet/rbi/gems/simplecov-html@0.12.3.rbi +89 -0
  126. data/sorbet/rbi/gems/simplecov@0.21.2.rbi +577 -0
  127. data/sorbet/rbi/gems/simplecov_json_formatter@0.1.2.rbi +8 -0
  128. data/sorbet/rbi/gems/spoom@1.1.15.rbi +1549 -0
  129. data/sorbet/rbi/gems/tapioca@0.7.3.rbi +1718 -0
  130. data/sorbet/rbi/gems/thor@1.2.1.rbi +844 -0
  131. data/sorbet/rbi/gems/unicode-display_width@1.7.0.rbi +22 -0
  132. data/sorbet/rbi/gems/unparser@0.6.2.rbi +8 -0
  133. data/sorbet/rbi/gems/vcr@5.0.0.rbi +699 -0
  134. data/sorbet/rbi/gems/webmock@3.12.2.rbi +662 -0
  135. data/sorbet/rbi/gems/yard-sorbet@0.8.0.rbi +268 -0
  136. data/sorbet/rbi/gems/yard@0.9.26.rbi +4048 -0
  137. data/sorbet/tapioca/config.yml +13 -0
  138. data/sorbet/tapioca/require.rb +4 -0
  139. data/spec/lib/workos/audit_logs_spec.rb +151 -0
  140. data/spec/lib/workos/audit_trail_spec.rb +146 -0
  141. data/spec/lib/workos/configuration_spec.rb +61 -0
  142. data/spec/lib/workos/directory_sync_spec.rb +492 -0
  143. data/spec/lib/workos/directory_user_spec.rb +36 -0
  144. data/spec/lib/workos/event_spec.rb +88 -0
  145. data/spec/lib/workos/mfa_spec.rb +281 -0
  146. data/spec/lib/workos/organizations_spec.rb +257 -0
  147. data/spec/lib/workos/passwordless_spec.rb +77 -0
  148. data/spec/lib/workos/portal_spec.rb +87 -0
  149. data/spec/lib/workos/sso_spec.rb +650 -0
  150. data/spec/lib/workos/webhooks_spec.rb +236 -0
  151. data/spec/spec_helper.rb +56 -0
  152. data/spec/support/fixtures/vcr_cassettes/audit_logs/create_event.yml +59 -0
  153. data/spec/support/fixtures/vcr_cassettes/audit_logs/create_event_custom_idempotency_key.yml +60 -0
  154. data/spec/support/fixtures/vcr_cassettes/audit_logs/create_event_invalid.yml +59 -0
  155. data/spec/support/fixtures/vcr_cassettes/audit_logs/create_export.yml +76 -0
  156. data/spec/support/fixtures/vcr_cassettes/audit_logs/create_export_with_filters.yml +77 -0
  157. data/spec/support/fixtures/vcr_cassettes/audit_logs/get_export.yml +73 -0
  158. data/spec/support/fixtures/vcr_cassettes/audit_trail/create_event.yml +65 -0
  159. data/spec/support/fixtures/vcr_cassettes/audit_trail/create_event_custom_idempotency_key.yml +67 -0
  160. data/spec/support/fixtures/vcr_cassettes/audit_trail/create_event_invalid.yml +68 -0
  161. data/spec/support/fixtures/vcr_cassettes/audit_trail/create_events_duplicate_idempotency_key_and_payload.yml +131 -0
  162. data/spec/support/fixtures/vcr_cassettes/audit_trail/create_events_duplicate_idempotency_key_different_payload.yml +134 -0
  163. data/spec/support/fixtures/vcr_cassettes/audit_trail/get_events.yml +61 -0
  164. data/spec/support/fixtures/vcr_cassettes/base/execute_request_unauthenticated.yml +66 -0
  165. data/spec/support/fixtures/vcr_cassettes/directory_sync/delete_directory.yml +72 -0
  166. data/spec/support/fixtures/vcr_cassettes/directory_sync/get_directory_with_invalid_id.yml +83 -0
  167. data/spec/support/fixtures/vcr_cassettes/directory_sync/get_directory_with_valid_id.yml +84 -0
  168. data/spec/support/fixtures/vcr_cassettes/directory_sync/get_group.yml +80 -0
  169. data/spec/support/fixtures/vcr_cassettes/directory_sync/get_group_with_invalid_id.yml +62 -0
  170. data/spec/support/fixtures/vcr_cassettes/directory_sync/get_user.yml +83 -0
  171. data/spec/support/fixtures/vcr_cassettes/directory_sync/get_user_with_invalid_id.yml +62 -0
  172. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_after.yml +87 -0
  173. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_before.yml +89 -0
  174. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_domain.yml +84 -0
  175. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_limit.yml +85 -0
  176. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_no_options.yml +93 -0
  177. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_search.yml +85 -0
  178. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_after.yml +90 -0
  179. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_before.yml +90 -0
  180. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_directory.yml +90 -0
  181. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_limit.yml +84 -0
  182. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_no_options.yml +84 -0
  183. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_user.yml +82 -0
  184. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_after.yml +186 -0
  185. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_before.yml +88 -0
  186. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_directory.yml +194 -0
  187. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_group.yml +186 -0
  188. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_limit.yml +189 -0
  189. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_no_options.yml +74 -0
  190. data/spec/support/fixtures/vcr_cassettes/events/list_events_with_after.yml +80 -0
  191. data/spec/support/fixtures/vcr_cassettes/events/list_events_with_event.yml +80 -0
  192. data/spec/support/fixtures/vcr_cassettes/events/list_events_with_no_options.yml +80 -0
  193. data/spec/support/fixtures/vcr_cassettes/events/list_events_with_range.yml +80 -0
  194. data/spec/support/fixtures/vcr_cassettes/mfa/challenge_factor_generic_valid.yml +82 -0
  195. data/spec/support/fixtures/vcr_cassettes/mfa/challenge_factor_sms_valid.yml +82 -0
  196. data/spec/support/fixtures/vcr_cassettes/mfa/challenge_factor_totp_valid.yml +82 -0
  197. data/spec/support/fixtures/vcr_cassettes/mfa/delete_factor.yml +80 -0
  198. data/spec/support/fixtures/vcr_cassettes/mfa/enroll_factor_generic_valid.yml +82 -0
  199. data/spec/support/fixtures/vcr_cassettes/mfa/enroll_factor_sms_valid.yml +82 -0
  200. data/spec/support/fixtures/vcr_cassettes/mfa/enroll_factor_totp_valid.yml +82 -0
  201. data/spec/support/fixtures/vcr_cassettes/mfa/get_factor_invalid.yml +82 -0
  202. data/spec/support/fixtures/vcr_cassettes/mfa/get_factor_valid.yml +82 -0
  203. data/spec/support/fixtures/vcr_cassettes/mfa/verify_challenge_generic_expired.yml +84 -0
  204. data/spec/support/fixtures/vcr_cassettes/mfa/verify_challenge_generic_invalid.yml +84 -0
  205. data/spec/support/fixtures/vcr_cassettes/mfa/verify_challenge_generic_valid.yml +82 -0
  206. data/spec/support/fixtures/vcr_cassettes/mfa/verify_challenge_generic_valid_is_false.yml +82 -0
  207. data/spec/support/fixtures/vcr_cassettes/organization/create.yml +84 -0
  208. data/spec/support/fixtures/vcr_cassettes/organization/create_invalid.yml +72 -0
  209. data/spec/support/fixtures/vcr_cassettes/organization/create_with_duplicate_idempotency_key_and_different_payload.yml +155 -0
  210. data/spec/support/fixtures/vcr_cassettes/organization/create_with_duplicate_idempotency_key_and_payload.yml +154 -0
  211. data/spec/support/fixtures/vcr_cassettes/organization/create_with_idempotency_key.yml +79 -0
  212. data/spec/support/fixtures/vcr_cassettes/organization/delete.yml +72 -0
  213. data/spec/support/fixtures/vcr_cassettes/organization/delete_invalid.yml +72 -0
  214. data/spec/support/fixtures/vcr_cassettes/organization/get.yml +84 -0
  215. data/spec/support/fixtures/vcr_cassettes/organization/get_invalid.yml +72 -0
  216. data/spec/support/fixtures/vcr_cassettes/organization/list.yml +87 -0
  217. data/spec/support/fixtures/vcr_cassettes/organization/update.yml +84 -0
  218. data/spec/support/fixtures/vcr_cassettes/passwordless/create_session.yml +72 -0
  219. data/spec/support/fixtures/vcr_cassettes/passwordless/create_session_invalid.yml +73 -0
  220. data/spec/support/fixtures/vcr_cassettes/passwordless/send_session.yml +72 -0
  221. data/spec/support/fixtures/vcr_cassettes/passwordless/send_session_invalid.yml +73 -0
  222. data/spec/support/fixtures/vcr_cassettes/portal/generate_link_audit_logs.yml +72 -0
  223. data/spec/support/fixtures/vcr_cassettes/portal/generate_link_dsync.yml +72 -0
  224. data/spec/support/fixtures/vcr_cassettes/portal/generate_link_invalid.yml +72 -0
  225. data/spec/support/fixtures/vcr_cassettes/portal/generate_link_sso.yml +72 -0
  226. data/spec/support/fixtures/vcr_cassettes/sso/delete_connection_with_invalid_id.yml +72 -0
  227. data/spec/support/fixtures/vcr_cassettes/sso/delete_connection_with_valid_id.yml +70 -0
  228. data/spec/support/fixtures/vcr_cassettes/sso/get_connection_with_invalid_id.yml +72 -0
  229. data/spec/support/fixtures/vcr_cassettes/sso/get_connection_with_valid_id.yml +86 -0
  230. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_after.yml +83 -0
  231. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_before.yml +86 -0
  232. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_connection_type.yml +90 -0
  233. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_domain.yml +86 -0
  234. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_limit.yml +83 -0
  235. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_no_options.yml +89 -0
  236. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_organization_id.yml +86 -0
  237. data/spec/support/fixtures/vcr_cassettes/sso/profile.yml +74 -0
  238. data/spec/support/profile.txt +1 -0
  239. data/spec/support/shared_examples/client_spec.rb +30 -0
  240. data/spec/support/webhook_payload.txt +1 -0
  241. data/workosv2.gemspec +38 -0
  242. metadata +531 -0
@@ -0,0 +1,492 @@
1
+ # frozen_string_literal: true
2
+ # typed: false
3
+
4
+ describe WorkOSV2::DirectorySync do
5
+ it_behaves_like 'client'
6
+
7
+ describe '.list_directories' do
8
+ context 'with no options' do
9
+ it 'returns directories and metadata' do
10
+ expected_metadata = {
11
+ 'after' => nil,
12
+ 'before' => 'before-id',
13
+ }
14
+
15
+ VCR.use_cassette 'directory_sync/list_directories/with_no_options' do
16
+ directories = described_class.list_directories
17
+
18
+ expect(directories.data.size).to eq(10)
19
+ expect(directories.list_metadata).to eq(expected_metadata)
20
+ end
21
+ end
22
+ end
23
+
24
+ context 'with domain option' do
25
+ it 'forms the proper request to the API' do
26
+ request_args = [
27
+ '/directories?domain=foo-corp.com',
28
+ 'Content-Type' => 'application/json'
29
+ ]
30
+
31
+ expected_request = Net::HTTP::Get.new(*request_args)
32
+
33
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
34
+ and_return(expected_request)
35
+
36
+ VCR.use_cassette 'directory_sync/list_directories/with_domain' do
37
+ directories = described_class.list_directories(
38
+ domain: 'foo-corp.com',
39
+ )
40
+
41
+ expect(directories.data.size).to eq(1)
42
+ end
43
+ end
44
+ end
45
+
46
+ context 'with search option' do
47
+ it 'forms the proper request to the API' do
48
+ request_args = [
49
+ '/directories?search=Testing',
50
+ 'Content-Type' => 'application/json'
51
+ ]
52
+
53
+ expected_request = Net::HTTP::Get.new(*request_args)
54
+
55
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
56
+ and_return(expected_request)
57
+
58
+ VCR.use_cassette 'directory_sync/list_directories/with_search' do
59
+ directories = described_class.list_directories(
60
+ search: 'Testing',
61
+ )
62
+
63
+ expect(directories.data.size).to eq(2)
64
+ expect(directories.data[0].name).to include('Testing')
65
+ end
66
+ end
67
+ end
68
+
69
+ context 'with the before option' do
70
+ it 'forms the proper request to the API' do
71
+ request_args = [
72
+ '/directories?before=directory_01FGCPNV312FHFRCX0BYWHVSE1',
73
+ 'Content-Type' => 'application/json'
74
+ ]
75
+
76
+ expected_request = Net::HTTP::Get.new(*request_args)
77
+
78
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
79
+ and_return(expected_request)
80
+
81
+ VCR.use_cassette 'directory_sync/list_directories/with_before' do
82
+ directories = described_class.list_directories(
83
+ before: 'directory_01FGCPNV312FHFRCX0BYWHVSE1',
84
+ )
85
+
86
+ expect(directories.data.size).to eq(6)
87
+ end
88
+ end
89
+ end
90
+
91
+ context 'with the after option' do
92
+ it 'forms the proper request to the API' do
93
+ request_args = [
94
+ '/directories?after=directory_01FGCPNV312FHFRCX0BYWHVSE1',
95
+ 'Content-Type' => 'application/json'
96
+ ]
97
+
98
+ expected_request = Net::HTTP::Get.new(*request_args)
99
+
100
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
101
+ and_return(expected_request)
102
+
103
+ VCR.use_cassette 'directory_sync/list_directories/with_after' do
104
+ directories = described_class.list_directories(after: 'directory_01FGCPNV312FHFRCX0BYWHVSE1')
105
+
106
+ expect(directories.data.size).to eq(4)
107
+ end
108
+ end
109
+ end
110
+
111
+ context 'with the limit option' do
112
+ it 'forms the proper request to the API' do
113
+ request_args = [
114
+ '/directories?limit=2',
115
+ 'Content-Type' => 'application/json'
116
+ ]
117
+
118
+ expected_request = Net::HTTP::Get.new(*request_args)
119
+
120
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
121
+ and_return(expected_request)
122
+
123
+ VCR.use_cassette 'directory_sync/list_directories/with_limit' do
124
+ directories = described_class.list_directories(limit: 2)
125
+
126
+ expect(directories.data.size).to eq(2)
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+ describe '.delete_directory' do
133
+ context 'with valid id' do
134
+ it 'deletes a directory' do
135
+ VCR.use_cassette('directory_sync/delete_directory') do
136
+ response = WorkOSV2::DirectorySync.delete_directory(
137
+ 'directory_01F2T098SKN5PCTVSJ7CWP70N5',
138
+ )
139
+
140
+ expect(response).to be(true)
141
+ end
142
+ end
143
+ end
144
+ end
145
+
146
+ describe '.get_directory' do
147
+ context 'with a valid id' do
148
+ it 'gets the directory details' do
149
+ VCR.use_cassette('directory_sync/get_directory_with_valid_id') do
150
+ directory = WorkOSV2::DirectorySync.get_directory(
151
+ id: 'directory_01FK17DWRHH7APAFXT5B52PV0W',
152
+ )
153
+
154
+ expect(directory.id).to eq('directory_01FK17DWRHH7APAFXT5B52PV0W')
155
+ expect(directory.name).to eq('Testing Active Attribute')
156
+ expect(directory.domain).to eq('example.me')
157
+ expect(directory.type).to eq('azure scim v2.0')
158
+ expect(directory.state).to eq('linked')
159
+ expect(directory.organization_id).to eq('org_01F6Q6TFP7RD2PF6J03ANNWDKV')
160
+ end
161
+ end
162
+ end
163
+
164
+ context 'with an invalid id' do
165
+ it 'raises an error' do
166
+ VCR.use_cassette('directory_sync/get_directory_with_invalid_id') do
167
+ expect do
168
+ WorkOSV2::DirectorySync.get_directory(id: 'invalid')
169
+ end.to raise_error(
170
+ WorkOSV2::APIError,
171
+ "Status 404, Directory not found: 'invalid'. - request ID: ",
172
+ )
173
+ end
174
+ end
175
+ end
176
+ end
177
+
178
+ describe '.list_groups' do
179
+ context 'with no options' do
180
+ it 'raises an error' do
181
+ VCR.use_cassette('directory_sync/list_groups/with_no_options') do
182
+ expect do
183
+ WorkOSV2::DirectorySync.list_groups
184
+ end.to raise_error(WorkOSV2::InvalidRequestError)
185
+ end
186
+ end
187
+ end
188
+
189
+ context 'with directory option' do
190
+ it 'forms the proper request to the API' do
191
+ request_args = [
192
+ '/directory_groups?directory=directory_01G2Z8ADK5NPMVTWF48MVVE4HT',
193
+ 'Content-Type' => 'application/json'
194
+ ]
195
+
196
+ expected_request = Net::HTTP::Get.new(*request_args)
197
+
198
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
199
+ and_return(expected_request)
200
+
201
+ VCR.use_cassette 'directory_sync/list_groups/with_directory' do
202
+ groups = described_class.list_groups(
203
+ directory: 'directory_01G2Z8ADK5NPMVTWF48MVVE4HT',
204
+ )
205
+
206
+ expect(groups.data.size).to eq(10)
207
+ expect(groups.data[0].name).to eq(groups.data[0]['name'])
208
+ end
209
+ end
210
+ end
211
+
212
+ context 'with user option' do
213
+ it 'forms the proper request to the API' do
214
+ request_args = [
215
+ '/directory_groups?user=directory_user_01G2Z8D4FDB28ZNSRRBVCF2E0P',
216
+ 'Content-Type' => 'application/json'
217
+ ]
218
+
219
+ expected_request = Net::HTTP::Get.new(*request_args)
220
+
221
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
222
+ and_return(expected_request)
223
+
224
+ VCR.use_cassette 'directory_sync/list_groups/with_user' do
225
+ groups = described_class.list_groups(
226
+ user: 'directory_user_01G2Z8D4FDB28ZNSRRBVCF2E0P',
227
+ )
228
+
229
+ expect(groups.data.size).to eq(3)
230
+ end
231
+ end
232
+ end
233
+
234
+ context 'with the before option' do
235
+ it 'forms the proper request to the API' do
236
+ request_args = [
237
+ '/directory_groups?before=directory_group_01G2Z8D4ZR8RJ03Y1W7P9K8NMG&' \
238
+ 'directory=directory_01G2Z8ADK5NPMVTWF48MVVE4HT',
239
+ 'Content-Type' => 'application/json'
240
+ ]
241
+
242
+ expected_request = Net::HTTP::Get.new(*request_args)
243
+
244
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
245
+ and_return(expected_request)
246
+
247
+ VCR.use_cassette 'directory_sync/list_groups/with_before' do
248
+ groups = described_class.list_groups(
249
+ before: 'directory_group_01G2Z8D4ZR8RJ03Y1W7P9K8NMG',
250
+ directory: 'directory_01G2Z8ADK5NPMVTWF48MVVE4HT',
251
+ )
252
+
253
+ expect(groups.data.size).to eq(10)
254
+ end
255
+ end
256
+ end
257
+
258
+ context 'with the after option' do
259
+ it 'forms the proper request to the API' do
260
+ request_args = [
261
+ '/directory_groups?after=directory_group_01G2Z8D4ZR8RJ03Y1W7P9K8NMG&' \
262
+ 'directory=directory_01G2Z8ADK5NPMVTWF48MVVE4HT',
263
+ 'Content-Type' => 'application/json'
264
+ ]
265
+
266
+ expected_request = Net::HTTP::Get.new(*request_args)
267
+
268
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
269
+ and_return(expected_request)
270
+
271
+ VCR.use_cassette 'directory_sync/list_groups/with_after' do
272
+ groups = described_class.list_groups(
273
+ after: 'directory_group_01G2Z8D4ZR8RJ03Y1W7P9K8NMG',
274
+ directory: 'directory_01G2Z8ADK5NPMVTWF48MVVE4HT',
275
+ )
276
+
277
+ expect(groups.data.size).to eq(9)
278
+ end
279
+ end
280
+ end
281
+
282
+ context 'with the limit option' do
283
+ it 'forms the proper request to the API' do
284
+ request_args = [
285
+ '/directory_groups?limit=2&' \
286
+ 'directory=directory_01G2Z8ADK5NPMVTWF48MVVE4HT',
287
+ 'Content-Type' => 'application/json'
288
+ ]
289
+
290
+ expected_request = Net::HTTP::Get.new(*request_args)
291
+
292
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
293
+ and_return(expected_request)
294
+
295
+ VCR.use_cassette 'directory_sync/list_groups/with_limit' do
296
+ groups = described_class.list_groups(
297
+ limit: 2,
298
+ directory: 'directory_01G2Z8ADK5NPMVTWF48MVVE4HT',
299
+ )
300
+
301
+ expect(groups.data.size).to eq(2)
302
+ end
303
+ end
304
+ end
305
+ end
306
+
307
+ describe '.list_users' do
308
+ context 'with no options' do
309
+ it 'raises an error' do
310
+ VCR.use_cassette('directory_sync/list_users/with_no_options') do
311
+ expect do
312
+ WorkOSV2::DirectorySync.list_users
313
+ end.to raise_error(WorkOSV2::InvalidRequestError)
314
+ end
315
+ end
316
+ end
317
+
318
+ context 'with directory option' do
319
+ it 'forms the proper request to the API' do
320
+ request_args = [
321
+ '/directory_users?directory=directory_01FAZYMST676QMTFN1DDJZZX87',
322
+ 'Content-Type' => 'application/json'
323
+ ]
324
+
325
+ expected_request = Net::HTTP::Get.new(*request_args)
326
+
327
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
328
+ and_return(expected_request)
329
+
330
+ VCR.use_cassette 'directory_sync/list_users/with_directory' do
331
+ users = described_class.list_users(
332
+ directory: 'directory_01FAZYMST676QMTFN1DDJZZX87',
333
+ )
334
+
335
+ expect(users.data.size).to eq(4)
336
+ expect(users.data[0].first_name).to eq(users.data[0]['first_name'])
337
+ end
338
+ end
339
+ end
340
+
341
+ context 'with group option' do
342
+ it 'forms the proper request to the API' do
343
+ request_args = [
344
+ '/directory_users?group=directory_group_01FBXGP79EJAYKW0WS9JCK1V6E',
345
+ 'Content-Type' => 'application/json'
346
+ ]
347
+
348
+ expected_request = Net::HTTP::Get.new(*request_args)
349
+
350
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
351
+ and_return(expected_request)
352
+
353
+ VCR.use_cassette 'directory_sync/list_users/with_group' do
354
+ users = described_class.list_users(
355
+ group: 'directory_group_01FBXGP79EJAYKW0WS9JCK1V6E',
356
+ )
357
+
358
+ expect(users.data.size).to eq(1)
359
+ end
360
+ end
361
+ end
362
+
363
+ context 'with the before option' do
364
+ it 'forms the proper request to the API' do
365
+ request_args = [
366
+ '/directory_users?before=directory_user_01FAZYNPC8TJBP7Y2ERT51MGDF&'\
367
+ 'directory=directory_01FAZYMST676QMTFN1DDJZZX87',
368
+ 'Content-Type' => 'application/json'
369
+ ]
370
+
371
+ expected_request = Net::HTTP::Get.new(*request_args)
372
+
373
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
374
+ and_return(expected_request)
375
+
376
+ VCR.use_cassette 'directory_sync/list_users/with_before' do
377
+ users = described_class.list_users(
378
+ before: 'directory_user_01FAZYNPC8TJBP7Y2ERT51MGDF',
379
+ directory: 'directory_01FAZYMST676QMTFN1DDJZZX87',
380
+ )
381
+
382
+ expect(users.data.size).to eq(2)
383
+ end
384
+ end
385
+ end
386
+
387
+ context 'with the after option' do
388
+ it 'forms the proper request to the API' do
389
+ request_args = [
390
+ '/directory_users?after=directory_user_01FAZYNPC8TJBP7Y2ERT51MGDF&' \
391
+ 'directory=directory_01FAZYMST676QMTFN1DDJZZX87',
392
+ 'Content-Type' => 'application/json'
393
+ ]
394
+
395
+ expected_request = Net::HTTP::Get.new(*request_args)
396
+
397
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
398
+ and_return(expected_request)
399
+
400
+ VCR.use_cassette 'directory_sync/list_users/with_after' do
401
+ users = described_class.list_users(
402
+ after: 'directory_user_01FAZYNPC8TJBP7Y2ERT51MGDF',
403
+ directory: 'directory_01FAZYMST676QMTFN1DDJZZX87',
404
+ )
405
+
406
+ expect(users.data.size).to eq(1)
407
+ end
408
+ end
409
+ end
410
+
411
+ context 'with the limit option' do
412
+ it 'forms the proper request to the API' do
413
+ request_args = [
414
+ '/directory_users?limit=2&' \
415
+ 'directory=directory_01FAZYMST676QMTFN1DDJZZX87',
416
+ 'Content-Type' => 'application/json'
417
+ ]
418
+
419
+ expected_request = Net::HTTP::Get.new(*request_args)
420
+
421
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
422
+ and_return(expected_request)
423
+
424
+ VCR.use_cassette 'directory_sync/list_users/with_limit' do
425
+ users = described_class.list_users(
426
+ limit: 2,
427
+ directory: 'directory_01FAZYMST676QMTFN1DDJZZX87',
428
+ )
429
+
430
+ expect(users.data.size).to eq(2)
431
+ end
432
+ end
433
+ end
434
+ end
435
+
436
+ describe '.get_group' do
437
+ context 'with valid id' do
438
+ it 'returns a group' do
439
+ VCR.use_cassette('directory_sync/get_group') do
440
+ group = WorkOSV2::DirectorySync.get_group(
441
+ 'directory_group_01G2Z8D4ZR8RJ03Y1W7P9K8NMG',
442
+ )
443
+
444
+ expect(group['directory_id']).to eq('directory_01G2Z8ADK5NPMVTWF48MVVE4HT')
445
+ expect(group['organization_id']).to eq('org_01EGS4P7QR31EZ4YWD1Z1XA176')
446
+ expect(group['idp_id']).to eq('01jlao4614two3d')
447
+ expect(group['name']).to eq('Sales')
448
+ expect(group.name).to eq('Sales')
449
+ expect(group['created_at']).to eq('2022-05-13T17:45:31.732Z')
450
+ expect(group['updated_at']).to eq('2022-07-13T17:45:42.618Z')
451
+ end
452
+ end
453
+ end
454
+
455
+ context 'with invalid id' do
456
+ it 'raises an error' do
457
+ VCR.use_cassette('directory_sync/get_group_with_invalid_id') do
458
+ expect do
459
+ WorkOSV2::DirectorySync.get_group('invalid')
460
+ end.to raise_error(WorkOSV2::APIError)
461
+ end
462
+ end
463
+ end
464
+ end
465
+
466
+ describe '.get_user' do
467
+ context 'with valid id' do
468
+ it 'returns a user' do
469
+ VCR.use_cassette('directory_sync/get_user') do
470
+ user = WorkOSV2::DirectorySync.get_user(
471
+ 'directory_user_01FAZYNPC8M0HRYTKFP2GNX852',
472
+ )
473
+
474
+ expect(user['first_name']).to eq('Logan')
475
+ expect(user.directory_id).to eq('directory_01FAZYMST676QMTFN1DDJZZX87')
476
+ expect(user.organization_id).to eq('org_01FAZWCWR03DVWA83NCJYKKD54')
477
+ expect(user.first_name).to eq('Logan')
478
+ end
479
+ end
480
+ end
481
+
482
+ context 'with invalid id' do
483
+ it 'raises an error' do
484
+ VCR.use_cassette('directory_sync/get_user_with_invalid_id') do
485
+ expect do
486
+ WorkOSV2::DirectorySync.get_user('invalid')
487
+ end.to raise_error(WorkOSV2::APIError)
488
+ end
489
+ end
490
+ end
491
+ end
492
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+ # typed: false
3
+
4
+ describe WorkOSV2::DirectoryUser do
5
+ # rubocop:disable Layout/LineLength
6
+ describe '.get_primary_email' do
7
+ context 'with one primary email' do
8
+ it 'returns the primary email' do
9
+ user = WorkOSV2::DirectoryUser.new('{"object":"directory_user","id":"directory_user_01FAZYNPC8M0HRYTKFP2GNX852","directory_id":"directory_01FAZYMST676QMTFN1DDJZZX87","idp_id":"6092c280a3f1e19ef6d8cef8","username":"logan@workos.com","emails":[{"primary":true,"value":"logan@workos.com"}, {"primary":false,"value":"logan@gmail.com"}],"first_name":"Logan","last_name":"Gingerich","job_title":"Developer Success Engineer","state":"active","raw_attributes":{},"custom_attributes":{},"groups":[],"created_at":"2022-05-13T17:45:31.732Z", "updated_at":"2022-07-13T17:45:42.618Z"}')
10
+ expect(user.primary_email).to eq('logan@workos.com')
11
+ end
12
+ end
13
+
14
+ context 'with multiple primary emails' do
15
+ it 'returns the first email marked as primary' do
16
+ user = WorkOSV2::DirectoryUser.new('{"object":"directory_user","id":"directory_user_01FAZYNPC8M0HRYTKFP2GNX852","directory_id":"directory_01FAZYMST676QMTFN1DDJZZX87","idp_id":"6092c280a3f1e19ef6d8cef8","username":"logan@workos.com","emails":[{"primary":true,"value":"logan@workos.com"}, {"primary":true,"value":"logan@gmail.com"}],"first_name":"Logan","last_name":"Gingerich","job_title":"Developer Success Engineer","state":"active","raw_attributes":{},"custom_attributes":{},"groups":[],"created_at":"2022-05-13T17:45:31.732Z", "updated_at":"2022-07-13T17:45:42.618Z"}')
17
+ expect(user.primary_email).to eq('logan@workos.com')
18
+ end
19
+ end
20
+
21
+ context 'with no primary emails' do
22
+ it 'returns nil' do
23
+ user = WorkOSV2::DirectoryUser.new('{"object":"directory_user","id":"directory_user_01FAZYNPC8M0HRYTKFP2GNX852","directory_id":"directory_01FAZYMST676QMTFN1DDJZZX87","idp_id":"6092c280a3f1e19ef6d8cef8","username":"logan@workos.com","emails":[{"primary":false,"value":"logan@gmail.com"}],"first_name":"Logan","last_name":"Gingerich","job_title":"Developer Success Engineer","state":"active","raw_attributes":{},"custom_attributes":{},"groups":[],"created_at":"2022-05-13T17:45:31.732Z","updated_at":"2022-07-13T17:45:42.618Z"}')
24
+ expect(user.primary_email).to eq(nil)
25
+ end
26
+ end
27
+
28
+ context 'with an empty email array' do
29
+ it 'returns nil' do
30
+ user = WorkOSV2::DirectoryUser.new('{"object":"directory_user","id":"directory_user_01FAZYNPC8M0HRYTKFP2GNX852","directory_id":"directory_01FAZYMST676QMTFN1DDJZZX87","idp_id":"6092c280a3f1e19ef6d8cef8","username":"logan@workos.com","emails":[],"first_name":"Logan","last_name":"Gingerich","job_title":"Developer Success Engineer","state":"active","raw_attributes":{},"custom_attributes":{},"groups":[],"created_at":"2022-05-13T17:45:31.732Z","updated_at":"2022-07-13T17:45:42.618Z"}')
31
+ expect(user.primary_email).to eq(nil)
32
+ end
33
+ end
34
+ end
35
+ # rubocop:enable Layout/LineLength
36
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+ # typed: false
3
+
4
+ describe WorkOSV2::Events do
5
+ it_behaves_like 'client'
6
+
7
+ describe '.list_events' do
8
+ context 'with no options' do
9
+ it 'returns events and metadata' do
10
+ expected_metadata = {
11
+ 'after' => nil,
12
+ }
13
+
14
+ VCR.use_cassette 'events/list_events_with_no_options' do
15
+ events = described_class.list_events
16
+
17
+ expect(events.data.size).to eq(1)
18
+ expect(events.list_metadata).to eq(expected_metadata)
19
+ end
20
+ end
21
+ end
22
+
23
+ context 'with event option' do
24
+ it 'forms the proper request to the API' do
25
+ request_args = [
26
+ '/events?events=connection.activated',
27
+ 'Content-Type' => 'application/json'
28
+ ]
29
+
30
+ expected_request = Net::HTTP::Get.new(*request_args)
31
+
32
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
33
+ and_return(expected_request)
34
+
35
+ VCR.use_cassette 'events/list_events_with_event' do
36
+ events = described_class.list_events(
37
+ events: ['connection.activated'],
38
+ )
39
+
40
+ expect(events.data.size).to eq(1)
41
+ end
42
+ end
43
+ end
44
+
45
+ context 'with the after option' do
46
+ it 'forms the proper request to the API' do
47
+ request_args = [
48
+ '/events?after=event_01FGCPNV312FHFRCX0BYWHVSE1',
49
+ 'Content-Type' => 'application/json'
50
+ ]
51
+
52
+ expected_request = Net::HTTP::Get.new(*request_args)
53
+
54
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
55
+ and_return(expected_request)
56
+
57
+ VCR.use_cassette 'events/list_events_with_after' do
58
+ events = described_class.list_events(after: 'event_01FGCPNV312FHFRCX0BYWHVSE1')
59
+
60
+ expect(events.data.size).to eq(1)
61
+ end
62
+ end
63
+ end
64
+
65
+ context 'with the range_start and range_end options' do
66
+ it 'forms the proper request to the API' do
67
+ request_args = [
68
+ '/events?range_start=2023-01-01T00%3A00%3A00Z&range_end=2023-01-03T00%3A00%3A00Z',
69
+ 'Content-Type' => 'application/json'
70
+ ]
71
+
72
+ expected_request = Net::HTTP::Get.new(*request_args)
73
+
74
+ expect(Net::HTTP::Get).to receive(:new).with(*request_args).
75
+ and_return(expected_request)
76
+
77
+ VCR.use_cassette 'events/list_events_with_range' do
78
+ events = described_class.list_events(
79
+ range_start: '2023-01-01T00:00:00Z',
80
+ range_end: '2023-01-03T00:00:00Z',
81
+ )
82
+
83
+ expect(events.data.size).to eq(1)
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end