Alpha 3
This commit is contained in:
committed by
Dr. Michael Kübler
parent
8e95cc3acd
commit
c5e46946ac
@@ -4,6 +4,51 @@ import Testing
|
||||
|
||||
@MainActor
|
||||
struct MailArchiveTests {
|
||||
@Test func confirmedMessageChangesPreserveOtherMailAndBackup() throws {
|
||||
let root = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString)
|
||||
defer { try? FileManager.default.removeItem(at: root) }
|
||||
let archive = try MailArchive(root: root.appending(path: "Archive"))
|
||||
let account = MailAccount(name: "Fixture", email: "fixture@example.com", username: "fixture", host: "example.invalid")
|
||||
let inbox = MailFolder(accountID: account.id, path: "INBOX", name: "Posteingang")
|
||||
let trash = MailFolder(accountID: account.id, path: "Trash", name: "Papierkorb")
|
||||
try archive.saveConfiguration(ArchiveConfiguration(accounts: [account], folders: [account.id: [inbox, trash]], recipients: []))
|
||||
let raw = Data("Subject: Move\r\n\r\nBody".utf8)
|
||||
for uid in ["1", "2"] { try archive.store(raw: raw, folderID: inbox.id, validity: "10", uid: uid, flags: []) }
|
||||
let id = inbox.id + ":10:1"
|
||||
try archive.applyMessageChange(id: id, flags: ["\\Seen"], removed: false)
|
||||
#expect(try archive.message(id: id).isRead)
|
||||
try archive.applyMessageChange(id: id, destination: trash.id, assigned: .init(validity: "20", uid: "9"), flags: ["\\Seen"])
|
||||
#expect(try archive.messages(folderID: inbox.id).map(\.id) == [inbox.id + ":10:2"])
|
||||
#expect(try archive.message(id: trash.id + ":20:9").body == "Body")
|
||||
#expect(try archive.unreadCounts()[inbox.id] == 1)
|
||||
try archive.applyMessageChange(id: trash.id + ":20:9")
|
||||
#expect(try archive.messages(folderID: trash.id).isEmpty)
|
||||
let backup = root.appending(path: "Backup")
|
||||
try archive.exportSnapshot(to: backup)
|
||||
let restored = try MailArchive.restoreSnapshot(from: backup, to: root.appending(path: "Restored"))
|
||||
#expect(try restored.messages(folderID: trash.id).isEmpty)
|
||||
#expect(try restored.messages(folderID: inbox.id).count == 1)
|
||||
}
|
||||
|
||||
@Test func singleMessageServerUIDMapping() {
|
||||
#expect(IMAPClient.assignedUID(["M1 OK [COPYUID 123 5 17] Done"], sourceUID: 5) == .init(validity: "123", uid: "17"))
|
||||
#expect(IMAPClient.assignedUID(["* OK [COPYUID 123 5 17] Done"], sourceUID: 6) == nil)
|
||||
#expect(IMAPClient.assignedUID(["M2 OK [APPENDUID 123 18] Done"]) == .init(validity: "123", uid: "18"))
|
||||
#expect(IMAPClient.assignedUID(["M2 OK Done"]) == nil)
|
||||
#expect(IMAPClient.assignedUID(["M2 OK [APPENDUID 0 18] Done"]) == nil)
|
||||
#expect(IMAPClient.assignedUID(["M2 OK [COPYUID 123 5:6 17:18] Done"], sourceUID: 5) == nil)
|
||||
}
|
||||
|
||||
@Test func automaticReadDelayIsCancellable() async throws {
|
||||
try await AutoReadRequest(ids: ["mail"], immediately: true, seconds: 3600).wait()
|
||||
let delayed = Task { try await AutoReadRequest(ids: ["mail"], immediately: false, seconds: 3600).wait() }
|
||||
delayed.cancel()
|
||||
do {
|
||||
try await delayed.value
|
||||
Issue.record("Cancelled selection must not be marked as read")
|
||||
} catch is CancellationError { }
|
||||
}
|
||||
|
||||
@Test func diskPersistenceIncrementalReconciliationAndRestore() throws {
|
||||
let base = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString)
|
||||
defer { try? FileManager.default.removeItem(at: base) }
|
||||
|
||||
Reference in New Issue
Block a user