Inkspring / app · inkspring.ai / native-mac / Tests / InkspringTests / LegacyWritingTests.swift
| 1 | import Foundation |
| 2 | import Testing |
| 3 | @testable import Inkspring |
| 4 | |
| 5 | @Test @MainActor func retiredWritingStaysInBackupsAndFormerPairsRequireANewSchedule() throws { |
| 6 | let directory = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString) |
| 7 | defer { try? FileManager.default.removeItem(at: directory) } |
| 8 | let workspace = Workspace(directory: directory) |
| 9 | let database = try #require(workspace.database) |
| 10 | var archived = WorkspaceRecord.new("article", projectID: workspace.projectID) |
| 11 | archived["platform"] = "linkedin" |
| 12 | archived["title"] = "Saved writing" |
| 13 | archived["body"] = "# A heading\n\nKeep the original text." |
| 14 | _ = try database.put(archived) |
| 15 | |
| 16 | var post = WorkspaceRecord.new("draft", projectID: workspace.projectID) |
| 17 | post["platform"] = "linkedin" |
| 18 | post["content"] = "This text is ready for a video post." |
| 19 | post["linkedinArticleID"] = archived.id |
| 20 | post.fields["schedule"] = ["status": "queued", "slotAt": "2026-11-20T17:00:00Z"] |
| 21 | _ = try database.put(post) |
| 22 | var xArticle = WorkspaceRecord.new("article", projectID: workspace.projectID) |
| 23 | xArticle["title"] = "Write for X" |
| 24 | xArticle = try workspace.save(xArticle) |
| 25 | |
| 26 | let active = try #require(workspace.drafts.first { $0.id == post.id }) |
| 27 | #expect(active.body == post.body) |
| 28 | #expect(active["linkedinArticleID"].isEmpty) |
| 29 | #expect(active.scheduleStatus == "ready") |
| 30 | #expect(active.schedule["slotAt"] as? String == "") |
| 31 | #expect(!workspace.records.contains { $0.id == archived.id }) |
| 32 | #expect(!workspace.trashedRecords.contains { $0.id == archived.id }) |
| 33 | let snapshot = workspace.makeCompanionLibrary(workspaceID: UUID()) |
| 34 | #expect(snapshot.supportsLinkedInArticles == true) |
| 35 | #expect(snapshot.articles?.map(\.id) == [xArticle.id]) |
| 36 | let backup = try database.snapshot() |
| 37 | #expect(backup.records.first { $0.id == archived.id }?.body == archived.body) |
| 38 | #expect(throws: WorkspaceError.self) { try workspace.save(archived) } |
| 39 | } |