using FluentAssertions; using MediatR; using Microsoft.Extensions.DependencyInjection; using MinAttest.Application.Features.Attests.Commands; using MinAttest.Application.Features.ShareLinks.Commands; using MinAttest.Application.Features.ShareLinks.Queries; using MinAttest.Contracts.Attests; using MinAttest.Contracts.ShareLinks; using Xunit; namespace MinAttest.Tests.Integration; [Collection("IntegrationCollection")] public class ShareLinksIntegrationTests { private readonly IntegrationTestFixture _fixture; public ShareLinksIntegrationTests(IntegrationTestFixture fixture) => _fixture = fixture; [Fact] public async Task Create_list_revoke_sharelink_for_attest() { var mediator = _fixture.Services.GetRequiredService(); // Ensure person var person = await mediator.Send(new MinAttest.Application.Features.Persons.Commands.UpsertPersonCommand("person-hash-123", "person@example.com", null)); // Create attest var attestId = await mediator.Send(new PersonUploadAttestCommand(person.Id, new PersonAttestUploadRequest( Title: "Test", From: new DateOnly(2023,1,1), To: new DateOnly(2023,12,31), Summary: null, BlobPath: string.Empty, BlobHash: null, ContentBase64: Convert.ToBase64String(new byte[]{1,2,3}), ContentType: "application/octet-stream" ))); attestId.Should().NotBeNull(); // Create sharelink var created = await mediator.Send(new CreateShareLinkCommand(attestId!.Value, new CreateShareLinkRequest(TimeSpan.FromDays(7), false), "https://localhost")); created.Should().NotBeNull(); // List var list = await mediator.Send(new ListShareLinksQuery(attestId.Value)); list.Should().Contain(sl => sl.ShareId == created!.ShareId); // Revoke var revoked = await mediator.Send(new RevokeShareLinkCommand(attestId.Value, created!.ShareId)); revoked.Should().BeTrue(); } }