The flag-media-questions CLI command only caught questions that existed in the DB when it ran once. Any question created, imported, or edited afterward could add media without ever being flagged for review, since nothing gated new writes going forward. CreateAsync, UpdateAsync, and UpsertManyByExternalIdAsync now all run new/updated questions through ApplyMediaReviewGate, which flags any question that has media and isn't already flagged.
50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
using QuestionsApi.Models;
|
|
using QuestionsApi.Services;
|
|
using Xunit;
|
|
|
|
namespace QuestionsApi.Tests;
|
|
|
|
public sealed class QuestionStoreTests
|
|
{
|
|
[Fact]
|
|
public void ApplyMediaReviewGate_FlagsUnflaggedQuestionWithMedia()
|
|
{
|
|
var question = new Question { Media = ["asset-1"] };
|
|
|
|
QuestionStore.ApplyMediaReviewGate(question);
|
|
|
|
Assert.NotNull(question.FlaggedForReviewUtc);
|
|
Assert.Equal("system", question.FlaggedByUserId);
|
|
Assert.False(string.IsNullOrWhiteSpace(question.FlagReason));
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyMediaReviewGate_LeavesMediaFreeQuestionsAlone()
|
|
{
|
|
var question = new Question { Media = [] };
|
|
|
|
QuestionStore.ApplyMediaReviewGate(question);
|
|
|
|
Assert.Null(question.FlaggedForReviewUtc);
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyMediaReviewGate_DoesNotOverwriteAnExistingFlag()
|
|
{
|
|
var flaggedAt = DateTime.UtcNow.AddDays(-1);
|
|
var question = new Question
|
|
{
|
|
Media = ["asset-1"],
|
|
FlaggedForReviewUtc = flaggedAt,
|
|
FlagReason = "Reported by student",
|
|
FlaggedByUserId = "user-42"
|
|
};
|
|
|
|
QuestionStore.ApplyMediaReviewGate(question);
|
|
|
|
Assert.Equal(flaggedAt, question.FlaggedForReviewUtc);
|
|
Assert.Equal("Reported by student", question.FlagReason);
|
|
Assert.Equal("user-42", question.FlaggedByUserId);
|
|
}
|
|
}
|