using System.Net; using System.Net.Http.Json; using FluentAssertions; using MinAttest.Contracts.Attests; using MinAttest.Contracts.Persons; using MinAttest.Contracts.ShareLinks; using MinAttest.Tests.Integration.Server; using Xunit; namespace MinAttest.Tests.Integration.Api; [Collection("IntegrationCollection")] public class ShareLinksApiTests : IClassFixture { private readonly HttpClient _client; public ShareLinksApiTests(ApiWebAppFactory factory) => _client = factory.CreateClient(); [Fact] public async Task Create_list_revoke_sharelink_via_http() { // Upsert person var personResp = await _client.PostAsJsonAsync("/api/v1/persons", new PersonUpsertRequest("hash-api-share-1", "share-person@example.com", null)); personResp.StatusCode.Should().Be(HttpStatusCode.OK); var person = await personResp.Content.ReadFromJsonAsync(); // Upload attest var upload = new PersonAttestUploadRequest( Title: "ShareAttest", From: new DateOnly(2024,1,1), To: new DateOnly(2024,6,1), Summary: null, BlobPath: string.Empty, BlobHash: null, ContentBase64: Convert.ToBase64String(new byte[]{1,2,3,4}), ContentType: "application/pdf"); var upResp = await _client.PostAsJsonAsync($"/api/v1/persons/{person!.Id}/attests", upload); upResp.StatusCode.Should().Be(HttpStatusCode.Created); var created = await upResp.Content.ReadFromJsonAsync>(); var attestId = Guid.Parse(created!["attestId"].ToString()!); // Create share link var createReq = new CreateShareLinkRequest(TimeSpan.FromDays(7), false); var slResp = await _client.PostAsJsonAsync($"/api/v1/attests/{attestId}/sharelinks", createReq); slResp.StatusCode.Should().Be(HttpStatusCode.OK); var link = await slResp.Content.ReadFromJsonAsync(); link.Should().NotBeNull(); // List var listResp = await _client.GetAsync($"/api/v1/attests/{attestId}/sharelinks"); listResp.StatusCode.Should().Be(HttpStatusCode.OK); // Revoke var delResp = await _client.DeleteAsync($"/api/v1/attests/{attestId}/sharelinks/{link!.ShareId}"); delResp.StatusCode.Should().Be(HttpStatusCode.NoContent); } }