Skip to content

Commit 1931e3f

Browse files
authored
Add ability to resend invitations (#404)
1 parent 8d75d32 commit 1931e3f

File tree

7 files changed

+506
-0
lines changed

7 files changed

+506
-0
lines changed

lib/workos/user_management.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,22 @@ def revoke_invitation(id:)
11391139
WorkOS::Invitation.new(response.body)
11401140
end
11411141

1142+
# Resends an existing Invitation.
1143+
#
1144+
# @param [String] id The unique ID of the Invitation.
1145+
#
1146+
# @return WorkOS::Invitation
1147+
def resend_invitation(id:)
1148+
request = post_request(
1149+
path: "/user_management/invitations/#{id}/resend",
1150+
auth: true,
1151+
)
1152+
1153+
response = execute_request(request: request)
1154+
1155+
WorkOS::Invitation.new(response.body)
1156+
end
1157+
11421158
private
11431159

11441160
def validate_session(session)

spec/lib/workos/user_management_spec.rb

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,81 @@
16931693
end
16941694
end
16951695

1696+
describe '.resend_invitation' do
1697+
context 'with valid payload' do
1698+
it 'resends invitation' do
1699+
VCR.use_cassette 'user_management/resend_invitation/valid' do
1700+
invitation = described_class.resend_invitation(
1701+
id: 'invitation_01H5JQDV7R7ATEYZDEG0W5PRYS',
1702+
)
1703+
1704+
expect(invitation.id).to eq('invitation_01H5JQDV7R7ATEYZDEG0W5PRYS')
1705+
expect(invitation.email).to eq('[email protected]')
1706+
end
1707+
end
1708+
end
1709+
1710+
context 'with an invalid id' do
1711+
it 'returns an error' do
1712+
VCR.use_cassette 'user_management/resend_invitation/invalid' do
1713+
expect do
1714+
described_class.resend_invitation(
1715+
id: 'invalid_id',
1716+
)
1717+
end.to raise_error(
1718+
WorkOS::NotFoundError,
1719+
/Invitation not found/,
1720+
)
1721+
end
1722+
end
1723+
end
1724+
1725+
context 'when invitation has expired' do
1726+
it 'returns an error' do
1727+
VCR.use_cassette 'user_management/resend_invitation/expired' do
1728+
expect do
1729+
described_class.resend_invitation(
1730+
id: 'invitation_01H5JQDV7R7ATEYZDEG0W5PRYS',
1731+
)
1732+
end.to raise_error(
1733+
WorkOS::InvalidRequestError,
1734+
/Invite has expired/,
1735+
)
1736+
end
1737+
end
1738+
end
1739+
1740+
context 'when invitation has been revoked' do
1741+
it 'returns an error' do
1742+
VCR.use_cassette 'user_management/resend_invitation/revoked' do
1743+
expect do
1744+
described_class.resend_invitation(
1745+
id: 'invitation_01H5JQDV7R7ATEYZDEG0W5PRYS',
1746+
)
1747+
end.to raise_error(
1748+
WorkOS::InvalidRequestError,
1749+
/Invite has been revoked/,
1750+
)
1751+
end
1752+
end
1753+
end
1754+
1755+
context 'when invitation has already been accepted' do
1756+
it 'returns an error' do
1757+
VCR.use_cassette 'user_management/resend_invitation/accepted' do
1758+
expect do
1759+
described_class.resend_invitation(
1760+
id: 'invitation_01H5JQDV7R7ATEYZDEG0W5PRYS',
1761+
)
1762+
end.to raise_error(
1763+
WorkOS::InvalidRequestError,
1764+
/Invite has already been accepted/,
1765+
)
1766+
end
1767+
end
1768+
end
1769+
end
1770+
16961771
describe '.revoke_session' do
16971772
context 'with valid payload' do
16981773
it 'revokes session' do
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
http_interactions:
3+
- request:
4+
method: post
5+
uri: https://api.workos.com/user_management/invitations/invitation_01H5JQDV7R7ATEYZDEG0W5PRYS/resend
6+
body:
7+
encoding: UTF-8
8+
string: ''
9+
headers:
10+
Content-Type:
11+
- application/json
12+
Accept-Encoding:
13+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14+
Accept:
15+
- "*/*"
16+
User-Agent:
17+
- WorkOS; ruby/3.0.2; arm64-darwin22; v2.16.0
18+
Authorization:
19+
- Bearer <API_KEY>
20+
response:
21+
status:
22+
code: 400
23+
message: Bad Request
24+
headers:
25+
Date:
26+
- Mon, 17 Nov 2025 18:28:05 GMT
27+
Content-Type:
28+
- application/json; charset=utf-8
29+
Transfer-Encoding:
30+
- chunked
31+
Connection:
32+
- keep-alive
33+
Cf-Ray:
34+
- 7fa4ef0eeafe8c12-EWR
35+
Cf-Cache-Status:
36+
- DYNAMIC
37+
Etag:
38+
- W/"56-2Auj80JGmZ1uWGCY950ud8v4KLQ"
39+
Strict-Transport-Security:
40+
- max-age=15552000; includeSubDomains
41+
Vary:
42+
- Origin, Accept-Encoding
43+
Via:
44+
- 1.1 spaces-router (devel)
45+
Access-Control-Allow-Credentials:
46+
- 'true'
47+
Content-Security-Policy:
48+
- 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self''
49+
https: data:;frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src
50+
''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests'
51+
Expect-Ct:
52+
- max-age=0
53+
Referrer-Policy:
54+
- no-referrer
55+
X-Content-Type-Options:
56+
- nosniff
57+
X-Dns-Prefetch-Control:
58+
- 'off'
59+
X-Download-Options:
60+
- noopen
61+
X-Frame-Options:
62+
- SAMEORIGIN
63+
X-Permitted-Cross-Domain-Policies:
64+
- none
65+
X-Request-Id:
66+
- f5f06564-2f73-4b73-989b-b577cfbdaa9a
67+
X-Xss-Protection:
68+
- '0'
69+
Set-Cookie:
70+
- __cf_bm=v55WlV2dq1rXkfx9668LFtglSD5c9292fFLKsviMegY-1692642485-0-AWmCDzQSIwCjWvanffzmFA5KJT/nWucOWyv7i3fyyXeH+i5iM9ZusABSbNOUR6zO2mcugNYr/TRj6ltRmm8eC3M=;
71+
path=/; expires=Mon, 21-Aug-23 18:58:05 GMT; domain=.workos.com; HttpOnly;
72+
Secure; SameSite=None
73+
- __cfruid=bea6b3e4c8ea6479881eb565b1ab9a0b6deabae9-1692642485; path=/; domain=.workos.com;
74+
HttpOnly; Secure; SameSite=None
75+
Server:
76+
- cloudflare
77+
body:
78+
encoding: ASCII-8BIT
79+
string: '{"code":"invite_accepted","message":"Invite has already been accepted."}'
80+
http_version:
81+
recorded_at: Mon, 17 Nov 2025 18:28:05 GMT
82+
recorded_with: VCR 5.0.0
83+
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
http_interactions:
3+
- request:
4+
method: post
5+
uri: https://api.workos.com/user_management/invitations/invitation_01H5JQDV7R7ATEYZDEG0W5PRYS/resend
6+
body:
7+
encoding: UTF-8
8+
string: ''
9+
headers:
10+
Content-Type:
11+
- application/json
12+
Accept-Encoding:
13+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14+
Accept:
15+
- "*/*"
16+
User-Agent:
17+
- WorkOS; ruby/3.0.2; arm64-darwin22; v2.16.0
18+
Authorization:
19+
- Bearer <API_KEY>
20+
response:
21+
status:
22+
code: 400
23+
message: Bad Request
24+
headers:
25+
Date:
26+
- Mon, 17 Nov 2025 18:28:05 GMT
27+
Content-Type:
28+
- application/json; charset=utf-8
29+
Transfer-Encoding:
30+
- chunked
31+
Connection:
32+
- keep-alive
33+
Cf-Ray:
34+
- 7fa4ef0eeafe8c12-EWR
35+
Cf-Cache-Status:
36+
- DYNAMIC
37+
Etag:
38+
- W/"56-2Auj80JGmZ1uWGCY950ud8v4KLQ"
39+
Strict-Transport-Security:
40+
- max-age=15552000; includeSubDomains
41+
Vary:
42+
- Origin, Accept-Encoding
43+
Via:
44+
- 1.1 spaces-router (devel)
45+
Access-Control-Allow-Credentials:
46+
- 'true'
47+
Content-Security-Policy:
48+
- 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self''
49+
https: data:;frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src
50+
''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests'
51+
Expect-Ct:
52+
- max-age=0
53+
Referrer-Policy:
54+
- no-referrer
55+
X-Content-Type-Options:
56+
- nosniff
57+
X-Dns-Prefetch-Control:
58+
- 'off'
59+
X-Download-Options:
60+
- noopen
61+
X-Frame-Options:
62+
- SAMEORIGIN
63+
X-Permitted-Cross-Domain-Policies:
64+
- none
65+
X-Request-Id:
66+
- f5f06564-2f73-4b73-989b-b577cfbdaa9a
67+
X-Xss-Protection:
68+
- '0'
69+
Set-Cookie:
70+
- __cf_bm=v55WlV2dq1rXkfx9668LFtglSD5c9292fFLKsviMegY-1692642485-0-AWmCDzQSIwCjWvanffzmFA5KJT/nWucOWyv7i3fyyXeH+i5iM9ZusABSbNOUR6zO2mcugNYr/TRj6ltRmm8eC3M=;
71+
path=/; expires=Mon, 21-Aug-23 18:58:05 GMT; domain=.workos.com; HttpOnly;
72+
Secure; SameSite=None
73+
- __cfruid=bea6b3e4c8ea6479881eb565b1ab9a0b6deabae9-1692642485; path=/; domain=.workos.com;
74+
HttpOnly; Secure; SameSite=None
75+
Server:
76+
- cloudflare
77+
body:
78+
encoding: ASCII-8BIT
79+
string: '{"code":"invite_expired","message":"Invite has expired."}'
80+
http_version:
81+
recorded_at: Mon, 17 Nov 2025 18:28:05 GMT
82+
recorded_with: VCR 5.0.0
83+
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
http_interactions:
3+
- request:
4+
method: post
5+
uri: https://api.workos.com/user_management/invitations/invalid_id/resend
6+
body:
7+
encoding: UTF-8
8+
string: ''
9+
headers:
10+
Content-Type:
11+
- application/json
12+
Accept-Encoding:
13+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14+
Accept:
15+
- "*/*"
16+
User-Agent:
17+
- WorkOS; ruby/3.0.2; arm64-darwin22; v2.16.0
18+
Authorization:
19+
- Bearer <API_KEY>
20+
response:
21+
status:
22+
code: 404
23+
message: Not Found
24+
headers:
25+
Date:
26+
- Mon, 17 Nov 2025 18:28:05 GMT
27+
Content-Type:
28+
- application/json; charset=utf-8
29+
Transfer-Encoding:
30+
- chunked
31+
Connection:
32+
- keep-alive
33+
Cf-Ray:
34+
- 7fa4ef0eeafe8c12-EWR
35+
Cf-Cache-Status:
36+
- DYNAMIC
37+
Etag:
38+
- W/"56-2Auj80JGmZ1uWGCY950ud8v4KLQ"
39+
Strict-Transport-Security:
40+
- max-age=15552000; includeSubDomains
41+
Vary:
42+
- Origin, Accept-Encoding
43+
Via:
44+
- 1.1 spaces-router (devel)
45+
Access-Control-Allow-Credentials:
46+
- 'true'
47+
Content-Security-Policy:
48+
- 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self''
49+
https: data:;frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src
50+
''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests'
51+
Expect-Ct:
52+
- max-age=0
53+
Referrer-Policy:
54+
- no-referrer
55+
X-Content-Type-Options:
56+
- nosniff
57+
X-Dns-Prefetch-Control:
58+
- 'off'
59+
X-Download-Options:
60+
- noopen
61+
X-Frame-Options:
62+
- SAMEORIGIN
63+
X-Permitted-Cross-Domain-Policies:
64+
- none
65+
X-Request-Id:
66+
- f5f06564-2f73-4b73-989b-b577cfbdaa9a
67+
X-Xss-Protection:
68+
- '0'
69+
Set-Cookie:
70+
- __cf_bm=v55WlV2dq1rXkfx9668LFtglSD5c9292fFLKsviMegY-1692642485-0-AWmCDzQSIwCjWvanffzmFA5KJT/nWucOWyv7i3fyyXeH+i5iM9ZusABSbNOUR6zO2mcugNYr/TRj6ltRmm8eC3M=;
71+
path=/; expires=Mon, 21-Aug-23 18:58:05 GMT; domain=.workos.com; HttpOnly;
72+
Secure; SameSite=None
73+
- __cfruid=bea6b3e4c8ea6479881eb565b1ab9a0b6deabae9-1692642485; path=/; domain=.workos.com;
74+
HttpOnly; Secure; SameSite=None
75+
Server:
76+
- cloudflare
77+
body:
78+
encoding: ASCII-8BIT
79+
string: '{"message":"Invitation not found: ''invalid_id''.","code":"entity_not_found","entity_id":"bad_id"}'
80+
http_version:
81+
recorded_at: Mon, 17 Nov 2025 18:28:05 GMT
82+
recorded_with: VCR 5.0.0
83+

0 commit comments

Comments
 (0)