summaryrefslogtreecommitdiff
path: root/spec/controllers/profiles/webauthn_registrations_controller_spec.rb
blob: 949de9d0b9099c07bf60c79adcf4ae82c28d6807 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Profiles::WebauthnRegistrationsController do
  let(:user) { create(:user, :two_factor_via_webauthn) }

  before do
    sign_in(user)
  end

  describe '#destroy' do
    let(:webauthn_id) { user.webauthn_registrations.first.id }

    subject { delete :destroy, params: { id: webauthn_id } }

    it 'redirects to the profile two factor authentication page' do
      subject

      expect(response).to redirect_to profile_two_factor_auth_path
    end

    it 'destroys the webauthn registration' do
      expect { subject }.to change { user.webauthn_registrations.count }.by(-1)
    end

    it 'calls the Webauthn::DestroyService' do
      service = double

      expect(Webauthn::DestroyService).to receive(:new).with(user, user, webauthn_id.to_s).and_return(service)
      expect(service).to receive(:execute)

      subject
    end
  end
end