|
1728 | 1728 | end |
1729 | 1729 | end |
1730 | 1730 |
|
| 1731 | + describe '.accept_invitation' do |
| 1732 | + context 'with a valid id' do |
| 1733 | + it 'accepts invitation' do |
| 1734 | + expect(described_class).to receive(:post_request) do |options| |
| 1735 | + expect(options[:path]).to eq('/user_management/invitations/invitation_123/accept') |
| 1736 | + expect(options[:auth]).to be true |
| 1737 | + |
| 1738 | + double('request') |
| 1739 | + end.and_return(double('request')) |
| 1740 | + |
| 1741 | + response_body = { |
| 1742 | + id: 'invitation_123', |
| 1743 | + email: 'test@workos.com', |
| 1744 | + state: 'accepted', |
| 1745 | + }.to_json |
| 1746 | + |
| 1747 | + expect(described_class).to receive(:execute_request).and_return( |
| 1748 | + double('response', body: response_body), |
| 1749 | + ) |
| 1750 | + |
| 1751 | + invitation = described_class.accept_invitation( |
| 1752 | + id: 'invitation_123', |
| 1753 | + ) |
| 1754 | + |
| 1755 | + expect(invitation.id).to eq('invitation_123') |
| 1756 | + expect(invitation.email).to eq('test@workos.com') |
| 1757 | + expect(invitation.state).to eq('accepted') |
| 1758 | + end |
| 1759 | + end |
| 1760 | + |
| 1761 | + context 'with an invalid id' do |
| 1762 | + it 'returns an error' do |
| 1763 | + expect(described_class).to receive(:post_request) do |options| |
| 1764 | + expect(options[:path]).to eq('/user_management/invitations/invalid_id/accept') |
| 1765 | + expect(options[:auth]).to be true |
| 1766 | + |
| 1767 | + double('request') |
| 1768 | + end.and_return(double('request')) |
| 1769 | + |
| 1770 | + expect(described_class).to receive(:execute_request).and_raise( |
| 1771 | + WorkOS::NotFoundError.new(message: 'Invitation not found'), |
| 1772 | + ) |
| 1773 | + |
| 1774 | + expect do |
| 1775 | + described_class.accept_invitation(id: 'invalid_id') |
| 1776 | + end.to raise_error( |
| 1777 | + WorkOS::NotFoundError, |
| 1778 | + /Invitation not found/, |
| 1779 | + ) |
| 1780 | + end |
| 1781 | + end |
| 1782 | + |
| 1783 | + context 'when invitation has already been accepted' do |
| 1784 | + it 'returns an error' do |
| 1785 | + expect(described_class).to receive(:post_request) do |options| |
| 1786 | + expect(options[:path]).to eq('/user_management/invitations/invitation_123/accept') |
| 1787 | + expect(options[:auth]).to be true |
| 1788 | + |
| 1789 | + double('request') |
| 1790 | + end.and_return(double('request')) |
| 1791 | + |
| 1792 | + expect(described_class).to receive(:execute_request).and_raise( |
| 1793 | + WorkOS::InvalidRequestError.new(message: 'Invite has already been accepted'), |
| 1794 | + ) |
| 1795 | + |
| 1796 | + expect do |
| 1797 | + described_class.accept_invitation(id: 'invitation_123') |
| 1798 | + end.to raise_error( |
| 1799 | + WorkOS::InvalidRequestError, |
| 1800 | + /Invite has already been accepted/, |
| 1801 | + ) |
| 1802 | + end |
| 1803 | + end |
| 1804 | + end |
| 1805 | + |
1731 | 1806 | describe '.revoke_invitation' do |
1732 | 1807 | context 'with valid payload' do |
1733 | 1808 | it 'revokes invitation' do |
|
0 commit comments