// // SharedInboxTests.swift // PocheTests // // Author: Simon-Pierre Boucher // Contact: contact@spboucher.ai // import Foundation import SwiftData import Testing @testable import Poche @MainActor struct SharedInboxTests { private func temporaryInboxURL() -> URL { FileManager.default.temporaryDirectory .appendingPathComponent("inbox-\(UUID().uuidString).json") } @Test func appendThenDrainRoundTrips() { let url = temporaryInboxURL() defer { try? FileManager.default.removeItem(at: url) } SharedInbox.append(SharedInboxItem(title: "Lien", content: "https://exemple.fr", date: .now), at: url) SharedInbox.append(SharedInboxItem(title: "Texte", content: "Un extrait partagé", date: .now), at: url) let drained = SharedInbox.drain(at: url) #expect(drained.count == 2) #expect(drained.first?.title == "Lien") // Draining empties the inbox. #expect(SharedInbox.drain(at: url).isEmpty) } @Test func importCreatesNotesFromInbox() throws { let url = temporaryInboxURL() defer { try? FileManager.default.removeItem(at: url) } SharedInbox.append(SharedInboxItem(title: "Article", content: "À lire plus tard", date: .now), at: url) let container = try ModelContainer( for: Note.self, TaskItem.self, ConversationRecord.self, TurnRecord.self, configurations: ModelConfiguration(isStoredInMemoryOnly: true) ) let store = PocheStore(container: container) store.importSharedInbox(from: url) let corpus = store.corpus() #expect(corpus.contains { $0.kind == "note" && $0.title == "Article" }) } @Test func missingInboxIsHarmless() throws { let container = try ModelContainer( for: Note.self, TaskItem.self, ConversationRecord.self, TurnRecord.self, configurations: ModelConfiguration(isStoredInMemoryOnly: true) ) let store = PocheStore(container: container) store.importSharedInbox(from: nil) store.importSharedInbox(from: temporaryInboxURL()) #expect(store.corpus().isEmpty) } }