Skip to content

Commit

Permalink
Spec for lottery service form upload, download, and remove
Browse files Browse the repository at this point in the history
  • Loading branch information
moveson committed Dec 19, 2024
1 parent 8208370 commit 62ba575
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails_helper"

RSpec.describe "manage lottery service", js: true do
RSpec.describe "manage entrant service form upload and download", js: true do
let(:user) { users(:fourth_user) }

let(:lottery) { lotteries(:lottery_with_tickets_and_draws) }
Expand Down
82 changes: 82 additions & 0 deletions spec/system/lotteries/manage_lottery_service_form_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe "manage lottery service form upload and download", js: true do
let(:steward) { users(:third_user) }

let(:lottery) { lotteries(:lottery_with_tickets_and_draws) }
let(:organization) { lottery.organization }
let(:download_path) { Rails.root.join("tmp/downloads") }

before do
lottery.update(status: :finished)
organization.stewards << steward
stewardship = organization.stewardships.find_by(user: steward)
stewardship.update(level: :lottery_manager)
end

context "service form not yet uploaded" do
scenario "user uploads a service form" do
login_as steward, scope: :user
visit_page

expect(page).to have_current_path(page_path)
expect(page).to have_text("Drag here to upload")

attach_file_and_validate
expect(page).to have_link("Download")
expect(page).to have_button("Remove")
end
end

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 steward, scope: :user
visit_page

expect(page).to have_current_path(page_path)

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 removes the service form" do
login_as steward, scope: :user
visit_page

expect(page).to have_current_path(page_path)

click_button "Remove"
expect(page).to have_current_path(page_path)
expect(page).not_to have_link("Download")
expect(page).not_to have_button("Remove")
end
end

def visit_page
visit page_path
end

def page_path
setup_organization_lottery_path(organization, lottery)
end

def attach_file_and_validate
find(".dropzone").drop(file_fixture("service_form.pdf"))
click_button "Attach"
sleep 1
expect(lottery.service_form.attached?).to eq(true)
end
end

0 comments on commit 62ba575

Please sign in to comment.