Add Discord guild ID configuration and enhance event announcement options
Some checks failed
CI / backend (push) Has been cancelled
CI / frontend (push) Has been cancelled
CI / compose (push) Has been cancelled

This commit introduces the `DISCORD_GUILD_ID` environment variable to the configuration files, allowing for better integration with Discord for role synchronization. The event announcement functionality has been updated to include an option for the `@everyone` mention, which can be toggled during event creation. The backend logic has been modified to handle this new option, and corresponding updates have been made to the frontend to allow users to control the mention behavior. Additionally, tests have been added to ensure the correct functionality of these features.
This commit is contained in:
2026-07-19 11:34:11 +03:00
parent ae19c03542
commit c3624376b0
29 changed files with 1524 additions and 37 deletions

View File

@@ -33,12 +33,14 @@ func (p *recordingPublisher) Publish(topic string, _ any) {
type recordingAnnouncer struct {
events []domain.Event
pings []bool
err error
hasDeadline bool
}
func (a *recordingAnnouncer) AnnounceEventCreated(ctx context.Context, event domain.Event) error {
func (a *recordingAnnouncer) AnnounceEventCreated(ctx context.Context, event domain.Event, pingEveryone bool) error {
a.events = append(a.events, event)
a.pings = append(a.pings, pingEveryone)
_, a.hasDeadline = ctx.Deadline()
return a.err
}
@@ -51,7 +53,7 @@ func TestCreateEventAnnouncesAfterPersistence(t *testing.T) {
now := time.Date(2026, time.July, 19, 8, 0, 0, 0, time.UTC)
service.Now = func() time.Time { return now }
created, err := service.CreateEvent(context.Background(), domain.Account{ID: "admin", Role: domain.RoleAdmin}, validEvent(now))
created, err := service.CreateEvent(context.Background(), domain.Account{ID: "admin", Role: domain.RoleAdmin}, validEvent(now), CreateEventOptions{PingEveryone: true})
if err != nil {
t.Fatal(err)
}
@@ -64,6 +66,9 @@ func TestCreateEventAnnouncesAfterPersistence(t *testing.T) {
if !announcer.hasDeadline {
t.Fatal("announcement context must have a timeout")
}
if len(announcer.pings) != 1 || !announcer.pings[0] {
t.Fatalf("expected @everyone option, got %v", announcer.pings)
}
if len(bus.topics) != 1 || bus.topics[0] != "events" {
t.Fatalf("unexpected published topics: %v", bus.topics)
}
@@ -77,7 +82,7 @@ func TestCreateEventDoesNotAnnouncePersistenceFailure(t *testing.T) {
now := time.Date(2026, time.July, 19, 8, 0, 0, 0, time.UTC)
service.Now = func() time.Time { return now }
_, err := service.CreateEvent(context.Background(), domain.Account{ID: "admin", Role: domain.RoleAdmin}, validEvent(now))
_, err := service.CreateEvent(context.Background(), domain.Account{ID: "admin", Role: domain.RoleAdmin}, validEvent(now), CreateEventOptions{PingEveryone: true})
if !errors.Is(err, persistenceErr) {
t.Fatalf("expected persistence error, got %v", err)
}
@@ -93,7 +98,7 @@ func TestCreateEventIgnoresAnnouncementFailure(t *testing.T) {
now := time.Date(2026, time.July, 19, 8, 0, 0, 0, time.UTC)
service.Now = func() time.Time { return now }
created, err := service.CreateEvent(context.Background(), domain.Account{ID: "admin", Role: domain.RoleAdmin}, validEvent(now))
created, err := service.CreateEvent(context.Background(), domain.Account{ID: "admin", Role: domain.RoleAdmin}, validEvent(now), CreateEventOptions{PingEveryone: true})
if err != nil {
t.Fatalf("announcement failure must not fail event creation: %v", err)
}
@@ -102,6 +107,20 @@ func TestCreateEventIgnoresAnnouncementFailure(t *testing.T) {
}
}
func TestCreateEventCanAnnounceWithoutEveryonePing(t *testing.T) {
announcer := &recordingAnnouncer{}
service := New(&createEventStore{}, &recordingPublisher{}, announcer)
now := time.Date(2026, time.July, 19, 8, 0, 0, 0, time.UTC)
service.Now = func() time.Time { return now }
if _, err := service.CreateEvent(context.Background(), domain.Account{ID: "admin", Role: domain.RoleAdmin}, validEvent(now), CreateEventOptions{}); err != nil {
t.Fatal(err)
}
if len(announcer.events) != 1 || len(announcer.pings) != 1 || announcer.pings[0] {
t.Fatalf("expected one announcement without @everyone, events=%d pings=%v", len(announcer.events), announcer.pings)
}
}
func validEvent(now time.Time) domain.Event {
return domain.Event{
Name: "Sunday Mix",