backend: Add integration tests
This commit is contained in:
1 parent
fd37986f5e
commit
def23d306e
9 files changed
+526
No files matched your search
@@ -0,0 +1,59 @@
|
||||
using Helpdesk.Api.Controllers;
|
||||
using Helpdesk.Infrastructure.Persistence;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using MySqlConnector;
|
||||
using static Helpdesk.IntegrationTests.BackendFixture;
|
||||
|
||||
namespace Helpdesk.IntegrationTests;
|
||||
|
||||
public sealed class DatabaseTests(BackendFixture fixture) : IClassFixture<BackendFixture>
|
||||
{
|
||||
[Fact]
|
||||
public async Task MigratorAppliesEveryScriptAndEfCanReadTheSchema()
|
||||
{
|
||||
using var client = fixture.CreateClient();
|
||||
await using var scope = fixture.Services.CreateAsyncScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<HelpdeskDbContext>();
|
||||
var expected = Directory.EnumerateFiles(MigrationsPath, "V*__*.sql")
|
||||
.Select(Path.GetFileName).Order(StringComparer.Ordinal).ToArray();
|
||||
var applied = await db.Database
|
||||
.SqlQueryRaw<string>("SELECT scriptname AS Value FROM schema_version ORDER BY schemaversionid")
|
||||
.ToListAsync(Cancellation);
|
||||
Assert.Equal(expected, applied);
|
||||
var health = await ReadAsync<HealthResponse>(client.GetAsync("/health", Cancellation));
|
||||
Assert.Equal(new HealthResponse("Healthy", expected[^1]), health);
|
||||
|
||||
await db.Users.AsNoTracking().ToListAsync(Cancellation);
|
||||
await db.AuthTokens.AsNoTracking().ToListAsync(Cancellation);
|
||||
await db.Buildings.AsNoTracking().ToListAsync(Cancellation);
|
||||
await db.IssueCategories.AsNoTracking().ToListAsync(Cancellation);
|
||||
await db.ProposalCategories.AsNoTracking().ToListAsync(Cancellation);
|
||||
await db.Issues.AsNoTracking().ToListAsync(Cancellation);
|
||||
await db.IssueEvents.AsNoTracking().ToListAsync(Cancellation);
|
||||
await db.IssueTimings.ToListAsync(Cancellation);
|
||||
await db.Attachments.AsNoTracking().ToListAsync(Cancellation);
|
||||
await db.Proposals.AsNoTracking().ToListAsync(Cancellation);
|
||||
await db.ProposalEvents.AsNoTracking().ToListAsync(Cancellation);
|
||||
await db.ProposalVotes.AsNoTracking().ToListAsync(Cancellation);
|
||||
await db.ProposalScores.ToListAsync(Cancellation);
|
||||
await db.Notifications.AsNoTracking().ToListAsync(Cancellation);
|
||||
await db.NotificationDeliveries.AsNoTracking().ToListAsync(Cancellation);
|
||||
await db.PushDevices.AsNoTracking().ToListAsync(Cancellation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DatabaseRejectsAnAssignedIssueWithoutAnAssignee()
|
||||
{
|
||||
await using var scope = fixture.Services.CreateAsyncScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<HelpdeskDbContext>();
|
||||
var reporterId = await db.Users.Select(user => user.Id).SingleAsync(Cancellation);
|
||||
var categoryId = await db.IssueCategories.MinAsync(category => category.Id, Cancellation);
|
||||
|
||||
var error = await Assert.ThrowsAsync<MySqlException>(() => db.Database.ExecuteSqlInterpolatedAsync($"""
|
||||
INSERT INTO issue (title, description, category_id, reporter_id, status)
|
||||
VALUES ('Test', 'Test', {categoryId}, {reporterId}, 'ASSIGNED')
|
||||
""", Cancellation));
|
||||
Assert.Contains("ck_issue_assignee", error.Message);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user