Skip to content

Commit

Permalink
updated spec scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
edwin-jebaraj committed Dec 8, 2024
1 parent 0558b06 commit 23c6111
Showing 1 changed file with 49 additions and 26 deletions.
75 changes: 49 additions & 26 deletions spec/features/support/agent_can_upload_evaluation_documents_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
require "rails_helper"

RSpec.describe "Agent can upload evaluation documents", type: :feature do
RSpec.feature "Agent can upload evaluation documents", :js, :with_csrf_protection do
include_context "with an agent"

let(:support_case) { create(:support_case) }
let(:file_1) { fixture_file_upload(Rails.root.join("spec/fixtures/support/text-file.txt"), "text/plain") }
let(:file_2) { fixture_file_upload(Rails.root.join("spec/fixtures/support/another-text-file.txt"), "text/plain") }
let(:document_uploader) { support_case.document_uploader(files: [file_1, file_2]) }

specify "Upload documents" do
specify "when no files are selected" do
visit edit_support_case_document_uploads_path(case_id: support_case)

expect(page).to have_text("Upload documents")
Expand All @@ -21,37 +22,59 @@
expect(page).to have_text("Please confirm that you uploaded all documents")
end

context "when files are uploaded" do
let(:document_uploader) { support_case.document_uploader(files: [file_1, file_2]) }
let(:is_upload_documents) { true }
specify "when files are uploaded and confirmation choosen as No (In progress)" do
support_case.update!(is_upload_documents: false)

it "attaches the files to the case" do
expect { document_uploader.save! }.to change { support_case.upload_documents.count }.from(0).to(2)
expect(support_case.upload_documents.pluck(:file_name)).to contain_exactly("text-file.txt", "another-text-file.txt")
expect(support_case.upload_documents.map { |a| a.file.attached? }.all?).to eq(true)
end
expect { document_uploader.save! }.to change { support_case.upload_documents.count }.from(0).to(2)
expect(support_case.upload_documents.pluck(:file_name)).to contain_exactly("text-file.txt", "another-text-file.txt")
expect(support_case.upload_documents.map { |a| a.file.attached? }.all?).to eq(true)

visit support_case_path(support_case, anchor: "tasklist")

expect(find("#complete-evaluation-3-status")).to have_text("In progress")
end

specify "when files are uploaded and confirmation choosen as Yes (Complete)" do
support_case.update!(is_upload_documents: true)

expect { document_uploader.save! }.to change { support_case.upload_documents.count }.from(0).to(2)
expect(support_case.upload_documents.pluck(:file_name)).to contain_exactly("text-file.txt", "another-text-file.txt")
expect(support_case.upload_documents.map { |a| a.file.attached? }.all?).to eq(true)

visit support_case_path(support_case, anchor: "tasklist")

expect(find("#complete-evaluation-3-status")).to have_text("Complete")
end

context "when no files are uploaded" do
let(:document_uploader) { support_case.document_uploader }
specify "viewing uploaded files and deleting files" do
support_case.update!(is_upload_documents: true)
document_uploader.save!

visit edit_support_case_document_uploads_path(case_id: support_case)

expect(page).to have_content("text-file.txt")
expect(page).to have_content("another-text-file.txt")

find_all(".case-files__file-remove a")[0].click

expect(find(".govuk-button--warning")).to have_content("Delete")

it "fails validation" do
expect(document_uploader).not_to be_valid
expect(document_uploader.errors.messages[:files]).to eq ["Select files to upload"]
end
expect(page).to have_content("text-file.txt")
end

context "when uploaded files contain viruses" do
before do
allow(Support::VirusScanner).to receive(:uploaded_file_safe?).with(file_1).and_return(true)
allow(Support::VirusScanner).to receive(:uploaded_file_safe?).with(file_2).and_return(false)
end
specify "when all files are deleted" do
support_case.reload

support_case.upload_documents(&:destroy!)

support_case.reload

support_case.update!(is_upload_documents: nil)

expect(support_case.upload_documents.count).to eq(0)

let(:document_uploader) { support_case.document_uploader(files: [file_1, file_2]) }
visit support_case_path(support_case, anchor: "tasklist")

it "fails validation" do
expect(document_uploader).not_to be_valid
expect(document_uploader.errors.messages[:files]).to eq ["One or more selected files contained a virus and have been rejected"]
end
expect(find("#complete-evaluation-3-status", wait: 10)).to have_text("To do")
end
end

0 comments on commit 23c6111

Please sign in to comment.