@@ -102,6 +102,43 @@ class ShipTest < ActiveSupport::TestCase
102102 assert_equal [ "Ship it" , "https://wrong.hackclub.com/ship" ] , dms . first [ :args ] . third [ "link" ]
103103 end
104104
105+ test "last call DMs everyone who never shipped with an hour or more, once, and a dry run sends nothing" do
106+ require "rake"
107+ Rails . application . load_tasks unless Rake ::Task . task_defined? ( "ships:last_call" )
108+ ship_now ( hours : 2 ) # in review: not owed
109+ ana = projects ( :ana )
110+ link_hackatime ( ana . user , token : "token-heidi" )
111+ ana . update! ( hackatime_projects : [ "heidis-game" ] )
112+ ana . ships . create! ( title : "Pong in Figma" , description : "Two paddles, one ball, and every frame is a Figma component." ,
113+ repo_url : "https://example.com/repo" , demo_url : "https://example.com/demo" , hours : 1 ,
114+ screenshot : fixture_upload , screenshot_shows_game : true ) . update! ( status : "rejected" )
115+ ana . user . streak_activities . create! ( activity_date : Program ::DATES . begin , coded_seconds : 2 * 3600 )
116+
117+ with_env ( "DRY_RUN" => "1" ) { capture_io { Rake ::Task [ "ships:last_call" ] . execute } }
118+ assert_empty enqueued_jobs . select { |job | job [ :job ] == SlackMessageJob }
119+
120+ capture_io { Rake ::Task [ "ships:last_call" ] . execute }
121+ dms = enqueued_jobs . select { |job | job [ :job ] == SlackMessageJob }
122+ assert_equal [ "U0ANA" ] , dms . map { |job | job [ :args ] . first }
123+ assert_equal "Shipping's open again for anyone who didn't make it. *Pong in Figma* can ship until the end of Nov 5, " \
124+ "finished or not. If it plays, ship it.\n :clippy-hopeful: clippy propped the door back open for you. :blob-wiggle:" ,
125+ dms . first [ :args ] . second
126+ assert_not_nil ana . reload . last_call_dmed_at
127+
128+ clear_enqueued_jobs
129+ capture_io { Rake ::Task [ "ships:last_call" ] . execute }
130+ assert_empty enqueued_jobs . select { |job | job [ :job ] == SlackMessageJob } , "once"
131+ end
132+
133+ test "last call skips anyone under an hour" do
134+ require "rake"
135+ Rails . application . load_tasks unless Rake ::Task . task_defined? ( "ships:last_call" )
136+ @project . user . streak_activities . create! ( activity_date : Program ::DATES . begin , coded_seconds : 30 * 60 )
137+
138+ capture_io { Rake ::Task [ "ships:last_call" ] . execute }
139+ assert_empty enqueued_jobs . select { |job | job [ :job ] == SlackMessageJob }
140+ end
141+
105142 private
106143 def with_env ( vars )
107144 originals = vars . keys . index_with { |key | ENV [ key ] }
0 commit comments