Skip to content

Commit

Permalink
Add tests for new withdrawing and retiring application methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mononoken committed Mar 10, 2024
1 parent 6ccae8f commit 852a040
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/integration/adopter_application_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
48 changes: 48 additions & 0 deletions test/models/adopter_application_test.rb
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions test/models/match_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 852a040

Please sign in to comment.