mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-06 21:31:27 +00:00
* 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
57 lines
No EOL
1.7 KiB
C#
57 lines
No EOL
1.7 KiB
C#
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));
|
|
}
|
|
} |