diff --git a/spec/jobs/match_appearance_releases_job_spec.rb b/spec/jobs/match_appearance_releases_job_spec.rb index 659c15e..6795c1b 100644 --- a/spec/jobs/match_appearance_releases_job_spec.rb +++ b/spec/jobs/match_appearance_releases_job_spec.rb @@ -10,14 +10,10 @@ describe MatchAppearanceReleasesJob do end describe ".perform_now" do - # before do - # allow(ProjectsChannel).to receive(:appearance_matching_flash_message).with(be_kind_of(Project), I18n.t("appearance_releases.create.matching_completed")) - # end - - it "returns if no attachment is sent" do expect(MatchingRequest).not_to receive(:create) attachments = [] + expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), failure_flash_message, :alert) MatchAppearanceReleasesJob.perform_now project, attachments end @@ -25,6 +21,7 @@ describe MatchAppearanceReleasesJob do expect(MatchingRequest).not_to receive(:create) dummy_video = create(:video) attachments = [dummy_video.file.blob.signed_id] + expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), failure_flash_message, :alert) MatchAppearanceReleasesJob.perform_now project, attachments end @@ -49,14 +46,14 @@ describe MatchAppearanceReleasesJob do expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response) expect(dummy_matching_request).to receive(:destroy) + expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), success_flash_message) + expect { MatchAppearanceReleasesJob.perform_now project, signed_ids }.to change{AppearanceRelease.count}.by(1) expect(AppearanceRelease.last.contract).not_to be_attached expect(AppearanceRelease.last.person_photo).to be_attached - - # expect(ProjectsChannel).to receive(:appearance_matching_flash_message) end it "creates a new incomplete appearance release for contracts which cannot be matched by BrayniacAI" do @@ -80,6 +77,8 @@ describe MatchAppearanceReleasesJob do expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response) expect(dummy_matching_request).to receive(:destroy) + expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), success_flash_message) + expect { MatchAppearanceReleasesJob.perform_now project, signed_ids }.to change{AppearanceRelease.count}.by(1) @@ -116,6 +115,8 @@ describe MatchAppearanceReleasesJob do expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response) expect(dummy_matching_request).to receive(:destroy) + expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), success_flash_message) + MatchAppearanceReleasesJob.perform_now project, signed_ids expect(AppearanceRelease.last.identifier).to eq mock_match.identifier @@ -151,6 +152,8 @@ describe MatchAppearanceReleasesJob do expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response) expect(dummy_matching_request).to receive(:destroy) + expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), success_flash_message) + expect { MatchAppearanceReleasesJob.perform_now project, signed_ids }.to change{AppearanceRelease.count}.by(2) @@ -194,6 +197,8 @@ describe MatchAppearanceReleasesJob do expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response) expect(dummy_matching_request).to receive(:destroy) + expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), success_flash_message) + MatchAppearanceReleasesJob.perform_now project, signed_ids expect(AppearanceRelease.last.identifier).to eq mock_match.identifier @@ -235,6 +240,8 @@ describe MatchAppearanceReleasesJob do expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response) expect(dummy_matching_request).to receive(:destroy) + expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), success_flash_message) + MatchAppearanceReleasesJob.perform_now project, signed_ids expect(AppearanceRelease.last.identifier).to eq mock_match.identifier @@ -282,6 +289,8 @@ describe MatchAppearanceReleasesJob do expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response) expect(dummy_matching_request).to receive(:destroy) + expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), success_flash_message) + MatchAppearanceReleasesJob.perform_now project, signed_ids releases = AppearanceRelease.last(2) @@ -295,4 +304,14 @@ describe MatchAppearanceReleasesJob do expect(releases[1].contract.attached?).to eq true end end + + private + + def success_flash_message + I18n.t 'appearance_releases.create.matching_completed' + end + + def failure_flash_message + I18n.t 'appearance_releases.create.matching_failed' + end end