Skip to content

Commit

Permalink
Use .any_instance.stub
Browse files Browse the repository at this point in the history
Testing locally helps :-)
  • Loading branch information
computermacgyver committed Nov 4, 2024
1 parent 8b4906c commit bfa87ad
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions test/models/bot/alegre_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,26 +185,32 @@ def teardown
}
]
})
ProjectMedia.stubs(:recalculate_last_seen).returns(Time.now - 2.months)
# Set the TeamBotInstallation (tbi) for Alegre so that a query
# matched to an item seen more than 1 month ago is downgraded to suggestion
tbi = Bot::Alegre.get_alegre_tbi(@team.id)
tbi.set_date_similarity_threshold_enabled = true
tbi.set_similarity_date_threshold("1")
tbi.save!

# First verify a confirmed_type relationship is not downgraded.
# because last_seen will be now and not more than one month ago.
assert_difference 'Relationship.count' do
result = Bot::Alegre.relate_project_media_to_similar_items(pm2)
end
r = Relationship.last
assert_equal Relationship.confirmed_type, r.relationship_type
r.destroy
pm1.created_at = Time.now - 2.months
pm1.save!
tbi = Bot::Alegre.get_alegre_tbi(@team.id)
tbi.set_date_similarity_threshold_enabled = true
tbi.set_similarity_date_threshold("1")
tbi.save!
r.destroy!

# Now stub last_seen so that confirmed_type is downgraded to suggest_type
# because it is more than tbi.similarity_date_threshold months old
ProjectMedia.any_instance.stubs(:last_seen).returns(Time.now - 2.months)
assert_difference 'Relationship.count' do
result = Bot::Alegre.relate_project_media_to_similar_items(pm2)
end
r = Relationship.last
assert_equal Relationship.suggested_type, r.relationship_type
Bot::Alegre.unstub(:request)
ProjectMedia.unstub(:recalculate_last_seen)
ProjectMedia.any_instance.unstub(:last_seen)
end

test "should index report data" do
Expand Down

0 comments on commit bfa87ad

Please sign in to comment.