diff --git a/app/services/form_response.rb b/app/services/form_response.rb index 1804a571d26..e7947483ffd 100644 --- a/app/services/form_response.rb +++ b/app/services/form_response.rb @@ -56,7 +56,9 @@ def merge_arrays(_key, first, second) end def flatten_details(details) - details.transform_values { |errors| errors.pluck(:error) } + details.transform_values do |errors| + errors.map { |error| error[:type] || error[:error] }.index_with(true) + end end attr_reader :success diff --git a/app/services/password_reset_token_validator.rb b/app/services/password_reset_token_validator.rb index 3ffce440c73..6b410353de8 100644 --- a/app/services/password_reset_token_validator.rb +++ b/app/services/password_reset_token_validator.rb @@ -17,6 +17,7 @@ def submit attr_accessor :user def valid_token - errors.add(:user, 'token_expired', type: :user) unless user.reset_password_period_valid? + return if user.reset_password_period_valid? + errors.add(:user, 'token_expired', type: :token_expired) end end diff --git a/spec/controllers/account_reset/cancel_controller_spec.rb b/spec/controllers/account_reset/cancel_controller_spec.rb index ee2ce3dda15..349f2641d6a 100644 --- a/spec/controllers/account_reset/cancel_controller_spec.rb +++ b/spec/controllers/account_reset/cancel_controller_spec.rb @@ -30,7 +30,7 @@ success: false, errors: { token: [t('errors.account_reset.cancel_token_invalid', app_name: APP_NAME)] }, error_details: { - token: [t('errors.account_reset.cancel_token_invalid', app_name: APP_NAME)], + token: { cancel_token_invalid: true }, }, user_id: 'anonymous-uuid', } @@ -46,7 +46,7 @@ analytics_hash = { success: false, errors: { token: [t('errors.account_reset.cancel_token_missing', app_name: APP_NAME)] }, - error_details: { token: [:blank] }, + error_details: { token: { blank: true } }, user_id: 'anonymous-uuid', } @@ -91,7 +91,7 @@ success: false, errors: { token: [t('errors.account_reset.cancel_token_invalid', app_name: APP_NAME)] }, error_details: { - token: [t('errors.account_reset.cancel_token_invalid', app_name: APP_NAME)], + token: { cancel_token_invalid: true }, }, } expect(@analytics).to receive(:track_event). diff --git a/spec/controllers/account_reset/delete_account_controller_spec.rb b/spec/controllers/account_reset/delete_account_controller_spec.rb index 8e0ca01ad78..a89cbed5f7c 100644 --- a/spec/controllers/account_reset/delete_account_controller_spec.rb +++ b/spec/controllers/account_reset/delete_account_controller_spec.rb @@ -61,7 +61,7 @@ user_id: 'anonymous-uuid', success: false, errors: invalid_token_error, - error_details: invalid_token_error, + error_details: { token: { granted_token_invalid: true } }, mfa_method_counts: {}, pii_like_keypaths: [[:mfa_method_counts, :phone]], account_age_in_days: 0, @@ -92,7 +92,7 @@ user_id: 'anonymous-uuid', success: false, errors: { token: [t('errors.account_reset.granted_token_missing', app_name: APP_NAME)] }, - error_details: { token: [:blank] }, + error_details: { token: { blank: true } }, mfa_method_counts: {}, pii_like_keypaths: [[:mfa_method_counts, :phone]], account_age_in_days: 0, @@ -118,9 +118,7 @@ user_id: user.uuid, success: false, errors: { token: [t('errors.account_reset.granted_token_expired', app_name: APP_NAME)] }, - error_details: { - token: [t('errors.account_reset.granted_token_expired', app_name: APP_NAME)], - }, + error_details: { token: { granted_token_invalid: true } }, mfa_method_counts: {}, pii_like_keypaths: [[:mfa_method_counts, :phone]], account_age_in_days: 2, @@ -146,7 +144,7 @@ user_id: 'anonymous-uuid', success: false, errors: invalid_token_error, - error_details: invalid_token_error, + error_details: { token: { granted_token_invalid: true } }, } expect(@analytics).to receive(:track_event). with('Account Reset: granted token validation', properties) @@ -167,9 +165,7 @@ user_id: user.uuid, success: false, errors: { token: [t('errors.account_reset.granted_token_expired', app_name: APP_NAME)] }, - error_details: { - token: [t('errors.account_reset.granted_token_expired', app_name: APP_NAME)], - }, + error_details: { token: { granted_token_invalid: true } }, } expect(@analytics).to receive(:track_event). with('Account Reset: granted token validation', properties) diff --git a/spec/controllers/idv/doc_auth_controller_spec.rb b/spec/controllers/idv/doc_auth_controller_spec.rb index 94d58266374..635683cddc8 100644 --- a/spec/controllers/idv/doc_auth_controller_spec.rb +++ b/spec/controllers/idv/doc_auth_controller_spec.rb @@ -416,7 +416,7 @@ errors: include( pii: [I18n.t('doc_auth.errors.general.no_liveness')], ), - error_details: { pii: [I18n.t('doc_auth.errors.general.no_liveness')] }, + error_details: { pii: { generic_error: true } }, attention_with_barcode: false, success: false, remaining_attempts: IdentityConfig.store.doc_auth_max_attempts, @@ -431,7 +431,7 @@ errors: include( pii: [I18n.t('doc_auth.errors.general.no_liveness')], ), - error_details: { pii: [I18n.t('doc_auth.errors.general.no_liveness')] }, + error_details: { pii: { generic_error: true } }, attention_with_barcode: false, success: false, remaining_attempts: IdentityConfig.store.doc_auth_max_attempts, diff --git a/spec/controllers/idv/gpo_verify_controller_spec.rb b/spec/controllers/idv/gpo_verify_controller_spec.rb index 14a9e3b1390..01e0959901e 100644 --- a/spec/controllers/idv/gpo_verify_controller_spec.rb +++ b/spec/controllers/idv/gpo_verify_controller_spec.rb @@ -86,7 +86,6 @@ describe '#create' do let(:otp_code_error_message) { { otp: [t('errors.messages.confirmation_code_incorrect')] } } - let(:otp_code_incorrect) { { otp: [:confirmation_code_incorrect] } } let(:success_properties) { { success: true, failure_reason: nil } } subject(:action) do @@ -175,11 +174,11 @@ errors: otp_code_error_message, pending_in_person_enrollment: false, enqueued_at: nil, - error_details: otp_code_incorrect, + error_details: { otp: { confirmation_code_incorrect: true } }, pii_like_keypaths: [[:errors, :otp], [:error_details, :otp]], ) expect(@irs_attempts_api_tracker).to receive(:idv_gpo_verification_submitted). - with(success: false, failure_reason: otp_code_incorrect) + with(success: false, failure_reason: { otp: { confirmation_code_incorrect: true } }) action @@ -205,7 +204,7 @@ errors: otp_code_error_message, pending_in_person_enrollment: false, enqueued_at: nil, - error_details: otp_code_incorrect, + error_details: { otp: { confirmation_code_incorrect: true } }, pii_like_keypaths: [[:errors, :otp], [:error_details, :otp]], ).exactly(max_attempts).times diff --git a/spec/controllers/idv/image_uploads_controller_spec.rb b/spec/controllers/idv/image_uploads_controller_spec.rb index 0c2c39f360b..5adb3f84171 100644 --- a/spec/controllers/idv/image_uploads_controller_spec.rb +++ b/spec/controllers/idv/image_uploads_controller_spec.rb @@ -59,7 +59,7 @@ front: ['Please fill in this field.'], }, error_details: { - front: [:blank], + front: { blank: true }, }, user_id: user.uuid, attempts: 1, @@ -120,7 +120,7 @@ front: [I18n.t('doc_auth.errors.not_a_file')], }, error_details: { - front: [I18n.t('doc_auth.errors.not_a_file')], + front: { not_a_file: true }, }, user_id: user.uuid, attempts: 1, @@ -220,7 +220,7 @@ limit: [I18n.t('errors.doc_auth.throttled_heading')], }, error_details: { - limit: [I18n.t('errors.doc_auth.throttled_heading')], + limit: { throttled: true }, }, user_id: user.uuid, attempts: IdentityConfig.store.doc_auth_max_attempts, @@ -446,7 +446,7 @@ pii: [I18n.t('doc_auth.errors.alerts.full_name_check')], }, error_details: { - pii: [I18n.t('doc_auth.errors.alerts.full_name_check')], + pii: { name_error: true }, }, attention_with_barcode: false, user_id: user.uuid, @@ -524,7 +524,7 @@ pii: [I18n.t('doc_auth.errors.general.no_liveness')], }, error_details: { - pii: [I18n.t('doc_auth.errors.general.no_liveness')], + pii: { generic_error: true }, }, attention_with_barcode: false, user_id: user.uuid, @@ -602,7 +602,7 @@ pii: [I18n.t('doc_auth.errors.alerts.birth_date_checks')], }, error_details: { - pii: [I18n.t('doc_auth.errors.alerts.birth_date_checks')], + pii: { dob_error: true }, }, attention_with_barcode: false, user_id: user.uuid, diff --git a/spec/controllers/idv/otp_delivery_method_controller_spec.rb b/spec/controllers/idv/otp_delivery_method_controller_spec.rb index 31334b47a05..d3cba80fd56 100644 --- a/spec/controllers/idv/otp_delivery_method_controller_spec.rb +++ b/spec/controllers/idv/otp_delivery_method_controller_spec.rb @@ -195,7 +195,7 @@ result = { success: false, errors: { otp_delivery_preference: ['is not included in the list'] }, - error_details: { otp_delivery_preference: [:inclusion] }, + error_details: { otp_delivery_preference: { inclusion: true } }, otp_delivery_preference: '🎷', } diff --git a/spec/controllers/idv/phone_controller_spec.rb b/spec/controllers/idv/phone_controller_spec.rb index d13815ae777..2e064af7a4f 100644 --- a/spec/controllers/idv/phone_controller_spec.rb +++ b/spec/controllers/idv/phone_controller_spec.rb @@ -136,8 +136,8 @@ context 'when form is invalid' do let(:improbable_phone_error) do { - phone: [:improbable_phone], - otp_delivery_preference: [:inclusion], + phone: { improbable_phone: true }, + otp_delivery_preference: { inclusion: true }, } end let(:improbable_phone_message) { t('errors.messages.improbable_phone') } diff --git a/spec/controllers/saml_idp_controller_spec.rb b/spec/controllers/saml_idp_controller_spec.rb index 57dd0fbcf3c..6b9067f5ebc 100644 --- a/spec/controllers/saml_idp_controller_spec.rb +++ b/spec/controllers/saml_idp_controller_spec.rb @@ -744,7 +744,7 @@ def name_id_version(format_urn) analytics_hash = { success: false, errors: { authn_context: [t('errors.messages.unauthorized_authn_context')] }, - error_details: { authn_context: [:unauthorized_authn_context] }, + error_details: { authn_context: { unauthorized_authn_context: true } }, nameid_format: Saml::Idp::Constants::NAME_ID_FORMAT_PERSISTENT, authn_context: ['http://idmanagement.gov/ns/assurance/loa/5'], authn_context_comparison: 'exact', @@ -917,7 +917,7 @@ def name_id_version(format_urn) analytics_hash = { success: false, errors: { service_provider: [t('errors.messages.unauthorized_service_provider')] }, - error_details: { service_provider: [:unauthorized_service_provider] }, + error_details: { service_provider: { unauthorized_service_provider: true } }, nameid_format: Saml::Idp::Constants::NAME_ID_FORMAT_PERSISTENT, authn_context: request_authn_contexts, authn_context_comparison: 'exact', @@ -959,8 +959,8 @@ def name_id_version(format_urn) authn_context: [t('errors.messages.unauthorized_authn_context')], }, error_details: { - authn_context: [:unauthorized_authn_context], - service_provider: [:unauthorized_service_provider], + authn_context: { unauthorized_authn_context: true }, + service_provider: { unauthorized_service_provider: true }, }, nameid_format: Saml::Idp::Constants::NAME_ID_FORMAT_PERSISTENT, authn_context: ['http://idmanagement.gov/ns/assurance/loa/5'], @@ -1350,7 +1350,7 @@ def name_id_version(format_urn) analytics_hash = { success: false, errors: { nameid_format: [t('errors.messages.unauthorized_nameid_format')] }, - error_details: { nameid_format: [:unauthorized_nameid_format] }, + error_details: { nameid_format: { unauthorized_nameid_format: true } }, nameid_format: Saml::Idp::Constants::NAME_ID_FORMAT_EMAIL, authn_context: request_authn_contexts, authn_context_comparison: 'exact', diff --git a/spec/controllers/sign_up/email_confirmations_controller_spec.rb b/spec/controllers/sign_up/email_confirmations_controller_spec.rb index 829308be21d..4b83a108464 100644 --- a/spec/controllers/sign_up/email_confirmations_controller_spec.rb +++ b/spec/controllers/sign_up/email_confirmations_controller_spec.rb @@ -2,8 +2,8 @@ describe SignUp::EmailConfirmationsController do describe '#create' do - let(:token_not_found_error) { { confirmation_token: [:not_found] } } - let(:token_expired_error) { { confirmation_token: [:expired] } } + let(:token_not_found_error) { { confirmation_token: { not_found: true } } } + let(:token_expired_error) { { confirmation_token: { expired: true } } } let(:analytics_token_error_hash) do { success: false, diff --git a/spec/controllers/sign_up/passwords_controller_spec.rb b/spec/controllers/sign_up/passwords_controller_spec.rb index 68f3a5f796e..5ba66798030 100644 --- a/spec/controllers/sign_up/passwords_controller_spec.rb +++ b/spec/controllers/sign_up/passwords_controller_spec.rb @@ -69,7 +69,7 @@ end it 'tracks an invalid password event' do - password_short_error = { password: [:too_short] } + password_short_error = { password: { too_short: true } } token = 'new token' user = create(:user, :unconfirmed, confirmation_token: token) diff --git a/spec/controllers/sign_up/registrations_controller_spec.rb b/spec/controllers/sign_up/registrations_controller_spec.rb index 9a814c18a0f..1782f71132f 100644 --- a/spec/controllers/sign_up/registrations_controller_spec.rb +++ b/spec/controllers/sign_up/registrations_controller_spec.rb @@ -125,7 +125,7 @@ success: false, throttled: false, errors: { email: [t('valid_email.validations.email.invalid')] }, - error_details: { email: [:invalid] }, + error_details: { email: { invalid: true } }, email_already_exists: false, user_id: 'anonymous-uuid', domain_name: 'invalid', diff --git a/spec/controllers/two_factor_authentication/otp_verification_controller_spec.rb b/spec/controllers/two_factor_authentication/otp_verification_controller_spec.rb index 52c09075ad3..efd961cb167 100644 --- a/spec/controllers/two_factor_authentication/otp_verification_controller_spec.rb +++ b/spec/controllers/two_factor_authentication/otp_verification_controller_spec.rb @@ -96,7 +96,7 @@ properties = { success: false, - error_details: { code: [:incorrect_length, :incorrect] }, + error_details: { code: { incorrect_length: true, incorrect: true } }, confirmation_for_add_phone: false, context: 'authentication', multi_factor_auth_method: 'sms', @@ -153,7 +153,7 @@ properties = { success: false, - error_details: { code: [:incorrect_length, :incorrect] }, + error_details: { code: { incorrect_length: true, incorrect: true } }, confirmation_for_add_phone: false, context: 'authentication', multi_factor_auth_method: 'sms', @@ -469,7 +469,7 @@ properties = { success: false, errors: nil, - error_details: { code: [:incorrect_length, :incorrect] }, + error_details: { code: { incorrect_length: true, incorrect: true } }, confirmation_for_add_phone: true, context: 'confirmation', multi_factor_auth_method: 'sms', diff --git a/spec/controllers/users/edit_phone_controller_spec.rb b/spec/controllers/users/edit_phone_controller_spec.rb index e2f2296de56..d2e6309391d 100644 --- a/spec/controllers/users/edit_phone_controller_spec.rb +++ b/spec/controllers/users/edit_phone_controller_spec.rb @@ -38,7 +38,7 @@ attributes = { success: false, errors: hash_including(:delivery_preference), - error_details: { delivery_preference: [:inclusion] }, + error_details: { delivery_preference: { inclusion: true } }, delivery_preference: 'noise', make_default_number: true, phone_configuration_id: phone_configuration.id, diff --git a/spec/controllers/users/passwords_controller_spec.rb b/spec/controllers/users/passwords_controller_spec.rb index 522106775b1..93bc821b4bd 100644 --- a/spec/controllers/users/passwords_controller_spec.rb +++ b/spec/controllers/users/passwords_controller_spec.rb @@ -79,7 +79,7 @@ context 'form returns failure' do it 'renders edit' do - password_short_error = { password: [:too_short] } + password_short_error = { password: { too_short: true } } stub_sign_in stub_analytics diff --git a/spec/controllers/users/phone_setup_controller_spec.rb b/spec/controllers/users/phone_setup_controller_spec.rb index a3f15baf9ec..f0f85c622e1 100644 --- a/spec/controllers/users/phone_setup_controller_spec.rb +++ b/spec/controllers/users/phone_setup_controller_spec.rb @@ -48,10 +48,10 @@ ], }, error_details: { - phone: [ - :improbable_phone, - t('two_factor_authentication.otp_delivery_preference.voice_unsupported', location: ''), - ], + phone: { + improbable_phone: true, + voice_unsupported: true, + }, }, otp_delivery_preference: 'sms', area_code: nil, diff --git a/spec/controllers/users/reset_passwords_controller_spec.rb b/spec/controllers/users/reset_passwords_controller_spec.rb index 93255438def..7e06a980457 100644 --- a/spec/controllers/users/reset_passwords_controller_spec.rb +++ b/spec/controllers/users/reset_passwords_controller_spec.rb @@ -5,7 +5,6 @@ "This password is too short (minimum is #{Devise.password_length.first} characters)" end let(:success_properties) { { success: true, failure_reason: nil } } - let(:token_expired_error) { 'token_expired' } describe '#edit' do before do stub_analytics @@ -14,7 +13,7 @@ end context 'no user matches token' do - let(:user_blank_error) { { user: [:blank] } } + let(:user_blank_error) { { user: { blank: true } } } let(:analytics_hash) do { success: false, @@ -40,11 +39,11 @@ end context 'token expired' do - let(:user_token_error) { { user: [token_expired_error] } } + let(:user_token_error) { { user: { token_expired: true } } } let(:analytics_hash) do { success: false, - errors: user_token_error, + errors: { user: ['token_expired'] }, error_details: user_token_error, user_id: '123', } @@ -104,8 +103,8 @@ end describe '#update' do - let(:password_short_error) { { password: [:too_short] } } - let(:password_token_error) { { reset_password_token: [token_expired_error] } } + let(:password_short_error) { { password: { too_short: true } } } + let(:password_token_error) { { reset_password_token: { token_expired: true } } } context 'user submits new password after token expires' do let(:reset_password_error_details) do { @@ -142,9 +141,12 @@ success: false, errors: { password: [password_error_message], - **password_token_error, + reset_password_token: ['token_expired'], + }, + error_details: { + password: { too_short: true }, + reset_password_token: { token_expired: true }, }, - error_details: reset_password_error_details, user_id: user.uuid, profile_deactivated: false, } @@ -512,7 +514,7 @@ analytics_hash = { success: false, errors: { email: [t('valid_email.validations.email.invalid')] }, - error_details: { email: [:invalid] }, + error_details: { email: { invalid: true } }, user_id: 'nonexistent-uuid', confirmed: false, active_profile: false, diff --git a/spec/controllers/users/totp_setup_controller_spec.rb b/spec/controllers/users/totp_setup_controller_spec.rb index e2ee9c3140f..de0a5abc870 100644 --- a/spec/controllers/users/totp_setup_controller_spec.rb +++ b/spec/controllers/users/totp_setup_controller_spec.rb @@ -219,7 +219,7 @@ result = { success: false, - error_details: { name: [:blank] }, + error_details: { name: { blank: true } }, errors: { name: [t('errors.messages.blank')] }, totp_secret_present: true, multi_factor_auth_method: 'totp', diff --git a/spec/controllers/users/verify_personal_key_controller_spec.rb b/spec/controllers/users/verify_personal_key_controller_spec.rb index 219bec799a0..df0e5d2e846 100644 --- a/spec/controllers/users/verify_personal_key_controller_spec.rb +++ b/spec/controllers/users/verify_personal_key_controller_spec.rb @@ -162,7 +162,7 @@ expect(@analytics).to receive(:track_event).with( 'Personal key reactivation: Personal key form submitted', errors: { personal_key: ['Please fill in this field.', error_text] }, - error_details: { personal_key: [:blank, :personal_key_incorrect] }, + error_details: { personal_key: { blank: true, personal_key_incorrect: true } }, success: false, pii_like_keypaths: pii_like_keypaths_errors, ).once diff --git a/spec/controllers/users/webauthn_setup_controller_spec.rb b/spec/controllers/users/webauthn_setup_controller_spec.rb index 0b3472035c3..3fd7e198cab 100644 --- a/spec/controllers/users/webauthn_setup_controller_spec.rb +++ b/spec/controllers/users/webauthn_setup_controller_spec.rb @@ -305,10 +305,7 @@ 'errors.webauthn_platform_setup.attestation_error', link: MarketingSite.contact_url, )] }, - error_details: { name: [I18n.t( - 'errors.webauthn_platform_setup.attestation_error', - link: MarketingSite.contact_url, - )] }, + error_details: { name: { attestation_error: true } }, in_multi_mfa_selection_flow: true, mfa_method_counts: {}, multi_factor_auth_method: 'webauthn_platform', diff --git a/spec/forms/openid_connect_authorize_form_spec.rb b/spec/forms/openid_connect_authorize_form_spec.rb index bb76a2dd5fd..9228cf797d7 100644 --- a/spec/forms/openid_connect_authorize_form_spec.rb +++ b/spec/forms/openid_connect_authorize_form_spec.rb @@ -60,7 +60,7 @@ expect(result.to_h).to eq( success: false, errors: { response_type: ['is not included in the list'] }, - error_details: { response_type: [:inclusion] }, + error_details: { response_type: { inclusion: true } }, client_id: client_id, redirect_uri: "#{redirect_uri}?error=invalid_request&error_description=" \ "Response+type+is+not+included+in+the+list&state=#{state}", diff --git a/spec/forms/otp_verification_form_spec.rb b/spec/forms/otp_verification_form_spec.rb index 63df2675c13..1ca7fe8d24b 100644 --- a/spec/forms/otp_verification_form_spec.rb +++ b/spec/forms/otp_verification_form_spec.rb @@ -43,7 +43,7 @@ expect(result.to_h).to eq( success: false, error_details: { - code: [:blank], + code: { blank: true }, }, multi_factor_auth_method: 'otp_code', ) @@ -64,7 +64,7 @@ expect(result.to_h).to eq( success: false, error_details: { - code: [:user_otp_missing], + code: { user_otp_missing: true }, }, multi_factor_auth_method: 'otp_code', ) @@ -85,7 +85,7 @@ expect(result.to_h).to eq( success: false, error_details: { - code: [:incorrect_length, :incorrect], + code: { incorrect_length: true, incorrect: true }, }, multi_factor_auth_method: 'otp_code', ) @@ -106,7 +106,7 @@ expect(result.to_h).to eq( success: false, error_details: { - code: [:pattern_mismatch, :incorrect], + code: { pattern_mismatch: true, incorrect: true }, }, multi_factor_auth_method: 'otp_code', ) @@ -130,7 +130,7 @@ expect(result.to_h).to eq( success: false, error_details: { - code: [:user_otp_expired], + code: { user_otp_expired: true }, }, multi_factor_auth_method: 'otp_code', ) diff --git a/spec/forms/totp_setup_form_spec.rb b/spec/forms/totp_setup_form_spec.rb index a7d0bdc78fe..ce0b3746685 100644 --- a/spec/forms/totp_setup_form_spec.rb +++ b/spec/forms/totp_setup_form_spec.rb @@ -80,7 +80,7 @@ expect(form.submit.to_h).to include( success: false, - error_details: { name: [:blank] }, + error_details: { name: { blank: true } }, errors: { name: [t('errors.messages.blank')] }, ) expect(user.auth_app_configurations.any?).to eq false @@ -95,7 +95,7 @@ expect(form2.submit.to_h).to include( success: false, - error_details: { name: [t('errors.piv_cac_setup.unique_name')] }, + error_details: { name: { unique_name: true } }, errors: { name: [t('errors.piv_cac_setup.unique_name')] }, ) end diff --git a/spec/forms/webauthn_setup_form_spec.rb b/spec/forms/webauthn_setup_form_spec.rb index e93020aa7ac..db6272a8c51 100644 --- a/spec/forms/webauthn_setup_form_spec.rb +++ b/spec/forms/webauthn_setup_form_spec.rb @@ -109,10 +109,7 @@ 'errors.webauthn_setup.attestation_error', link: MarketingSite.contact_url, )] }, - error_details: { name: [I18n.t( - 'errors.webauthn_setup.attestation_error', - link: MarketingSite.contact_url, - )] }, + error_details: { name: { attestation_error: true } }, **extra_attributes, ) end diff --git a/spec/services/form_response_spec.rb b/spec/services/form_response_spec.rb index 2f8f9fc4a28..09e5cca8b21 100644 --- a/spec/services/form_response_spec.rb +++ b/spec/services/form_response_spec.rb @@ -78,7 +78,9 @@ response2 = FormResponse.new(success: false, errors: errors2) combined_response = response1.merge(response2) - expect(combined_response.to_h[:error_details]).to eq(email_language: [:blank, :invalid]) + expect(combined_response.to_h[:error_details]).to eq( + email_language: { blank: true, invalid: true }, + ) end it 'merges hash and ActiveModel::Errors' do @@ -93,7 +95,7 @@ expect(combined_response.errors).to eq( email_language: ['Language cannot be blank', 'Language is not valid'], ) - expect(combined_response.to_h[:error_details]).to eq(email_language: [:blank]) + expect(combined_response.to_h[:error_details]).to eq(email_language: { blank: true }) end it 'returns true if one is false and one is true' do @@ -146,13 +148,32 @@ email_language: ['Language cannot be blank'], }, error_details: { - email_language: [:blank], + email_language: { blank: true }, }, } expect(response.to_h).to eq response_hash end + context 'without error type' do + it 'falls back to message as key for details' do + errors = ActiveModel::Errors.new(build_stubbed(:user)) + errors.add(:email_language, :blank) + response = FormResponse.new(success: false, errors: errors) + response_hash = { + success: false, + errors: { + email_language: [t('errors.messages.blank')], + }, + error_details: { + email_language: { blank: true }, + }, + } + + expect(response.to_h).to eq response_hash + end + end + it 'omits details if errors are empty' do errors = ActiveModel::Errors.new(build_stubbed(:user)) response = FormResponse.new(success: true, errors: errors) @@ -190,7 +211,7 @@ expect(response.to_h).to eq( success: false, error_details: { - email_language: [:blank], + email_language: { blank: true }, }, ) end diff --git a/spec/services/irs_attempts_api/tracker_spec.rb b/spec/services/irs_attempts_api/tracker_spec.rb index f7ba6492e1a..76dd185f20e 100644 --- a/spec/services/irs_attempts_api/tracker_spec.rb +++ b/spec/services/irs_attempts_api/tracker_spec.rb @@ -159,12 +159,12 @@ describe '#parse_failure_reason' do let(:mock_error_message) { 'failure_reason_from_error' } - let(:mock_error_details) { [{ mock_error: 'failure_reason_from_error_details' }] } + let(:mock_error_details) { { mock_error: { failure_reason_from_error_details: true } } } it 'parses failure_reason from error_details' do test_failure_reason = subject.parse_failure_reason( { errors: mock_error_message, - error_details: mock_error_details }, + error_details: { mock_error: { failure_reason_from_error_details: true } } }, ) expect(test_failure_reason).to eq(mock_error_details)