Files
fizzy/test/models/card/entropy_test.rb
T
Jorge Manrubia 91787a3523 Revamp entropy configuraiton
- Move both settings to its dedicated model entropy configuration
- A collection can have an entropy configuration, or will default to the account if not
2025-06-04 10:41:08 +02:00

67 lines
2.1 KiB
Ruby

require "test_helper"
class Card::EntropyTest < ActiveSupport::TestCase
setup do
Current.session = sessions(:david)
end
test "auto_close_at infers the period from the collection" do
freeze_time
entropy_configurations(:writebook_collection).update! auto_close_period: 123.days
cards(:layout).update! last_active_at: 2.day.ago
assert_equal (123-2).days.from_now, cards(:layout).auto_close_at
end
test "auto close all due" do
cards(:logo, :shipping).each(&:reconsider)
cards(:logo).update!(last_active_at: 1.day.ago - entropy_configurations(:writebook_collection).auto_close_period)
cards(:shipping).update!(last_active_at: 1.day.from_now - entropy_configurations(:writebook_collection).auto_close_period)
assert_difference -> { Card.closed.count }, +1 do
Card.auto_close_all_due
end
assert cards(:logo).reload.closed?
assert_not cards(:shipping).reload.closed?
end
test "don't auto close those cards where the collection has no auto close period" do
cards(:logo, :shipping).each(&:reconsider)
collections(:writebook).entropy_configuration.destroy
assert_no_difference -> { Card.closed.count } do
Card.auto_close_all_due
end
assert_not cards(:logo).reload.closed?
end
test "auto_reconsider_all_stagnated" do
travel_to Time.current
cards(:logo, :shipping).each(&:engage)
cards(:logo).update!(last_active_at: 1.day.ago - Card::AUTO_RECONSIDER_PERIOD)
cards(:shipping).update!(last_active_at: 1.day.from_now - Card::AUTO_RECONSIDER_PERIOD)
assert_difference -> { Card.considering.count }, +1 do
Card.auto_reconsider_all_stagnated
end
assert cards(:shipping).reload.doing?
assert cards(:logo).reload.considering?
assert_equal Time.current, cards(:logo).last_active_at
end
test "entropy_cleaned_at returns when the entropy will be cleaned" do
assert_equal cards(:layout).auto_close_at, cards(:layout).entropy_cleaned_at
assert_not_nil cards(:layout).entropy_cleaned_at
assert_equal cards(:logo).auto_reconsider_at, cards(:logo).entropy_cleaned_at
assert_not_nil cards(:logo).entropy_cleaned_at
end
end