backend: Expand backend integration test coverage

This commit is contained in:
GonnaHetzMe committed 2026-12-02 23:56:26 +01:00
1 parent ce04c8beb3
commit 32bc5a4691
8 files changed
+500 -19

No files matched your search

@@ -1,12 +1,10 @@
using System.Net;
using System.Net.Http.Json;
using Helpdesk.Application.Auth;
using Helpdesk.Application.Catalogs;
using Helpdesk.Application.Common;
using Helpdesk.Application.Issues;
using Helpdesk.Application.Notifications;
using Helpdesk.Application.Statistics;
using Helpdesk.Application.Users;
using static Helpdesk.IntegrationTests.BackendFixture;
namespace Helpdesk.IntegrationTests;
@@ -20,9 +18,9 @@ public sealed class IssueWorkflowTests(BackendFixture fixture) : IClassFixture<B
using var admin = fixture.CreateClient((await LoginAsync(anonymous, AdminEmail)).AccessToken);
var author = await fixture.RegisterAsync(anonymous);
using var reporter = fixture.CreateClient((await LoginAsync(anonymous, author.Email)).AccessToken);
var management = await CreateStaffAsync(anonymous, admin, "MANAGEMENT");
var firstAssignee = await CreateStaffAsync(anonymous, admin, "FACILITY_MANAGER");
var secondAssignee = await CreateStaffAsync(anonymous, admin, "FACILITY_MANAGER");
var management = await fixture.RegisterStaffAsync(anonymous, admin, "MANAGEMENT");
var firstAssignee = await fixture.RegisterStaffAsync(anonymous, admin, "FACILITY_MANAGER");
var secondAssignee = await fixture.RegisterStaffAsync(anonymous, admin, "FACILITY_MANAGER");
using var manager = fixture.CreateClient(management.AccessToken);
using var firstSolver = fixture.CreateClient(firstAssignee.AccessToken);
using var secondSolver = fixture.CreateClient(secondAssignee.AccessToken);
@@ -35,6 +33,10 @@ public sealed class IssueWorkflowTests(BackendFixture fixture) : IClassFixture<B
Assert.Equal("RECEIVED", issue.Status);
await ExpectAsync(anonymous.GetAsync(path, Cancellation), HttpStatusCode.Unauthorized);
issue = await ReadAsync<IssueDetail>(reporter.PutAsJsonAsync(path,
new EditIssueRequest(issue.Title, "Projektor nereaguje ani po restartu.", issue.CategoryId,
issue.BuildingId, issue.LocationDetail, issue.RowVersion), Cancellation));
Assert.Equal("Projektor nereaguje ani po restartu.", issue.Description);
var assign = new AssignIssueRequest(firstAssignee.User.Id, null, issue.RowVersion);
await ExpectAsync(reporter.PostAsJsonAsync(path + "/assign", assign, Cancellation), HttpStatusCode.Forbidden);
issue = await PostIssueAsync(manager, path + "/assign", assign);
@@ -63,6 +65,10 @@ public sealed class IssueWorkflowTests(BackendFixture fixture) : IClassFixture<B
issue = await ReadAsync<IssueDetail>(firstSolver.GetAsync(path, Cancellation));
issue = await PostIssueAsync(firstSolver, path + "/submit-for-verification", new VerifyIssueRequest(issue.RowVersion, null));
Assert.Equal("PENDING_VERIFICATION", issue.Status);
issue = await PostIssueAsync(reporter, path + "/reopen", new IssueReasonRequest(issue.RowVersion, "Porucha se vrátila."));
Assert.Equal("IN_PROGRESS", issue.Status);
Assert.Contains(await InboxAsync(firstSolver, issue.Id), notification => notification.Type == "ISSUE_REOPENED");
issue = await PostIssueAsync(firstSolver, path + "/submit-for-verification", new VerifyIssueRequest(issue.RowVersion, "Ověřeno."));
issue = await PostIssueAsync(reporter, path + "/confirm", new IssueVersionRequest(issue.RowVersion));
Assert.Equal("RESOLVED", issue.Status);
var events = await ReadAsync<IssueEventDto[]>(reporter.GetAsync(path + "/events", Cancellation));
@@ -72,14 +78,9 @@ public sealed class IssueWorkflowTests(BackendFixture fixture) : IClassFixture<B
var openIssue = await PostIssueAsync(reporter, "/api/v1/issues",
request with { Title = "Porucha osvětlení" }, HttpStatusCode.Created);
await VerifyReadsAsync(reporter, manager, issue, openIssue);
}
private async Task<AuthResponse> CreateStaffAsync(HttpClient anonymous, HttpClient admin, string role)
{
var user = await fixture.RegisterAsync(anonymous);
await ExpectAsync(admin.PutAsJsonAsync($"/api/v1/admin/users/{user.Id}/role",
new ChangeRoleRequest(role), Cancellation), HttpStatusCode.NoContent);
return await LoginAsync(anonymous, user.Email);
var rejected = await PostIssueAsync(manager, $"/api/v1/issues/{openIssue.Id}/reject",
new IssueReasonRequest(openIssue.RowVersion, "Duplicitní hlášení."));
Assert.Equal("REJECTED", rejected.Status);
}
private static async Task VerifyReadsAsync(HttpClient reporter, HttpClient manager, IssueDetail resolved, IssueDetail open)
@@ -105,6 +106,18 @@ public sealed class IssueWorkflowTests(BackendFixture fixture) : IClassFixture<B
Assert.Equal(1, statistics.IssuesByStatus["RECEIVED"]);
Assert.NotNull(statistics.AverageHoursToAssignment);
Assert.NotNull(statistics.AverageHoursToClosure);
var byCategory = Assert.Single(await ReadAsync<IssueCategoryStatistics[]>(
manager.GetAsync("/api/v1/statistics/issues/by-category" + period, Cancellation)));
Assert.Equal((resolved.CategoryId, 2), (byCategory.CategoryId, byCategory.IssueCount));
Assert.NotNull(byCategory.AverageHoursToResolution);
var byBuilding = Assert.Single(await ReadAsync<IssueBuildingStatistics[]>(
manager.GetAsync("/api/v1/statistics/issues/by-building" + period, Cancellation)));
Assert.Equal((resolved.BuildingId, 2), (byBuilding.BuildingId, byBuilding.IssueCount));
var byAssignee = Assert.Single(await ReadAsync<IssueAssigneeStatistics[]>(
manager.GetAsync("/api/v1/statistics/issues/by-assignee" + period, Cancellation)));
Assert.Equal((resolved.AssigneeId, 1, 0), ((int?)byAssignee.AssigneeId, byAssignee.ResolvedIssues, byAssignee.OpenIssues));
var available = await ReadAsync<AssignableUserDto[]>(manager.GetAsync("/api/v1/users/assignable", Cancellation));
Assert.Contains(available, user => user.Id == resolved.AssigneeId && user.OpenIssues == 0);
var trend = await ReadAsync<IssueTrendPoint[]>(manager.GetAsync("/api/v1/statistics/issues/trend" + period, Cancellation));
Assert.Equal(2, trend.Sum(point => point.CreatedIssues));
Assert.Equal(1, trend.Sum(point => point.ClosedIssues));