-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spec for lottery service form upload, download, and remove
- Loading branch information
Showing
2 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |