Skip to content

Commit

Permalink
Added tests for revoking user invites
Browse files Browse the repository at this point in the history
  • Loading branch information
alihadimazeh committed Jun 18, 2024
1 parent a2f5cc6 commit 93abcad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
10 changes: 5 additions & 5 deletions app/controllers/api/v1/admin/invitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def create

def destroy
invitation = Invitation.find(params[:id])
invitation.destroy
render_data status: :ok
rescue StandardError => e
logger.error "Failed to revoke invite, error: #{e.message}"
render_error status: :bad_request
if invitation.destroy
render_data status: :ok
else
render_error status: :not_found
end
end
end
end
Expand Down
15 changes: 14 additions & 1 deletion spec/controllers/admin/invitations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

require 'rails_helper'

RSpec.describe Api::V1::Admin::InvitationsController, type: :controller do
RSpec.describe Api::V1::Admin::InvitationsController do
let(:user) { create(:user) }
let(:user_with_manage_users_permission) { create(:user, :with_manage_users_permission) }

Expand Down Expand Up @@ -105,4 +105,17 @@
end
end
end

describe 'invitation#destroy' do
it 'deletes the invitation' do
invitation = create(:invitation, email: 'faker@faker.com')
expect { delete :destroy, params: { id: invitation.id } }
expect(response).to have_http_status(:ok)
end

it 'fails to delete the invitation if the id does not exist' do
expect { delete :destroy, params: { id: 'invalid-id' } }.not_to change(Invitation, :count)
expect(response).to have_http_status(:not_found)
end
end
end

0 comments on commit 93abcad

Please sign in to comment.