System decks/notes are owned by a reserved sentinel user id, reusing all existing per-user store/index plumbing unchanged. Regular users see them under a separate "Official Decks" section, can study them with fully independent per-user FSRS progress (lazily materialized on first visit), but can never edit or archive them - enforced both in the client (no Edit/Archive controls) and server-side (ownership guard on every mutating endpoint). Includes a small idempotent seed command (`dotnet run -- seed-flashcards`) for testing, since there's no in-app authoring UI yet.
33 lines
1.0 KiB
C#
33 lines
1.0 KiB
C#
using QuestionsApi.Models;
|
|
using QuestionsApi.Services.Flashcards;
|
|
using Xunit;
|
|
|
|
namespace QuestionsApi.Tests;
|
|
|
|
public sealed class FlashcardOwnershipTests
|
|
{
|
|
[Theory]
|
|
[InlineData(false, false, true)]
|
|
[InlineData(false, true, false)]
|
|
[InlineData(true, false, true)]
|
|
[InlineData(true, true, true)]
|
|
public void CanMutate_MatchesTruthTable(bool isSuper, bool targetIsSystem, bool expected)
|
|
{
|
|
Assert.Equal(expected, FlashcardOwnershipGuard.CanMutate(isSuper, targetIsSystem));
|
|
}
|
|
|
|
[Fact]
|
|
public void FlashcardDeck_IsSystem_TrueOnlyForTheReservedOwner()
|
|
{
|
|
Assert.True(new FlashcardDeck { UserId = FlashcardOwners.System }.IsSystem);
|
|
Assert.False(new FlashcardDeck { UserId = "a-real-user-id" }.IsSystem);
|
|
}
|
|
|
|
[Fact]
|
|
public void FlashcardNote_IsSystem_TrueOnlyForTheReservedOwner()
|
|
{
|
|
Assert.True(new FlashcardNote { UserId = FlashcardOwners.System }.IsSystem);
|
|
Assert.False(new FlashcardNote { UserId = "a-real-user-id" }.IsSystem);
|
|
}
|
|
}
|