diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cc9b37261..6e54b6eb0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -117,7 +117,7 @@ def user_not_authorized end def set_current_url_options - ::ActiveStorage::Current.url_options = { host: OstConfig.full_uri } if Rails.env.development? + ::ActiveStorage::Current.url_options = { host: OstConfig.full_uri } if Rails.env.development? || Rails.env.test? end def set_current_user diff --git a/app/views/lotteries/entrant_service_details/_service_form_status_card.html.erb b/app/views/lotteries/entrant_service_details/_service_form_status_card.html.erb index 208d9f1af..7dae276a2 100644 --- a/app/views/lotteries/entrant_service_details/_service_form_status_card.html.erb +++ b/app/views/lotteries/entrant_service_details/_service_form_status_card.html.erb @@ -25,13 +25,13 @@ <% if presenter.rejected? %> <%= fa_icon("circle-xmark", type: :solid, class: "text-danger") %> Rejected - <%= l(presenter.service_form_rejected_at) %> - <%= presenter.service_form_rejected_comments %> + <%= l(presenter.form_rejected_at) %> + <%= presenter.form_rejected_comments %> <% elsif presenter.accepted? %> <%= fa_icon("circle-check", type: :solid, class: "text-success") %> Accepted - <%= l(presenter.service_form_accepted_at) %> - <%= presenter.service_form_accepted_comments %> + <%= l(presenter.form_accepted_at) %> + <%= presenter.form_accepted_comments %> <% elsif presenter.completed_form.attached? %> <%= fa_icon("file-magnifying-glass", type: :solid, class: "text-secondary") %> Under review diff --git a/service_form.pdf b/service_form.pdf new file mode 100644 index 000000000..481eb1215 Binary files /dev/null and b/service_form.pdf differ diff --git a/spec/fixtures/files/service_form.pdf b/spec/fixtures/files/service_form.pdf new file mode 100644 index 000000000..481eb1215 Binary files /dev/null and b/spec/fixtures/files/service_form.pdf differ diff --git a/spec/support/basic_configure.rb b/spec/support/basic_configure.rb index 6cd37aca6..6556966e9 100644 --- a/spec/support/basic_configure.rb +++ b/spec/support/basic_configure.rb @@ -10,5 +10,9 @@ config.before(:each, type: :system, js: true) do driven_by :chrome_headless # driven_by :chrome_visible + + download_path = Rails.root.join("tmp/downloads") + page.driver.browser.download_path = download_path + FileUtils.mkdir_p(download_path) end end diff --git a/spec/system/lotteries/manage_service_spec.rb b/spec/system/lotteries/manage_service_spec.rb index d1bea2e7e..bb80d4f05 100644 --- a/spec/system/lotteries/manage_service_spec.rb +++ b/spec/system/lotteries/manage_service_spec.rb @@ -3,61 +3,116 @@ require "rails_helper" RSpec.describe "manage lottery service", js: true do - let(:admin) { users(:admin_user) } - let(:steward) { users(:fifth_user) } let(:user) { users(:fourth_user) } - before do - organization.stewards << steward - end - let(:lottery) { lotteries(:lottery_with_tickets_and_draws) } let(:organization) { lottery.organization } let(:entrant) { lottery_entrants(:lottery_entrant_0004) } - let(:person) { people(:bruno_fadel) } - - before { lottery.update(status: :finished) } + let(:download_path) { Rails.root.join("tmp/downloads") } - scenario "user who is an admin" do - login_as admin, scope: :user - visit_page - - expect(page).to have_current_path(organization_lottery_entrant_service_detail_path(organization, lottery, entrant)) + before do + entrant.update!(email: user.email) + lottery.update(status: :finished) end - scenario "user who is a steward" do - login_as steward, scope: :user - visit_page + context "service form not available" do + scenario "user visits the page" do + login_as user, scope: :user + visit_page - expect(page).to have_current_path(organization_lottery_entrant_service_detail_path(organization, lottery, entrant)) + expect(page).to have_current_path(page_path) + expect(page).to have_text("not yet available for download") + end end - scenario "user who has the same email as the entrant" do - entrant.update!(email: user.email) - login_as user, scope: :user - visit_page - - expect(page).to have_current_path(organization_lottery_entrant_service_detail_path(organization, lottery, entrant)) + context "service form is available" do + before do + lottery.service_form.attach( + io: File.open(file_fixture("service_form.pdf")), + filename: "service_form.pdf", + content_type: "application/pdf" + ) + end + + scenario "user downloads the service form" do + login_as user, scope: :user + visit_page + + expect(page).to have_current_path(page_path) + expect(page).to have_text("Download a blank service form") + + click_link "Download" + downloaded_file = download_path.join("service_form.pdf") + expect(File.exist?(downloaded_file)).to be true + + expect(page).to have_current_path(page_path) + end + + scenario "user uploads a completed service form pdf" do + login_as user, scope: :user + visit_page + + expect(page).to have_current_path(page_path) + attach_file_and_validate + expect(page).to have_current_path(page_path) + expect(page).to have_text("Under review") + end + + context "completed form is attached and has been rejected" do + before do + entrant.create_service_detail + entrant.service_detail.completed_form.attach( + io: File.open(file_fixture("potato3.jpg")), + filename: "potato3.jpg", + content_type: "image/jpeg" + ) + end + + context "and has been accepted" do + before { entrant.service_detail.update(form_accepted_at: Time.zone.now, form_accepted_comments: "Thank you for your service") } + + scenario "user sees feedback" do + login_as user, scope: :user + visit_page + + expect(page).to have_current_path(page_path) + expect(page).to have_text "Accepted" + expect(page).to have_text "Thank you for your service" + end + end + + context "and has been rejected" do + before { entrant.service_detail.update(form_rejected_at: Time.zone.now, form_rejected_comments: "This is a potato") } + + scenario "user sees feedback and removes the form" do + login_as user, scope: :user + visit_page + + expect(page).to have_current_path(page_path) + expect(page).to have_text "Rejected" + expect(page).to have_text "This is a potato" + + click_button "Remove" + expect(page).to have_current_path(page_path) + expect(page).to have_text "Not received" + expect(page).not_to have_text "This is a potato" + end + end + end end - scenario "user who has the same person" do - entrant.update!(person: person) - person.update!(claimant: user) - login_as user, scope: :user - visit_page - - expect(page).to have_current_path(organization_lottery_entrant_service_detail_path(organization, lottery, entrant)) + def visit_page + visit page_path end - scenario "user who is not associated" do - login_as user, scope: :user - visit_page - - expect(page).to have_current_path(root_path) - expect(page).to have_text("Access denied") + def page_path + organization_lottery_entrant_service_detail_path(organization, lottery, entrant) end - def visit_page - visit organization_lottery_entrant_service_detail_path(organization, lottery, entrant) + def attach_file_and_validate + find(".dropzone").drop(file_fixture("potato3.jpg")) + click_button "Attach" + sleep 1 + expect(entrant.service_detail.completed_form.attached?).to eq(true) end end diff --git a/spec/system/lotteries/visit_manage_service_spec.rb b/spec/system/lotteries/visit_manage_service_spec.rb new file mode 100644 index 000000000..6cd7f780a --- /dev/null +++ b/spec/system/lotteries/visit_manage_service_spec.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe "visit the manage service view", js: true do + let(:admin) { users(:admin_user) } + let(:steward) { users(:fifth_user) } + let(:user) { users(:fourth_user) } + + before do + organization.stewards << steward + end + + let(:lottery) { lotteries(:lottery_with_tickets_and_draws) } + let(:organization) { lottery.organization } + let(:entrant) { lottery_entrants(:lottery_entrant_0004) } + let(:person) { people(:bruno_fadel) } + + before { lottery.update(status: :finished) } + + scenario "user who is an admin" do + login_as admin, scope: :user + visit_page + + expect(page).to have_current_path(organization_lottery_entrant_service_detail_path(organization, lottery, entrant)) + end + + scenario "user who is a steward" do + login_as steward, scope: :user + visit_page + + expect(page).to have_current_path(organization_lottery_entrant_service_detail_path(organization, lottery, entrant)) + end + + scenario "user who has the same email as the entrant" do + entrant.update!(email: user.email) + login_as user, scope: :user + visit_page + + expect(page).to have_current_path(organization_lottery_entrant_service_detail_path(organization, lottery, entrant)) + end + + scenario "user who has the same person" do + entrant.update!(person: person) + person.update!(claimant: user) + login_as user, scope: :user + visit_page + + expect(page).to have_current_path(organization_lottery_entrant_service_detail_path(organization, lottery, entrant)) + end + + scenario "user who is not associated" do + login_as user, scope: :user + visit_page + + expect(page).to have_current_path(root_path) + expect(page).to have_text("Access denied") + end + + def visit_page + visit organization_lottery_entrant_service_detail_path(organization, lottery, entrant) + end +end