From 852a040acceb82986fedad69677aabd9612fb5e7 Mon Sep 17 00:00:00 2001 From: mononoken Date: Sat, 9 Mar 2024 19:47:18 -0800 Subject: [PATCH] Add tests for new withdrawing and retiring application methods --- test/integration/adopter_application_test.rb | 2 +- test/models/adopter_application_test.rb | 48 ++++++++++++++++++++ test/models/match_test.rb | 29 ++++++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 test/models/adopter_application_test.rb diff --git a/test/integration/adopter_application_test.rb b/test/integration/adopter_application_test.rb index 77ef7e92c..cf0528c32 100644 --- a/test/integration/adopter_application_test.rb +++ b/test/integration/adopter_application_test.rb @@ -1,6 +1,6 @@ require "test_helper" -class AdopterApplicationTest < ActionDispatch::IntegrationTest +class AdopterApplicationIntegrationTest < ActionDispatch::IntegrationTest setup do @organization = create(:organization) @pet_id = create(:pet, organization: @organization).id diff --git a/test/models/adopter_application_test.rb b/test/models/adopter_application_test.rb new file mode 100644 index 000000000..327da43d2 --- /dev/null +++ b/test/models/adopter_application_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class AdopterApplicationTest < ActiveSupport::TestCase + setup do + @application = create(:adopter_application) + end + + context "self.retire_applications" do + context "when some applications match pet_id and some do not" do + setup do + @selected_applications = Array.new(3) { + create(:adopter_application, pet_id: @application.pet_id) + } + @unselected_applications = Array.new(2) { + create(:adopter_application) + } + end + + should "update status of matching applications to :adoption_made" do + AdopterApplication.retire_applications(pet_id: @application.pet_id) + + @selected_applications.each do |application| + assert_equal "adoption_made", application.reload.status + end + end + + should "not update status of mismatching applications" do + cached_statuses = @unselected_applications.map(&:status) + + AdopterApplication.retire_applications(pet_id: @application.pet_id) + + current_statuses = @unselected_applications.map do |application| + application.reload.status + end + + assert_equal cached_statuses, current_statuses + end + end + end + + context "#withdraw" do + should "update status to :withdrawn" do + @application.withdraw + + assert "withdrawn", @application.status + end + end +end diff --git a/test/models/match_test.rb b/test/models/match_test.rb index 31481f09d..127a15c4b 100644 --- a/test/models/match_test.rb +++ b/test/models/match_test.rb @@ -7,4 +7,33 @@ class MatchTest < ActiveSupport::TestCase should belong_to(:pet) should belong_to(:adopter_account) end + + setup do + @match = build_stubbed(:match) + end + + context "#withdraw_application" do + setup do + @application = mock("adopter_application") + end + + should "send #withdraw to application" do + @match.expects(:adopter_application).returns(@application) + @application.expects(:withdraw) + + @match.withdraw_application + end + end + + context "#retire_applications" do + setup do + @application_class = mock("AdopterApplication") + end + + should "send #retire_applications with pet_id to application_class" do + @application_class.expects(:retire_applications).with(pet_id: @match.pet_id) + + @match.retire_applications(application_class: @application_class) + end + end end