mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-23 13:41:31 +00:00
Don't dismiss already dismissed cases in repeating task (#897)
* Don't dismiss already dismissed cases in repeating task * Implement unit test to cover patch * Remove unnecessary null check
This commit is contained in:
parent
22c220c432
commit
665f9d9d34
2 changed files with 33 additions and 7 deletions
|
@ -15,22 +15,22 @@ public class ModerationTests
|
|||
public async void DismissExpiredCases_ShouldDismissExpiredCase()
|
||||
{
|
||||
await using DatabaseContext database = await MockHelper.GetTestDatabase();
|
||||
|
||||
|
||||
ModerationCaseEntity @case = new()
|
||||
{
|
||||
CaseId = 1,
|
||||
ExpiresAt = DateTime.UnixEpoch,
|
||||
CreatorUsername = "unitTestUser",
|
||||
};
|
||||
|
||||
|
||||
database.Cases.Add(@case);
|
||||
|
||||
|
||||
await database.SaveChangesAsync();
|
||||
|
||||
|
||||
DismissExpiredCasesTask task = new();
|
||||
await task.Run(database);
|
||||
|
||||
Assert.Null(await database.Cases.FirstOrDefaultAsync(c => c.CaseId == 1 && c.DismissedAt == null));
|
||||
Assert.NotNull(await database.Cases.FirstOrDefaultAsync(c => c.CaseId == 1 && c.DismissedAt != null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -54,4 +54,29 @@ public class ModerationTests
|
|||
|
||||
Assert.NotNull(await database.Cases.FirstOrDefaultAsync(c => c.CaseId == 2 && c.DismissedAt == null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DismissExpiredCases_ShouldNotDismissAlreadyDismissedCase()
|
||||
{
|
||||
await using DatabaseContext database = await MockHelper.GetTestDatabase();
|
||||
|
||||
ModerationCaseEntity @case = new()
|
||||
{
|
||||
CaseId = 3,
|
||||
ExpiresAt = DateTime.UnixEpoch,
|
||||
DismissedAt = DateTime.UnixEpoch,
|
||||
CreatorUsername = "unitTestUser",
|
||||
};
|
||||
|
||||
database.Cases.Add(@case);
|
||||
|
||||
await database.SaveChangesAsync();
|
||||
|
||||
DismissExpiredCasesTask task = new();
|
||||
await task.Run(database);
|
||||
|
||||
// check that the case was not dismissed again by comparing original time to new time
|
||||
Assert.NotNull(
|
||||
await database.Cases.FirstOrDefaultAsync(c => c.CaseId == 3 && c.DismissedAt == DateTime.UnixEpoch));
|
||||
}
|
||||
}
|
|
@ -19,8 +19,9 @@ public class DismissExpiredCasesTask : IRepeatingTask
|
|||
|
||||
public async Task Run(DatabaseContext database)
|
||||
{
|
||||
List<ModerationCaseEntity> expiredCases =
|
||||
await database.Cases.Where(c => c.ExpiresAt != null && c.ExpiresAt < DateTime.UtcNow).ToListAsync();
|
||||
List<ModerationCaseEntity> expiredCases = await database.Cases
|
||||
.Where(c => c.DismissedAt == null && c.ExpiresAt != null && c.ExpiresAt < DateTime.UtcNow)
|
||||
.ToListAsync();
|
||||
|
||||
if (expiredCases.Count == 0)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue