Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/forms/welsh_translation_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def welsh_translation_params
{ selection_options_cy_attributes: %i[id name_cy] },
{ condition_translations_attributes: WelshConditionTranslationInput.attribute_names },
],
).merge(form: current_form)
).merge(current_user:, form: current_form)
end

def delete_welsh_translation_params
Expand Down
2 changes: 1 addition & 1 deletion app/input_objects/forms/welsh_translation_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Forms::WelshTranslationInput < Forms::MarkCompleteInput
include TextInputHelper
include ActiveModel::Attributes

attr_accessor :form, :page_translations
attr_accessor :current_user, :form, :page_translations

attribute :mark_complete

Expand Down
11 changes: 11 additions & 0 deletions spec/input_objects/forms/welsh_translation_input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
RSpec.describe Forms::WelshTranslationInput, type: :model do
subject(:welsh_translation_input) { described_class.new(new_input_data) }

let(:current_user) { build :user }
let(:form) { build_form }
let(:page) do
create :page,
Expand All @@ -18,6 +19,7 @@

let(:new_input_data) do
{
current_user:,
form:,
mark_complete:,
name_cy: "New Welsh name",
Expand Down Expand Up @@ -194,6 +196,15 @@ def build_empty_welsh_form
expect(welsh_translation_input).not_to be_valid
expect(welsh_translation_input.errors.full_messages_for(:support_email_cy)).to include "Support email cy #{I18n.t('activemodel.errors.models.forms/welsh_translation_input.attributes.support_email_cy.non_government_email')}"
end

context "when the user has an email address with the same domain" do
let(:current_user) { build :user, email: "user@example.com" }

it "is valid" do
expect(welsh_translation_input).to be_valid
expect(welsh_translation_input.errors.full_messages_for(:support_email_cy)).to be_empty
end
end
end
end

Expand Down
27 changes: 27 additions & 0 deletions spec/requests/forms/welsh_translation_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,33 @@
end
end

context "when 'Yes' is selected and support email does not end in '.gov.uk'" do
let(:domain) { "ogd.ewxample" }
let(:support_email) { Faker::Internet.email(domain:) }

let(:form) { create(:form, :ready_for_routing, welsh_completed: false, support_email:) }
let(:params) { { forms_welsh_translation_input: { form:, mark_complete:, name_cy: "Gwneud cais am drwydded jyglo", privacy_policy_url_cy: "https://juggling.gov.uk/privacy_policy/cy", support_email_cy: support_email, page_translations_attributes: } } }

it "returns a 422, re-renders the page with an error, and does not display a success banner" do
post(welsh_translation_create_path(id), params:)

expect(response).to have_http_status(:unprocessable_content)
expect(response).to render_template(:new)
expect(response.body).to include(I18n.t("activemodel.errors.models.forms/welsh_translation_input.attributes.support_email_cy.non_government_email"))
expect(flash).to be_empty
end

context "and the current user is signed in with an email address at the same domain" do
let(:standard_user) { build :user, :standard, organisation: test_org, email: Faker::Internet.email(domain:) }

it "redirects to the form task list and displays a success banner including text about being marked complete" do
post(welsh_translation_create_path(id), params:)
expect(response).to redirect_to(form_path(id))
expect(flash[:success]).to eq(I18n.t("banner.success.form.welsh_translation_saved_and_completed"))
end
end
end

context "when the user is not authorized" do
let(:current_user) { build :user }

Expand Down