Skip to content

Commit

Permalink
Spec for uploading, downloading, and removing completed service form
Browse files Browse the repository at this point in the history
  • Loading branch information
moveson committed Dec 19, 2024
1 parent 561e730 commit 8208370
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 44 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
<% if presenter.rejected? %>
<td class="text-center"><%= fa_icon("circle-xmark", type: :solid, class: "text-danger") %></td>
<td>Rejected</td>
<td><%= l(presenter.service_form_rejected_at) %></td>
<td><%= presenter.service_form_rejected_comments %></td>
<td><%= l(presenter.form_rejected_at) %></td>
<td><%= presenter.form_rejected_comments %></td>
<% elsif presenter.accepted? %>
<td class="text-center"><%= fa_icon("circle-check", type: :solid, class: "text-success") %></td>
<td>Accepted</td>
<td><%= l(presenter.service_form_accepted_at) %></td>
<td><%= presenter.service_form_accepted_comments %></td>
<td><%= l(presenter.form_accepted_at) %></td>
<td><%= presenter.form_accepted_comments %></td>
<% elsif presenter.completed_form.attached? %>
<td class="text-center"><%= fa_icon("file-magnifying-glass", type: :solid, class: "text-secondary") %></td>
<td>Under review</td>
Expand Down
Binary file added service_form.pdf
Binary file not shown.
Binary file added spec/fixtures/files/service_form.pdf
Binary file not shown.
4 changes: 4 additions & 0 deletions spec/support/basic_configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
133 changes: 94 additions & 39 deletions spec/system/lotteries/manage_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
63 changes: 63 additions & 0 deletions spec/system/lotteries/visit_manage_service_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8208370

Please sign in to comment.