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
|
@ -30,7 +30,7 @@ public class ModerationTests
|
||||||
DismissExpiredCasesTask task = new();
|
DismissExpiredCasesTask task = new();
|
||||||
await task.Run(database);
|
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]
|
[Fact]
|
||||||
|
@ -54,4 +54,29 @@ public class ModerationTests
|
||||||
|
|
||||||
Assert.NotNull(await database.Cases.FirstOrDefaultAsync(c => c.CaseId == 2 && c.DismissedAt == null));
|
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)
|
public async Task Run(DatabaseContext database)
|
||||||
{
|
{
|
||||||
List<ModerationCaseEntity> expiredCases =
|
List<ModerationCaseEntity> expiredCases = await database.Cases
|
||||||
await database.Cases.Where(c => c.ExpiresAt != null && c.ExpiresAt < DateTime.UtcNow).ToListAsync();
|
.Where(c => c.DismissedAt == null && c.ExpiresAt != null && c.ExpiresAt < DateTime.UtcNow)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
if (expiredCases.Count == 0)
|
if (expiredCases.Count == 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue