Skip to content

Commit

Permalink
Adjust the tests to match the new structure of the class
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorcorrea committed Oct 24, 2022
1 parent c2e5541 commit d417390
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions spec/services/work_upload_edit_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require "rails_helper"

RSpec.describe WorkUploadsEditService do
let(:user) { FactoryBot.create :research_data_moderator}
let(:work) { FactoryBot.create :draft_work }
let(:uploaded_file) do
fixture_file_upload("us_covid_2019.csv", "text/csv")
Expand Down Expand Up @@ -32,7 +33,8 @@
let(:params) { { "work_id" => "" }.with_indifferent_access }

it "returns all existing files" do
updated_work = described_class.update_precurated_file_list(work, params)
upload_service = described_class.new(work, user)
updated_work = upload_service.update_precurated_file_list(params)
list = updated_work.pre_curation_uploads
expect(list.map(&:filename)).to eq([uploaded_file.original_filename])
expect(a_request(:delete, attachment_url)).not_to have_been_made
Expand All @@ -51,7 +53,8 @@
end

it "returns all existing files except the deleted one" do
updated_work = described_class.update_precurated_file_list(work, params)
upload_service = described_class.new(work, user)
updated_work = upload_service.update_precurated_file_list(params)
list = updated_work.pre_curation_uploads
expect(list.map(&:filename)).to eq([uploaded_file2.original_filename])
expect(a_request(:delete, attachment_url)).to have_been_made.once
Expand All @@ -67,7 +70,8 @@
let(:params) { { "work_id" => "", "replaced_uploads" => { "1" => uploaded_file4 } }.with_indifferent_access }

it "replaces the correct file" do
updated_work = described_class.update_precurated_file_list(work, params)
upload_service = described_class.new(work, user)
updated_work = upload_service.update_precurated_file_list(params)
list = updated_work.pre_curation_uploads

# remeber order of the files will be alphabetical
Expand All @@ -80,7 +84,8 @@
let(:params) { { "work_id" => "", "pre_curation_uploads" => [uploaded_file2, uploaded_file3] }.with_indifferent_access }

it "replaces all the files" do
updated_work = described_class.update_precurated_file_list(work, params)
upload_service = described_class.new(work, user)
updated_work = upload_service.update_precurated_file_list(params)
list = updated_work.reload.pre_curation_uploads
expect(list.map(&:filename)).to eq([uploaded_file2.original_filename, uploaded_file3.original_filename])
expect(a_request(:delete, attachment_url)).to have_been_made.once
Expand All @@ -91,7 +96,8 @@
let(:params) { { "work_id" => "", "pre_curation_uploads" => [uploaded_file, uploaded_file3] }.with_indifferent_access }

it "replaces all the files" do
updated_work = described_class.update_precurated_file_list(work, params)
upload_service = described_class.new(work, user)
updated_work = upload_service.update_precurated_file_list(params)
list = updated_work.pre_curation_uploads
expect(list.map(&:filename)).to eq([uploaded_file.original_filename, uploaded_file3.original_filename])

Expand Down

0 comments on commit d417390

Please sign in to comment.