-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcopy_controller_spec.rb
More file actions
92 lines (73 loc) · 3.08 KB
/
copy_controller_spec.rb
File metadata and controls
92 lines (73 loc) · 3.08 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
require "rails_helper"
RSpec.describe Forms::CopyController, :feature_org_admin_alerts_enabled, type: :request do
let(:id) { form.id }
let(:form) { create(:form) }
let(:group) { create(:group, organisation: standard_user.organisation, status: :active) }
before do
Membership.create!(group_id: group.id, user: standard_user, added_by: standard_user)
GroupForm.create!(form_id: form.id, group_id: group.id)
login_as_standard_user
end
describe "#copy" do
before do
get copy_form_path(id, "draft")
end
it "returns 200" do
expect(response).to have_http_status(:ok)
end
it "renders copy template" do
expect(response).to render_template(:confirm)
end
describe "#set_back_link" do
context "when copying a draft form" do
it "sets the back link to the draft form edit page" do
get copy_form_path(id, "draft")
expect(assigns(:back_link)).to eq({ url: form_path(form.id), body: I18n.t("back_link.form_edit") })
end
end
context "when copying a live form" do
let(:form) { create(:form, :live) }
it "sets the back link to the live form view page" do
get copy_form_path(id, "live")
expect(assigns(:back_link)).to eq({ url: live_form_path(form.id), body: I18n.t("back_link.form_view") })
end
end
context "when copying an archived form" do
let(:form) { create(:form, :archived) }
it "sets the back link to the archived form view page" do
get copy_form_path(id, "archived")
expect(assigns(:back_link)).to eq({ url: archived_form_path(form.id), body: I18n.t("back_link.form_view") })
end
end
end
end
describe "#create" do
before do
create(:organisation_admin_user, organisation: standard_user.organisation)
end
context "when the copy is successful" do
it "redirects to the form page" do
post create_copy_form_path(id), params: { forms_copy_input: { name: "Copied Form", tag: "draft" } }
expect(response).to have_http_status(:found)
expect(response).to redirect_to(form_path(Form.last.id))
end
it "sends an email to the organisation admins" do
post create_copy_form_path(id), params: { forms_copy_input: { name: "Copied Form", tag: "draft" } }
expect(ActionMailer::Base.deliveries.count).to eq(1)
template_id = Settings.govuk_notify.org_admin_alerts.copied_draft_form_created_template_id
expect(ActionMailer::Base.deliveries.last.govuk_notify_template).to eq(template_id)
end
end
context "when the copy fails" do
it "renders the confirm template" do
post create_copy_form_path(id), params: { forms_copy_input: { name: "", tag: "draft" } }
expect(response).to have_http_status(:ok)
expect(response).to render_template(:confirm)
end
it "does not send an email to the organisation admins" do
post create_copy_form_path(id), params: { forms_copy_input: { name: "", tag: "draft" } }
expect(ActionMailer::Base.deliveries.count).to eq(0)
end
end
end
end