Files
minattest/backend/tests/MinAttest.Tests/Integration/ShareLinksIntegrationTests.cs
T
Stein Helge Riise ede31fbb7e Initial import
2025-11-17 08:32:46 +01:00

53 lines
2.0 KiB
C#

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<IMediator>();
// 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();
}
}