Fix account and backup admin settings flows

This commit is contained in:
2026-03-28 15:30:07 +01:00
parent 5f14490ead
commit 4103f84f85
12 changed files with 446 additions and 37 deletions
@@ -0,0 +1,44 @@
using JobTrackerApi.Controllers;
using JobTrackerApi.Data;
using JobTrackerApi.Models;
using JobTrackerApi.Services;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;
namespace JobTrackerApi.Tests;
public sealed class BackupControllerTests
{
[Fact]
public async Task Encrypted_returns_file_payload_on_non_windows_platforms_too()
{
await using var db = CreateDb();
db.Companies.Add(new Company { Name = "Acme", OwnerUserId = "user-1" });
db.JobApplications.Add(new JobApplication { JobTitle = "Backend Developer", OwnerUserId = "user-1" });
await db.SaveChangesAsync();
var provider = DataProtectionProvider.Create(new DirectoryInfo(Path.Combine(Path.GetTempPath(), $"jobtracker-tests-{Guid.NewGuid():N}")));
var controller = new BackupController(db, new NullLogger<BackupController>(), provider);
var result = await controller.Encrypted(CancellationToken.None);
var file = Assert.IsType<FileContentResult>(result);
Assert.Equal("application/octet-stream", file.ContentType);
Assert.EndsWith(".jtbackup", file.FileDownloadName);
Assert.NotEmpty(file.FileContents);
}
private static JobTrackerContext CreateDb()
{
var options = new DbContextOptionsBuilder<JobTrackerContext>()
.UseInMemoryDatabase(Guid.NewGuid().ToString())
.Options;
var currentUser = new Mock<ICurrentUserService>();
currentUser.SetupGet(x => x.UserId).Returns("user-1");
return new JobTrackerContext(options, currentUser.Object);
}
}