"""Tests for slack-bot _handle_register and _handle_rate.""" class TestRegister: def test_register_links_account( self, slackbot_app, schedule, seed, respond, text_of ): seed.roster("114", "Alice") slackbot_app._handle_register(respond, schedule, "U_ALICE", "register 114") assert "Linked" in text_of(respond) assert schedule.get_employee_by_extension("114")["slack_user_id"] == "U_ALICE" def test_register_unknown_extension(self, slackbot_app, schedule, respond, text_of): slackbot_app._handle_register(respond, schedule, "U_ALICE", "register 999") assert "not found" in text_of(respond).lower() def test_register_usage(self, slackbot_app, schedule, respond, text_of): slackbot_app._handle_register(respond, schedule, "U_ALICE", "register") assert "Usage" in text_of(respond) class TestRate: def test_show_rates(self, slackbot_app, schedule, seed, respond, text_of): seed.config(shift_rate="50") seed.roster("114", "Alice", shift_rate="75") slackbot_app._handle_rate(respond, schedule, "rate") text = text_of(respond) assert "$50.00" in text and "Alice" in text and "$75.00" in text def test_show_rates_no_custom(self, slackbot_app, schedule, seed, respond, text_of): seed.config(shift_rate="50") slackbot_app._handle_rate(respond, schedule, "rate") assert "No per-person rates" in text_of(respond) def test_set_default(self, slackbot_app, schedule, seed, respond, text_of): seed.config(shift_rate="50") slackbot_app._handle_rate(respond, schedule, "rate default 60") assert schedule.get_shift_rate() == 60.0 assert "$60.00" in text_of(respond) def test_set_default_invalid_amount(self, slackbot_app, schedule, respond, text_of): slackbot_app._handle_rate(respond, schedule, "rate default abc") assert "Invalid amount" in text_of(respond) def test_set_default_usage(self, slackbot_app, schedule, respond, text_of): slackbot_app._handle_rate(respond, schedule, "rate default") assert "Usage" in text_of(respond) def test_set_per_employee(self, slackbot_app, schedule, seed, respond, text_of): seed.roster("114", "Alice") slackbot_app._handle_rate(respond, schedule, "rate 114 90") assert schedule.get_shift_rate("114") == 90.0 assert "Alice" in text_of(respond) and "$90.00" in text_of(respond) def test_set_per_employee_unknown(self, slackbot_app, schedule, respond, text_of): slackbot_app._handle_rate(respond, schedule, "rate 999 90") assert "not found" in text_of(respond).lower() def test_set_per_employee_strips_dollar_sign( self, slackbot_app, schedule, seed, respond ): seed.roster("114", "Alice") slackbot_app._handle_rate(respond, schedule, "rate 114 $90") assert schedule.get_shift_rate("114") == 90.0