mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-07-15 22:32:29 -05:00
Add NotificationCreatedEvent that fires automatically when a DatabaseNotification is inserted, using XORM's AfterInsertProcessor interface. The AfterInsert hook dispatches the event after the row is persisted, without callers needing to manage DispatchOnCommit or DispatchPending. The WebSocket listener subscribes to this event, reloads the notification from the database (ensuring accurate timestamps), and pushes it to connected clients subscribed to the notification.created event. Dispatch errors are logged rather than propagated since the DB notification is already committed at that point.
61 lines
1.5 KiB
Go
61 lines
1.5 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 (
|
|
"os"
|
|
"testing"
|
|
|
|
"code.vikunja.io/api/pkg/config"
|
|
"code.vikunja.io/api/pkg/db"
|
|
"code.vikunja.io/api/pkg/events"
|
|
"code.vikunja.io/api/pkg/i18n"
|
|
"code.vikunja.io/api/pkg/log"
|
|
"code.vikunja.io/api/pkg/mail"
|
|
)
|
|
|
|
// SetupTests initializes all db tests
|
|
func SetupTests() {
|
|
var err error
|
|
x, err := db.CreateTestEngine()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
err = x.Sync2(&DatabaseNotification{})
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
i18n.Init()
|
|
}
|
|
|
|
// TestMain is the main test function used to bootstrap the test env
|
|
func TestMain(m *testing.M) {
|
|
// Initialize logger for tests
|
|
log.InitLogger()
|
|
|
|
// Set default config
|
|
config.InitDefaultConfig()
|
|
|
|
SetupTests()
|
|
|
|
mail.Fake()
|
|
events.Fake()
|
|
os.Exit(m.Run())
|
|
}
|