feat(email): include drafts in user exports
CI and Deploy / test (pull_request) Successful in 4m14s
CI and Deploy / deploy (pull_request) Has been skipped

Export readable private draft content only through existing owner-filtered encrypted and daily export boundaries, with cross-tenant regression coverage.
This commit is contained in:
cesnimda
2026-08-10 10:00:34 +02:00
parent 10740fd8c3
commit 2fa4e38ba9
5 changed files with 98 additions and 1 deletions
+34 -1
View File
@@ -36,7 +36,8 @@ public sealed class BackupControllerTests
await using var db = CreateDb();
db.Companies.Add(new Company { Name = "Acme", OwnerUserId = "user-1" });
var job = new JobApplication { JobTitle = "Backend Developer", OwnerUserId = "user-1" };
db.JobApplications.Add(job);
var otherJob = new JobApplication { JobTitle = "Other tenant role", OwnerUserId = "user-2" };
db.JobApplications.AddRange(job, otherJob);
await db.SaveChangesAsync();
db.EmailSendAttempts.Add(new EmailSendAttempt
{
@@ -51,6 +52,32 @@ public sealed class BackupControllerTests
CreatedAtUtc = DateTime.UtcNow,
CompletedAtUtc = DateTime.UtcNow,
});
db.EmailDrafts.Add(new EmailDraft
{
Id = Guid.NewGuid(),
OwnerUserId = "user-1",
JobApplicationId = job.Id,
Provider = "gmail",
To = "recipient@example.test",
Subject = "Synthetic export subject",
BodyText = "Synthetic readable draft body.",
ThreadId = "synthetic-thread",
Revision = 3,
CreatedAtUtc = DateTime.UtcNow.AddMinutes(-5),
UpdatedAtUtc = DateTime.UtcNow,
});
db.EmailDrafts.Add(new EmailDraft
{
Id = Guid.NewGuid(),
OwnerUserId = "user-2",
JobApplicationId = otherJob.Id,
Provider = "microsoft",
To = "other@example.test",
Subject = "Other tenant subject",
BodyText = "Other tenant private body.",
CreatedAtUtc = DateTime.UtcNow,
UpdatedAtUtc = DateTime.UtcNow,
});
await db.SaveChangesAsync();
var provider = DataProtectionProvider.Create(new DirectoryInfo(Path.Combine(Path.GetTempPath(), $"jobtracker-tests-{Guid.NewGuid():N}")));
@@ -70,6 +97,12 @@ public sealed class BackupControllerTests
Assert.Equal("gmail", attempt.GetProperty("Provider").GetString());
Assert.Equal("sent", attempt.GetProperty("Status").GetString());
Assert.False(attempt.TryGetProperty("PayloadHash", out _));
var draft = Assert.Single(document.RootElement.GetProperty("Data").GetProperty("EmailDrafts").EnumerateArray());
Assert.Equal("recipient@example.test", draft.GetProperty("To").GetString());
Assert.Equal("Synthetic export subject", draft.GetProperty("Subject").GetString());
Assert.Equal("Synthetic readable draft body.", draft.GetProperty("BodyText").GetString());
Assert.Equal("synthetic-thread", draft.GetProperty("ThreadId").GetString());
Assert.Equal(3, draft.GetProperty("Revision").GetInt64());
}
private static JobTrackerContext CreateDb()