Skip to content

Commit 7e6680a

Browse files
committed
fix: purge FcmRegistrations in GuildPurgeService (guild-keyed credentials)
1 parent 759614a commit 7e6680a

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/RustPlusBot.Features.Workspace/Teardown/GuildPurgeService.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ public async Task PurgeGuildAsync(ulong guildId, CancellationToken cancellationT
2727
await servers.RemoveAsync(guildId, server.Id, cancellationToken).ConfigureAwait(false);
2828
}
2929

30-
// 3) Delete guild-keyed rows that have no cascade FK to RustServer.
30+
// 3) Delete guild-keyed rows that have no cascade FK to RustServer (event subscriptions,
31+
// paired entities, guild settings, FCM registrations).
3132
await context.EventSubscriptions.Where(e => e.GuildId == guildId)
3233
.ExecuteDeleteAsync(cancellationToken).ConfigureAwait(false);
3334
await context.PairedEntities.Where(p => p.GuildId == guildId)
3435
.ExecuteDeleteAsync(cancellationToken).ConfigureAwait(false);
3536
await context.GuildSettings.Where(g => g.GuildId == guildId)
3637
.ExecuteDeleteAsync(cancellationToken).ConfigureAwait(false);
38+
await context.FcmRegistrations.Where(f => f.GuildId == guildId)
39+
.ExecuteDeleteAsync(cancellationToken).ConfigureAwait(false);
3740
}
3841
}

tests/RustPlusBot.Features.Workspace.Tests/Teardown/GuildPurgeServiceTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.EntityFrameworkCore;
33
using NSubstitute;
44
using RustPlusBot.Domain.Connections;
5+
using RustPlusBot.Domain.Credentials;
56
using RustPlusBot.Domain.Entities;
67
using RustPlusBot.Domain.Events;
78
using RustPlusBot.Domain.Guilds;
@@ -68,6 +69,14 @@ public async Task PurgeGuild_RemovesTargetGuildRows_AndLeavesOtherGuildIntact()
6869
{
6970
GuildId = 2, Culture = "fr"
7071
});
72+
context.FcmRegistrations.Add(new FcmRegistration
73+
{
74+
GuildId = 1, OwnerUserId = 100, ProtectedFcmCredentials = "x"
75+
});
76+
context.FcmRegistrations.Add(new FcmRegistration
77+
{
78+
GuildId = 2, OwnerUserId = 200, ProtectedFcmCredentials = "y"
79+
});
7180
await context.SaveChangesAsync();
7281

7382
var teardown = Substitute.For<IWorkspaceTeardownService>();
@@ -82,10 +91,12 @@ public async Task PurgeGuild_RemovesTargetGuildRows_AndLeavesOtherGuildIntact()
8291
Assert.Empty(await context.EventSubscriptions.Where(e => e.GuildId == 1).ToListAsync());
8392
Assert.Empty(await context.PairedEntities.Where(p => p.GuildId == 1).ToListAsync());
8493
Assert.Empty(await context.GuildSettings.Where(g => g.GuildId == 1).ToListAsync());
94+
Assert.Empty(await context.FcmRegistrations.Where(f => f.GuildId == 1).ToListAsync());
8595

8696
// Guild 2 untouched.
8797
Assert.Single(await context.RustServers.Where(s => s.GuildId == 2).ToListAsync());
8898
Assert.Single(await context.EventSubscriptions.Where(e => e.GuildId == 2).ToListAsync());
8999
Assert.Single(await context.GuildSettings.Where(g => g.GuildId == 2).ToListAsync());
100+
Assert.Single(await context.FcmRegistrations.Where(f => f.GuildId == 2).ToListAsync());
90101
}
91102
}

0 commit comments

Comments
 (0)