diff --git a/spec/forms/webauthn_setup_form_spec.rb b/spec/forms/webauthn_setup_form_spec.rb index e467c404ec0..284b5811446 100644 --- a/spec/forms/webauthn_setup_form_spec.rb +++ b/spec/forms/webauthn_setup_form_spec.rb @@ -246,6 +246,10 @@ end end context 'webauthn_platform' do + let(:params) do + super().merge(platform_authenticator: true, transports: 'internal,hybrid') + end + context 'with one platform authenticator with the same name' do let(:user) do user = create(:user) @@ -257,12 +261,7 @@ ) user end - let(:params) do - super().merge( - platform_authenticator: true, - transports: 'internal,hybrid', - ) - end + it 'adds a new platform device with the same existing name and appends a (1)' do result = subject.submit(protocol, params) expect(result.extra[:multi_factor_auth_method]).to eq 'webauthn_platform' @@ -276,37 +275,26 @@ end context 'with two existing platform authenticators one with the same name' do - let(:user) do - user = create(:user) - user.webauthn_configurations << create( - :webauthn_configuration, - name: device_name, - platform_authenticator: true, - transports: ['internal', 'hybrid'], - ) - user.webauthn_configurations << create( - :webauthn_configuration, - name: device_name, - platform_authenticator: true, - transports: ['internal', 'hybrid'], - ) - user - end - let(:params) do - super().merge( - platform_authenticator: true, - transports: 'internal,hybrid', + let!(:user) do + create( + :user, + webauthn_configurations: create_list( + :webauthn_configuration, + 2, + name: device_name, + platform_authenticator: true, + transports: ['internal', 'hybrid'], + ), ) end + it 'adds a second new platform device with the same existing name and appends a (2)' do result = subject.submit(protocol, params) - expect(result.extra[:multi_factor_auth_method]).to eq 'webauthn_platform' + + expect(result.success?).to eq(true) expect(user.webauthn_configurations.platform_authenticators.count).to eq(3) - expect( - user.webauthn_configurations.platform_authenticators[2].name, - ). + expect(user.webauthn_configurations.platform_authenticators.last.name). to eq("#{device_name} (2)") - expect(result.to_h[:success]).to eq(true) end end end