Add Discord guild ID configuration and enhance event announcement options
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:
@@ -54,6 +54,77 @@ func TestMigrationsAndReadiness(t *testing.T) {
|
||||
if !bracketTable {
|
||||
t.Fatal("event_bracket_drafts table is missing")
|
||||
}
|
||||
for _, table := range []string{"discord_managed_roles", "discord_role_assignments", "discord_role_sync_jobs"} {
|
||||
var exists bool
|
||||
if err := store.pool.QueryRow(ctx, `SELECT to_regclass('public.' || $1) IS NOT NULL`, table).Scan(&exists); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !exists {
|
||||
t.Fatalf("%s table is missing", table)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiscordRoleSyncPersistence(t *testing.T) {
|
||||
databaseURL := os.Getenv("TEST_DATABASE_URL")
|
||||
if databaseURL == "" {
|
||||
t.Skip("TEST_DATABASE_URL is not configured")
|
||||
}
|
||||
ctx := context.Background()
|
||||
if err := Migrate(ctx, databaseURL, "../../../migrations"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store, err := Open(ctx, databaseURL)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
eventID := fmt.Sprintf("discord-sync-%d", time.Now().UnixNano())
|
||||
role := application.DiscordManagedRole{
|
||||
Scope: application.DiscordRoleScopeEvent, EventID: eventID, TeamID: "team-1",
|
||||
Kind: application.DiscordRoleKindTeam, DiscordRoleID: eventID + "-role", RoleName: "Alpha",
|
||||
}
|
||||
defer func() {
|
||||
_, _ = store.pool.Exec(ctx, `DELETE FROM discord_role_sync_jobs WHERE event_id=$1`, eventID)
|
||||
_, _ = store.pool.Exec(ctx, `DELETE FROM discord_managed_roles WHERE event_id=$1`, eventID)
|
||||
}()
|
||||
if err = store.UpsertDiscordManagedRole(ctx, role); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = store.UpsertDiscordRoleAssignment(ctx, role.DiscordRoleID, "discord-user"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assignments, err := store.ListDiscordRoleAssignments(ctx, role.DiscordRoleID)
|
||||
if err != nil || len(assignments) != 1 || assignments[0] != "discord-user" {
|
||||
t.Fatalf("unexpected assignments: %v err=%v", assignments, err)
|
||||
}
|
||||
if _, err = store.pool.Exec(ctx, `UPDATE discord_role_sync_jobs SET status='completed' WHERE status='pending'`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = store.EnqueueDiscordRoleSync(ctx, eventID, application.DiscordRoleActionReconcile, 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
job, err := store.ClaimDiscordRoleSyncJob(ctx)
|
||||
if err != nil || job.EventID != eventID || len(job.RoleSnapshot) != 1 || job.Attempts != 1 {
|
||||
t.Fatalf("unexpected claimed job: %+v err=%v", job, err)
|
||||
}
|
||||
if err = store.RetryDiscordRoleSyncJob(ctx, job.ID, "retry", time.Now().Add(-time.Second)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
job, err = store.ClaimDiscordRoleSyncJob(ctx)
|
||||
if err != nil || job.Attempts != 2 {
|
||||
t.Fatalf("unexpected retried job: %+v err=%v", job, err)
|
||||
}
|
||||
if err = store.CompleteDiscordRoleSyncJob(ctx, job.ID, "warning"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var status, warning string
|
||||
if err = store.pool.QueryRow(ctx, `SELECT status,last_error FROM discord_role_sync_jobs WHERE id=$1`, job.ID).Scan(&status, &warning); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if status != "completed" || warning != "warning" {
|
||||
t.Fatalf("unexpected completed job state: status=%s warning=%s", status, warning)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFullScrimPipeline(t *testing.T) {
|
||||
@@ -82,6 +153,7 @@ func TestFullScrimPipeline(t *testing.T) {
|
||||
defer func() {
|
||||
_, _ = store.pool.Exec(ctx, `DELETE FROM audit_log WHERE actor_account_id=$1`, accountID)
|
||||
_, _ = store.pool.Exec(ctx, `DELETE FROM events WHERE id=$1`, eventID)
|
||||
_, _ = store.pool.Exec(ctx, `DELETE FROM discord_role_sync_jobs WHERE event_id=$1`, eventID)
|
||||
for _, seriesID := range seriesIDs {
|
||||
_, _ = store.pool.Exec(ctx, `DELETE FROM series WHERE id=$1`, seriesID)
|
||||
}
|
||||
@@ -97,7 +169,7 @@ func TestFullScrimPipeline(t *testing.T) {
|
||||
event, err := service.CreateEvent(ctx, admin, domain.Event{
|
||||
ID: eventID, Name: "Pipeline", StartsAt: now.Add(24 * time.Hour), EndsAt: now.Add(28 * time.Hour),
|
||||
RegistrationDeadline: now.Add(23 * time.Hour), RulesetID: "standard-control-hybrid-control",
|
||||
})
|
||||
}, application.CreateEventOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -217,13 +289,14 @@ func TestParallelTournamentHydratesLiveSeriesAndFinal(t *testing.T) {
|
||||
defer func() {
|
||||
_, _ = store.pool.Exec(ctx, `DELETE FROM series WHERE tournament_id=$1`, tournamentID)
|
||||
_, _ = store.pool.Exec(ctx, `DELETE FROM events WHERE id=$1`, eventID)
|
||||
_, _ = store.pool.Exec(ctx, `DELETE FROM discord_role_sync_jobs WHERE event_id=$1`, eventID)
|
||||
_, _ = store.pool.Exec(ctx, `DELETE FROM accounts WHERE id=$1`, accountID)
|
||||
}()
|
||||
service := application.New(store, discardPublisher{}, nil)
|
||||
event, err := service.CreateEvent(ctx, domain.Account{ID: accountID, Role: domain.RoleAdmin}, domain.Event{
|
||||
ID: eventID, Name: "Parallel tournament", StartsAt: time.Now().Add(time.Hour), EndsAt: time.Now().Add(3 * time.Hour),
|
||||
RegistrationDeadline: time.Now(), RulesetID: "standard-control-hybrid-control",
|
||||
})
|
||||
}, application.CreateEventOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user