1
0

tgbot_delete_after_test.go 758 B

12345678910111213141516171819202122
  1. package tgbot
  2. import "testing"
  3. // A transient "delete after N seconds" message must not reset the conversation
  4. // state when its timer fires: the user may have advanced to the next wizard step
  5. // (setting a fresh state) within that window, and clearing it would silently
  6. // drop their next input.
  7. func TestDeleteMessageAfterDelayKeepsUserState(t *testing.T) {
  8. userStateMgr.reset()
  9. t.Cleanup(userStateMgr.reset)
  10. const chatID = int64(4242)
  11. userStateMgr.set(chatID, "awaiting_comment")
  12. tg := &Tgbot{}
  13. tg.deleteMessageAfterDelay(chatID, 1, 0)
  14. if st, ok := userStateMgr.get(chatID); !ok || st != "awaiting_comment" {
  15. t.Fatalf("delayed message deletion cleared the conversation state: got (%q, %v), want (%q, true)", st, ok, "awaiting_comment")
  16. }
  17. }