fix: refresh uploads and remember login

This commit is contained in:
2026-08-13 22:25:00 +08:00
parent e0bd001541
commit fdab9978bf
17 changed files with 424 additions and 19 deletions
@@ -0,0 +1,38 @@
using LiveRecorder.Application.Common;
using LiveRecorder.Application.Models.Auth;
using LiveRecorder.Application.Services;
using LiveRecorder.Domain.Entities;
using LiveRecorder.Infrastructure.Persistence;
using LiveRecorder.Infrastructure.Persistence.Repositories;
using Microsoft.EntityFrameworkCore;
namespace LiveRecorder.Tests;
public sealed class AuthServiceTests
{
[Theory]
[InlineData(false, 12)]
[InlineData(true, 720)]
public async Task Login_UsesExpectedSessionLifetime(bool rememberMe, int expectedHours)
{
var options = new DbContextOptionsBuilder<LiveRecorderDbContext>()
.UseInMemoryDatabase($"auth-{Guid.NewGuid():N}")
.Options;
await using var context = new LiveRecorderDbContext(options);
var user = new UserAccount("admin", "Admin", PasswordHasher.Hash("secret123"), DateTimeOffset.UtcNow);
context.UserAccounts.Add(user);
await context.SaveChangesAsync();
var service = new AuthService(new UserAccountRepository(context), new UserSessionRepository(context), context);
var before = DateTimeOffset.UtcNow;
var response = await service.LoginAsync(new LoginRequest
{
Username = "admin",
Password = "secret123",
RememberMe = rememberMe
});
var after = DateTimeOffset.UtcNow;
Assert.InRange(response.ExpiresAt, before.AddHours(expectedHours), after.AddHours(expectedHours));
}
}
@@ -434,6 +434,28 @@ public sealed class OpenListUploadTests
Assert.Equal(1, await fixture.Context.RecordUploadJobs.CountAsync());
}
[Fact]
public async Task Queue_RefreshesQueuedJobWhenConsolidationChangesResultPath()
{
await using var fixture = await QueueFixture.CreateAsync();
await fixture.Queue.EnqueueAsync(fixture.RecordTaskId);
var originalJob = await fixture.Context.RecordUploadJobs.AsNoTracking().SingleAsync();
var result = await fixture.Context.RecordResults.SingleAsync();
var mergedPath = Path.Combine(Path.GetDirectoryName(result.FilePath)!, "segment-merged.mp4");
await File.WriteAllBytesAsync(mergedPath, Encoding.UTF8.GetBytes("merged-video-content"));
result.Update(mergedPath, new FileInfo(mergedPath).Length, 60, null, 0, RecordTaskStatus.Completed, null);
await fixture.Context.SaveChangesAsync();
Assert.True(await fixture.Queue.ProcessNextAsync());
fixture.Context.ChangeTracker.Clear();
var refreshedJob = await fixture.Context.RecordUploadJobs.SingleAsync();
Assert.Equal("/source/Douyin/2026/08/01/主播/segment-merged.mp4", refreshedJob.SourceVideoPath);
Assert.Equal("/destination/Douyin/2026/08/01/主播/segment-merged.mp4", refreshedJob.TargetVideoPath);
Assert.Equal(RecordArtifactUploadStatus.Queued, refreshedJob.Status);
Assert.NotEqual(originalJob.SourceVideoPath, refreshedJob.SourceVideoPath);
}
[Fact]
public async Task Queue_RenamesSameNameConflictWithoutOverwriting()
{
@@ -906,5 +928,15 @@ public sealed class OpenListUploadTests
Operations.Add($"move:{sourcePath}->{targetDirectory}");
return Task.CompletedTask;
}
public Task DeleteFileAsync(
OpenListConnectionRequest connection,
string path,
CancellationToken cancellationToken = default)
{
Operations.Add($"delete:{path}");
Objects.Remove(path);
return Task.CompletedTask;
}
}
}