Files
vikunja/pkg/notifications/notify_disabled_test.go
kolaente eea59c33c7 fix: isolate deletion notifications into per-user transactions
On Postgres, a failed operation puts the transaction in an error state
where subsequent operations fail. The previous loop with continue would
keep trying to use a broken transaction. Each user now gets its own
transaction so a single notification failure doesn't affect others.
2026-02-25 11:03:02 +01:00

62 lines
2.1 KiB
Go

// Vikunja is a to-do list application to facilitate your life.
// Copyright 2018-present Vikunja and contributors. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package notifications
import (
"testing"
"time"
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/i18n"
"xorm.io/xorm"
)
type disabledMailNotifiable struct{}
func (d *disabledMailNotifiable) RouteForMail() (string, error) { return "test@example.com", nil }
func (d *disabledMailNotifiable) RouteForDB() int64 { return 1 }
func (d *disabledMailNotifiable) ShouldNotify(_ ...*xorm.Session) (bool, error) { return true, nil }
func (d *disabledMailNotifiable) Lang() string { return "en" }
type disabledMailNotification struct{}
func (n *disabledMailNotification) ToMail(string) *Mail {
return NewMail().Subject("Test").Line("Test")
}
func (n *disabledMailNotification) ToDB() any { return nil }
func (n *disabledMailNotification) Name() string { return "disabled.mail.notification" }
func TestNotifyDoesNotBlockWhenMailerDisabled(t *testing.T) {
config.InitDefaultConfig()
config.MailerEnabled.Set(false)
i18n.Init()
done := make(chan struct{})
go func() {
_ = Notify(&disabledMailNotifiable{}, &disabledMailNotification{})
close(done)
}()
select {
case <-done:
// Success - Notify returned without blocking
case <-time.After(1 * time.Second):
t.Fatal("Notify blocked when mailer was disabled")
}
}