using MongoDB.Entities; using PrivaPub.Models.Federation; using PrivaPub.Models.Post; using PrivaPub.Models.Social; using PrivaPub.Tests.Support; using System.Text.Json.Nodes; using static PrivaPub.Tests.Support.FederatedSeeds; namespace PrivaPub.Tests.Federation { // A deleted remote post is never brought back by its own Create, however late it comes; an id its server gives a new // post afterwards (Gancio numbers an event after the last one it keeps) is that new post [Trait("Category", "Integration")] public sealed class ReusedIdTests : IAsyncLifetime { Harness _harness; public async ValueTask InitializeAsync() { Assert.SkipUnless(MongoFixture.Enabled, MongoFixture.Skip); _harness = await Harness.Start(); } public async ValueTask DisposeAsync() { if (_harness != default) await _harness.DisposeAsync(); } [Fact] public async Task A_deleted_posts_create_stays_dropped_and_a_new_post_under_its_id_is_kept() { var token = TestContext.Current.CancellationToken; var (_, alice) = await _harness.Persona("alice"); var carol = new RemoteActor(_harness.Peer, "carol"); await Follows(alice.Id, carol); var first = PublicNote(carol, "
the first event
"); first["published"] = DateTime.UtcNow.AddMinutes(-10).ToString("O"); await _harness.Deliver(carol, "/human-centipede", Create(carol, first)); await _harness.Deliver(carol, "/human-centipede", new JsonObject { ["id"] = NewId(carol, "deletes"), ["type"] = "Delete", ["actor"] = carol.Id, ["object"] = new JsonObject { ["id"] = IdOf(first), ["type"] = "Tombstone" } }); Assert.True(await DB.Default.Finda new event, numbered as the first
"); second["id"] = IdOf(first); second["published"] = DateTime.UtcNow.ToString("O"); await _harness.Deliver(carol, "/human-centipede", Create(carol, second)); var kept = await DB.Default.Find