Initial import
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using FluentAssertions;
|
||||
using MinAttest.Contracts.Attests;
|
||||
using MinAttest.Contracts.Employers;
|
||||
using MinAttest.Contracts.Persons;
|
||||
using MinAttest.Tests.Integration.Server;
|
||||
using Xunit;
|
||||
|
||||
namespace MinAttest.Tests.Integration.Api;
|
||||
|
||||
[Collection("IntegrationCollection")]
|
||||
public class EmployersApiTests : IClassFixture<ApiWebAppFactory>
|
||||
{
|
||||
private readonly HttpClient _client;
|
||||
public EmployersApiTests(ApiWebAppFactory factory) => _client = factory.CreateClient();
|
||||
|
||||
[Fact]
|
||||
public async Task Employer_issue_and_list_and_download_via_http()
|
||||
{
|
||||
// Upsert employer
|
||||
var employerUpsert = new EmployerUpsertRequest("321654987", "ApiCo AS");
|
||||
var employerResp = await _client.PostAsJsonAsync("/api/v1/employers", employerUpsert);
|
||||
employerResp.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
var employer = await employerResp.Content.ReadFromJsonAsync<EmployerResponse>();
|
||||
employer.Should().NotBeNull();
|
||||
|
||||
// Upsert person
|
||||
var personResp = await _client.PostAsJsonAsync("/api/v1/persons", new PersonUpsertRequest("hash-api-emp-1", "emp-person@example.com", null));
|
||||
personResp.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
var person = await personResp.Content.ReadFromJsonAsync<PersonResponse>();
|
||||
person.Should().NotBeNull();
|
||||
|
||||
// Issue attest for person
|
||||
var issueReq = new EmployerAttestUploadRequest(
|
||||
PersonId: person!.Id,
|
||||
Title: "ApiEmployerAttest",
|
||||
From: new DateOnly(2024,1,1),
|
||||
To: new DateOnly(2024,6,1),
|
||||
Summary: null,
|
||||
BlobPath: string.Empty,
|
||||
BlobHash: null,
|
||||
ContentBase64: Convert.ToBase64String(new byte[]{7,8,9}),
|
||||
ContentType: "application/octet-stream");
|
||||
|
||||
var issueResp = await _client.PostAsJsonAsync($"/api/v1/employers/{employer!.Id}/attests", issueReq);
|
||||
issueResp.StatusCode.Should().Be(HttpStatusCode.Created);
|
||||
var created = await issueResp.Content.ReadFromJsonAsync<Dictionary<string, object>>();
|
||||
created.Should().NotBeNull();
|
||||
var createdId = Guid.Parse(created!["attestId"].ToString()!);
|
||||
|
||||
// List employer attests
|
||||
var listResp = await _client.GetAsync($"/api/v1/employers/{employer.Id}/attests");
|
||||
listResp.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
|
||||
// Download
|
||||
var dlResp = await _client.GetAsync($"/api/v1/employers/{employer.Id}/attests/{createdId}/download");
|
||||
dlResp.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
(await dlResp.Content.ReadAsByteArrayAsync()).Length.Should().BeGreaterThan(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using FluentAssertions;
|
||||
using MinAttest.Contracts.Attests;
|
||||
using MinAttest.Contracts.Persons;
|
||||
using MinAttest.Tests.Integration.Server;
|
||||
using Xunit;
|
||||
|
||||
namespace MinAttest.Tests.Integration.Api;
|
||||
|
||||
[Collection("IntegrationCollection")]
|
||||
public class PersonsApiTests : IClassFixture<ApiWebAppFactory>
|
||||
{
|
||||
private readonly HttpClient _client;
|
||||
public PersonsApiTests(ApiWebAppFactory factory) => _client = factory.CreateClient();
|
||||
|
||||
[Fact]
|
||||
public async Task Upsert_person_and_upload_and_list()
|
||||
{
|
||||
var upsertResp = await _client.PostAsJsonAsync("/api/v1/persons", new PersonUpsertRequest("hash-api-1", "api@example.com", null));
|
||||
upsertResp.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
var person = await upsertResp.Content.ReadFromJsonAsync<PersonResponse>();
|
||||
person.Should().NotBeNull();
|
||||
|
||||
var uploadReq = new PersonAttestUploadRequest(
|
||||
Title: "ApiAttest",
|
||||
From: new DateOnly(2024,1,1),
|
||||
To: new DateOnly(2024,6,1),
|
||||
Summary: "",
|
||||
BlobPath: "",
|
||||
BlobHash: null,
|
||||
ContentBase64: Convert.ToBase64String(new byte[]{1,2,3}),
|
||||
ContentType: "application/octet-stream");
|
||||
|
||||
var uploadResp = await _client.PostAsJsonAsync($"/api/v1/persons/{person!.Id}/attests", uploadReq);
|
||||
uploadResp.StatusCode.Should().Be(HttpStatusCode.Created);
|
||||
|
||||
var listResp = await _client.GetAsync($"/api/v1/persons/{person.Id}/attests");
|
||||
listResp.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
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<ApiWebAppFactory>
|
||||
{
|
||||
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<PersonResponse>();
|
||||
|
||||
// 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<Dictionary<string, object>>();
|
||||
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<ShareLinkResponse>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user