mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-28 16:08:38 +00:00
Implement dismiss expired cases repeating task (#891)
* Implement dismiss expired cases repeating task I have the time temporarily set to every 1 minute for testing purposes * Rename cases list variable to be a bit more self documenting * Switch repeat interval to four hours * Make no operation log a debug * Add case expiration unit tests I called the file ModerationTests in case we want to add more general moderation unit tests in the future * I blame zaprit * Fix tests * Tests nitpicks and use UtcNow instead of Now * Use Assert.Null and Assert.NotNull for better readability
This commit is contained in:
parent
d0686b5f5f
commit
22c220c432
2 changed files with 96 additions and 0 deletions
57
ProjectLighthouse.Tests/Unit/ModerationTests.cs
Normal file
57
ProjectLighthouse.Tests/Unit/ModerationTests.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
using System;
|
||||
using LBPUnion.ProjectLighthouse.Administration.Maintenance.RepeatingTasks;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Tests.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Moderation;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Xunit;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Tests.Unit;
|
||||
|
||||
[Trait("Category", "Unit")]
|
||||
public class ModerationTests
|
||||
{
|
||||
[Fact]
|
||||
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));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DismissExpiredCases_ShouldNotDismissActiveCase()
|
||||
{
|
||||
await using DatabaseContext database = await MockHelper.GetTestDatabase();
|
||||
|
||||
ModerationCaseEntity @case = new()
|
||||
{
|
||||
CaseId = 2,
|
||||
ExpiresAt = DateTime.UtcNow.AddHours(1),
|
||||
CreatorUsername = "unitTestUser",
|
||||
};
|
||||
|
||||
database.Cases.Add(@case);
|
||||
|
||||
await database.SaveChangesAsync();
|
||||
|
||||
DismissExpiredCasesTask task = new();
|
||||
await task.Run(database);
|
||||
|
||||
Assert.NotNull(await database.Cases.FirstOrDefaultAsync(c => c.CaseId == 2 && c.DismissedAt == null));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue