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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user