diff --git a/Modules/Account/Tests/AccountTests/AccountManagerDuplicateEndpointTests.swift b/Modules/Account/Tests/AccountTests/AccountManagerDuplicateEndpointTests.swift index 8b3b76f9d..ddc23df60 100644 --- a/Modules/Account/Tests/AccountTests/AccountManagerDuplicateEndpointTests.swift +++ b/Modules/Account/Tests/AccountTests/AccountManagerDuplicateEndpointTests.swift @@ -6,40 +6,26 @@ // Copyright © 2026 Ranchero Software, LLC. All rights reserved. // -import XCTest +import Foundation +import Testing @testable import Account -@MainActor final class AccountManagerDuplicateEndpointTests: XCTestCase { +@MainActor struct AccountManagerDuplicateEndpointTests { - func testCaseInsensitiveHostMatches() { - let a = AccountManager.normalizedEndpointForComparison(URL(string: "https://Miniflux.Example.com")) - let b = AccountManager.normalizedEndpointForComparison(URL(string: "https://miniflux.example.com")) - XCTAssertEqual(a, b) - } - - func testTrailingSlashIsIgnored() { - let a = AccountManager.normalizedEndpointForComparison(URL(string: "https://miniflux.example.com/")) - let b = AccountManager.normalizedEndpointForComparison(URL(string: "https://miniflux.example.com")) - XCTAssertEqual(a, b) - } - - func testSchemeAndDefaultPortAreIgnored() { + @Test func hostCaseTrailingSlashSchemeAndDefaultPortAreIgnored() { let endpoint = AccountManager.normalizedEndpointForComparison(URL(string: "https://miniflux.example.com")) - XCTAssertEqual(AccountManager.normalizedEndpointForComparison(URL(string: "https://miniflux.example.com:443")), endpoint) - XCTAssertEqual(AccountManager.normalizedEndpointForComparison(URL(string: "http://miniflux.example.com")), endpoint) + #expect(AccountManager.normalizedEndpointForComparison(URL(string: "https://Miniflux.Example.com/")) == endpoint) + #expect(AccountManager.normalizedEndpointForComparison(URL(string: "https://miniflux.example.com:443")) == endpoint) + #expect(AccountManager.normalizedEndpointForComparison(URL(string: "http://miniflux.example.com")) == endpoint) } - func testDifferentPathsDoNotMatch() { - let a = AccountManager.normalizedEndpointForComparison(URL(string: "https://example.com/miniflux")) - let b = AccountManager.normalizedEndpointForComparison(URL(string: "https://example.com/other")) - XCTAssertNotEqual(a, b) + @Test func differentPathsDoNotMatch() { + let first = AccountManager.normalizedEndpointForComparison(URL(string: "https://example.com/miniflux")) + let second = AccountManager.normalizedEndpointForComparison(URL(string: "https://example.com/other")) + #expect(first != second) } - func testNilURLNormalizesToNil() { - XCTAssertNil(AccountManager.normalizedEndpointForComparison(nil)) - } - - func testSameUsernameOnDifferentServersIsAllowed() { + @Test func duplicateRequiresSameUsernameAndServer() { let existingAccount = TestAccountManager.shared.createAccount(type: .miniflux) defer { TestAccountManager.shared.deleteAccount(existingAccount) @@ -47,18 +33,8 @@ import XCTest existingAccount.username = "admin" existingAccount.endpointURL = URL(string: "https://first.miniflux.test") - XCTAssertFalse(AccountManager.duplicateServiceAccount(type: .miniflux, username: "admin", endpoint: URL(string: "https://second.miniflux.test"), among: [existingAccount])) - XCTAssertTrue(AccountManager.duplicateServiceAccount(type: .miniflux, username: "admin", endpoint: URL(string: "https://first.miniflux.test"), among: [existingAccount])) - } - - func testDifferentUsernamesOnSameServerAreAllowed() { - let existingAccount = TestAccountManager.shared.createAccount(type: .miniflux) - defer { - TestAccountManager.shared.deleteAccount(existingAccount) - } - existingAccount.username = "admin" - existingAccount.endpointURL = URL(string: "https://first.miniflux.test") - - XCTAssertFalse(AccountManager.duplicateServiceAccount(type: .miniflux, username: "claude", endpoint: URL(string: "https://first.miniflux.test"), among: [existingAccount])) + #expect(AccountManager.duplicateServiceAccount(type: .miniflux, username: "admin", endpoint: URL(string: "https://first.miniflux.test"), among: [existingAccount])) + #expect(!AccountManager.duplicateServiceAccount(type: .miniflux, username: "admin", endpoint: URL(string: "https://second.miniflux.test"), among: [existingAccount])) + #expect(!AccountManager.duplicateServiceAccount(type: .miniflux, username: "claude", endpoint: URL(string: "https://first.miniflux.test"), among: [existingAccount])) } } diff --git a/Modules/Account/Tests/AccountTests/JSON/miniflux_me.json b/Modules/Account/Tests/AccountTests/JSON/miniflux_me.json deleted file mode 100644 index 770d08f03..000000000 --- a/Modules/Account/Tests/AccountTests/JSON/miniflux_me.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "id": 35, - "username": "testuser", - "is_admin": false, - "theme": "light_serif", - "language": "en_US", - "timezone": "UTC" -} diff --git a/Modules/Account/Tests/AccountTests/Miniflux/AccountMinifluxFolderSyncTest.swift b/Modules/Account/Tests/AccountTests/Miniflux/AccountMinifluxFolderSyncTest.swift index b151c0ea4..a7ef2e553 100644 --- a/Modules/Account/Tests/AccountTests/Miniflux/AccountMinifluxFolderSyncTest.swift +++ b/Modules/Account/Tests/AccountTests/Miniflux/AccountMinifluxFolderSyncTest.swift @@ -6,23 +6,15 @@ // Copyright © 2026 Ranchero Software, LLC. All rights reserved. // -import XCTest +import Foundation +import Testing import RSWeb @testable import Account -@MainActor final class AccountMinifluxFolderSyncTest: XCTestCase { +@Suite(.isolatedWebserviceResponses) @MainActor struct AccountMinifluxFolderSyncTest { - override func setUp() { - TestingURLProtocol.reset() - } - - func testDownloadSync() async throws { - - TestingURLProtocol.setResponse("/v1/version", file: "JSON/miniflux_version.json") - TestingURLProtocol.setResponse("/v1/categories", file: "JSON/miniflux_categories_initial.json") - TestingURLProtocol.setResponse("/v1/feeds", file: "JSON/miniflux_feeds_initial.json") - TestingURLProtocol.setResponse("/v1/entries/ids", file: "JSON/miniflux_entry_ids.json") - TestingURLProtocol.setResponse("/v1/entries?", file: "JSON/miniflux_entries_page1.json") + @Test func feedsLandInTheirCategoryFolders() async throws { + setInitialSyncResponses() let account = TestAccountManager.shared.createAccount(type: .miniflux) defer { @@ -30,135 +22,60 @@ import RSWeb } account.endpointURL = URL(string: "https://miniflux.test") - // Test initial folders - try await account.refreshAll() - guard let initialFolders = account.folders else { - XCTFail("Expected folders after the initial sync") - return + #expect(folderExternalIDsByName(account) == ["All": "1", "Tech": "2", "News": "3"]) + #expect(feedExternalIDsByFolderName(account) == ["All": ["101", "105"], "Tech": ["102", "103"], "News": ["104"]]) + #expect(account.topLevelFeeds.isEmpty) + + let generalFeed = try #require(account.existingFeed(withExternalID: "101")) + #expect(generalFeed.url == "https://miniflux.test/feeds/general.xml") + #expect(generalFeed.name == "General Feed") + } + + @Test func removedAndAddedCategoriesUpdateFolders() async throws { + setInitialSyncResponses() + + let account = TestAccountManager.shared.createAccount(type: .miniflux) + defer { + TestAccountManager.shared.deleteAccount(account) } + account.endpointURL = URL(string: "https://miniflux.test") - XCTAssertEqual(3, initialFolders.count) - - guard let all = initialFolders.first(where: { $0.name == "All" }) else { - XCTFail("Expected an “All” folder") - return - } - XCTAssertEqual("1", all.externalID) - - guard let tech = initialFolders.first(where: { $0.name == "Tech" }) else { - XCTFail("Expected a “Tech” folder") - return - } - XCTAssertEqual("2", tech.externalID) - - guard let news = initialFolders.first(where: { $0.name == "News" }) else { - XCTFail("Expected a “News” folder") - return - } - XCTAssertEqual("3", news.externalID) - - // Test removing a folder + try await account.refreshAll() TestingURLProtocol.setResponse("/v1/categories", file: "JSON/miniflux_categories_delete.json") - try await account.refreshAll() - - guard let deleteFolders = account.folders else { - XCTFail("Expected folders after removing a category") - return - } - - XCTAssertEqual(2, deleteFolders.count) - let deleteFolderNames = deleteFolders.map { $0.name ?? "" } - XCTAssertTrue(deleteFolderNames.contains("All")) - XCTAssertTrue(deleteFolderNames.contains("Tech")) - XCTAssertFalse(deleteFolderNames.contains("News")) - - // Test adding a folder + #expect(folderExternalIDsByName(account) == ["All": "1", "Tech": "2"]) TestingURLProtocol.setResponse("/v1/categories", file: "JSON/miniflux_categories_add.json") - try await account.refreshAll() - - guard let addFolders = account.folders else { - XCTFail("Expected folders after adding a category") - return - } - - XCTAssertEqual(4, addFolders.count) - let addFolderNames = addFolders.map { $0.name ?? "" } - XCTAssertTrue(addFolderNames.contains("News")) - XCTAssertTrue(addFolderNames.contains("Reviews")) - - guard let reviews = addFolders.first(where: { $0.name == "Reviews" }) else { - XCTFail("Expected a “Reviews” folder") - return - } - XCTAssertEqual("4", reviews.externalID) + #expect(folderExternalIDsByName(account) == ["All": "1", "Tech": "2", "News": "3", "Reviews": "4"]) } - - func testFeedsLandInCorrectFolders() async throws { - - TestingURLProtocol.setResponse("/v1/version", file: "JSON/miniflux_version.json") - TestingURLProtocol.setResponse("/v1/categories", file: "JSON/miniflux_categories_initial.json") - TestingURLProtocol.setResponse("/v1/feeds", file: "JSON/miniflux_feeds_initial.json") - TestingURLProtocol.setResponse("/v1/entries/ids", file: "JSON/miniflux_entry_ids.json") - TestingURLProtocol.setResponse("/v1/entries?", file: "JSON/miniflux_entries_page1.json") - - let account = TestAccountManager.shared.createAccount(type: .miniflux) - defer { - TestAccountManager.shared.deleteAccount(account) - } - account.endpointURL = URL(string: "https://miniflux.test") - - try await account.refreshAll() - - guard let folders = account.folders else { - XCTFail("Expected folders after the initial sync") - return - } - XCTAssertEqual(3, folders.count) +} + +// MARK: - Helpers + +private func setInitialSyncResponses() { + TestingURLProtocol.setResponse("/v1/version", file: "JSON/miniflux_version.json") + TestingURLProtocol.setResponse("/v1/categories", file: "JSON/miniflux_categories_initial.json") + TestingURLProtocol.setResponse("/v1/feeds", file: "JSON/miniflux_feeds_initial.json") + TestingURLProtocol.setResponse("/v1/entries/ids", file: "JSON/miniflux_entry_ids.json") + TestingURLProtocol.setResponse("/v1/entries?", file: "JSON/miniflux_entries_page1.json") +} + +@MainActor private func folderExternalIDsByName(_ account: Account) -> [String: String] { + var externalIDsByName = [String: String]() + for folder in account.folders ?? [] { + externalIDsByName[folder.name ?? ""] = folder.externalID + } + return externalIDsByName +} - guard let all = folders.first(where: { $0.name == "All" }) else { - XCTFail("Expected an “All” folder") - return - } - guard let tech = folders.first(where: { $0.name == "Tech" }) else { - XCTFail("Expected a “Tech” folder") - return - } - guard let news = folders.first(where: { $0.name == "News" }) else { - XCTFail("Expected a “News” folder") - return - } - - // Feeds 101 and 105 belong to category 1 (“All”). - XCTAssertEqual(2, all.topLevelFeeds.count) - let allFeedExternalIDs = Set(all.topLevelFeeds.map { $0.externalID }) - XCTAssertEqual(Set(["101", "105"]), allFeedExternalIDs) - - // Feeds 102 and 103 belong to category 2 (“Tech”). - XCTAssertEqual(2, tech.topLevelFeeds.count) - let techFeedExternalIDs = Set(tech.topLevelFeeds.map { $0.externalID }) - XCTAssertEqual(Set(["102", "103"]), techFeedExternalIDs) - - // Feed 104 belongs to category 3 (“News”). - XCTAssertEqual(1, news.topLevelFeeds.count) - let newsFeedExternalIDs = Set(news.topLevelFeeds.map { $0.externalID }) - XCTAssertEqual(Set(["104"]), newsFeedExternalIDs) - - // Miniflux feeds always belong to exactly one category, so nothing should land - // at the account's top level. - XCTAssertEqual(0, account.topLevelFeeds.count) - - guard let generalFeed = all.topLevelFeeds.first(where: { $0.externalID == "101" }) else { - XCTFail("Expected feed 101 in the “All” folder") - return - } - XCTAssertEqual("https://miniflux.test/feeds/general.xml", generalFeed.url) - XCTAssertEqual("General Feed", generalFeed.name) +@MainActor private func feedExternalIDsByFolderName(_ account: Account) -> [String: Set] { + var externalIDsByName = [String: Set]() + for folder in account.folders ?? [] { + externalIDsByName[folder.name ?? ""] = Set(folder.topLevelFeeds.map { $0.externalID ?? "" }) } - + return externalIDsByName } diff --git a/Modules/Account/Tests/AccountTests/Miniflux/MinifluxModelDecodingTests.swift b/Modules/Account/Tests/AccountTests/Miniflux/MinifluxModelDecodingTests.swift index 5909536df..3da56a70a 100644 --- a/Modules/Account/Tests/AccountTests/Miniflux/MinifluxModelDecodingTests.swift +++ b/Modules/Account/Tests/AccountTests/Miniflux/MinifluxModelDecodingTests.swift @@ -6,152 +6,38 @@ // Copyright © 2026 Ranchero Software, LLC. All rights reserved. // -import XCTest +import Foundation +import Testing @testable import Account -@MainActor final class MinifluxModelDecodingTests: XCTestCase { +struct MinifluxModelDecodingTests { - func testDecodeUser() throws { - let user = try decode(MinifluxUser.self, from: "miniflux_me.json") - XCTAssertEqual("testuser", user.username) - } + @Test func entriesResponse() throws { + let resourceURL = try #require(Bundle.module.resourceURL) + let data = try Data(contentsOf: resourceURL.appendingPathComponent("JSON/miniflux_entries_page1.json")) + let entries = try JSONDecoder().decode(MinifluxEntriesResponse.self, from: data).entries - func testDecodeCategories() throws { - let categories = try decode([MinifluxCategory].self, from: "miniflux_categories_initial.json") - XCTAssertEqual(3, categories.count) + let unreadStarred = try #require(entries.first { $0.entryID == 5001 }) + #expect(unreadStarred.status == .unread) + #expect(unreadStarred.starred == true) + // published_at has fractional seconds, which JSONDecoder’s .iso8601 strategy can’t parse. + #expect(unreadStarred.parsedDatePublished != nil) - guard let all = categories.first(where: { $0.title == "All" }) else { - XCTFail("Expected an “All” category") - return - } - XCTAssertEqual(1, all.categoryID) + let read = try #require(entries.first { $0.entryID == 5002 }) + #expect(read.status == .read) - guard let tech = categories.first(where: { $0.title == "Tech" }) else { - XCTFail("Expected a “Tech” category") - return - } - XCTAssertEqual(2, tech.categoryID) + let missingAuthor = try #require(entries.first { $0.entryID == 5003 }) + #expect(missingAuthor.author == nil) - guard let news = categories.first(where: { $0.title == "News" }) else { - XCTFail("Expected a “News” category") - return - } - XCTAssertEqual(3, news.categoryID) - } + let emptyEnclosures = try #require(entries.first { $0.entryID == 5004 }) + #expect(emptyEnclosures.enclosures?.isEmpty == true) + #expect(emptyEnclosures.attachments == nil) - func testDecodeCategoriesAfterDelete() throws { - let categories = try decode([MinifluxCategory].self, from: "miniflux_categories_delete.json") - XCTAssertEqual(2, categories.count) - XCTAssertFalse(categories.contains { $0.title == "News" }) - } - - func testDecodeFeeds() throws { - let feeds = try decode([MinifluxFeed].self, from: "miniflux_feeds_initial.json") - XCTAssertEqual(5, feeds.count) - - guard let feed = feeds.first(where: { $0.feedID == 101 }) else { - XCTFail("Expected feed 101") - return - } - XCTAssertEqual("https://miniflux.test/feeds/general.xml", feed.feedURL) - XCTAssertEqual("https://general.example", feed.siteURL) - XCTAssertEqual("General Feed", feed.title) - XCTAssertEqual(1, feed.category?.categoryID) - XCTAssertEqual("All", feed.category?.title) - - // Feed 105 has no "icon" key at all — confirms lenient decoding tolerates its absence. - guard let feedWithoutIcon = feeds.first(where: { $0.feedID == 105 }) else { - XCTFail("Expected feed 105") - return - } - XCTAssertEqual(1, feedWithoutIcon.category?.categoryID) - - let categoryIDs = Set(feeds.compactMap { $0.category?.categoryID }) - XCTAssertEqual(Set([1, 2, 3]), categoryIDs) - } - - func testDecodeEntriesResponse() throws { - let response = try decode(MinifluxEntriesResponse.self, from: "miniflux_entries_page1.json") - XCTAssertEqual(5, response.total) - XCTAssertEqual(5, response.entries.count) - - guard let unreadStarred = response.entries.first(where: { $0.entryID == 5001 }) else { - XCTFail("Expected entry 5001") - return - } - XCTAssertEqual(101, unreadStarred.feedID) - XCTAssertEqual("Jane Doe", unreadStarred.author) - XCTAssertEqual(.unread, unreadStarred.status) - XCTAssertEqual(true, unreadStarred.starred) - // published_at has fractional seconds — confirms DateParser (not JSONDecoder's - // .iso8601 strategy) is what's doing the parsing. - XCTAssertNotNil(unreadStarred.parsedDatePublished) - - guard let readEntry = response.entries.first(where: { $0.entryID == 5002 }) else { - XCTFail("Expected entry 5002") - return - } - XCTAssertEqual(.read, readEntry.status) - XCTAssertEqual(false, readEntry.starred) - - guard let missingAuthor = response.entries.first(where: { $0.entryID == 5003 }) else { - XCTFail("Expected entry 5003") - return - } - XCTAssertNil(missingAuthor.author) - - guard let emptyEnclosures = response.entries.first(where: { $0.entryID == 5004 }) else { - XCTFail("Expected entry 5004") - return - } - XCTAssertNotNil(emptyEnclosures.enclosures) - XCTAssertEqual(0, emptyEnclosures.enclosures?.count ?? -1) - XCTAssertNil(emptyEnclosures.attachments) - - guard let withEnclosure = response.entries.first(where: { $0.entryID == 5005 }) else { - XCTFail("Expected entry 5005") - return - } - guard let enclosure = withEnclosure.enclosures?.first else { - XCTFail("Expected an enclosure on entry 5005") - return - } - XCTAssertEqual("https://media.example/ep1.mp3", enclosure.url) - XCTAssertEqual("audio/mpeg", enclosure.mimeType) - - let attachments = withEnclosure.attachments ?? [] - XCTAssertEqual(["https://media.example/ep1.mp3", "https://media.example/ep1.jpg"], attachments.map(\.url)) - XCTAssertEqual(1234567, attachments.first?.sizeInBytes) - XCTAssertNil(attachments.last?.sizeInBytes) - XCTAssertEqual("https://media.example/ep1.jpg", withEnclosure.imageURL) - } - - func testDecodeEntryIDsResponse() throws { - let response = try decode(MinifluxEntryIDsResponse.self, from: "miniflux_entry_ids.json") - XCTAssertEqual(3, response.total) - XCTAssertEqual([5001, 5003, 5004], response.entryIDs) - } - - func testDecodeErrorResponse() throws { - let json = Data(#"{"error_message": "This feed already exists (feed_id: 123)"}"#.utf8) - let error = try JSONDecoder().decode(MinifluxErrorResponse.self, from: json) - XCTAssertEqual("This feed already exists (feed_id: 123)", error.errorMessage) - } - - func testDecodeVersionResponse() throws { - let response = try decode(MinifluxVersionResponse.self, from: "miniflux_version.json") - XCTAssertEqual("2.3.2", response.version) - } -} - -// MARK: - Fixture loading - -private extension MinifluxModelDecodingTests { - - func decode(_ type: T.Type, from fileName: String) throws -> T { - let resourceURL = try XCTUnwrap(Bundle.module.resourceURL) - let fileURL = resourceURL.appendingPathComponent("JSON/\(fileName)") - let data = try Data(contentsOf: fileURL) - return try JSONDecoder().decode(T.self, from: data) + let withEnclosures = try #require(entries.first { $0.entryID == 5005 }) + let attachments = try #require(withEnclosures.attachments) + #expect(attachments.map(\.url) == ["https://media.example/ep1.mp3", "https://media.example/ep1.jpg"]) + #expect(attachments.first?.sizeInBytes == 1234567) + #expect(attachments.last?.sizeInBytes == nil) + #expect(withEnclosures.imageURL == "https://media.example/ep1.jpg") } } diff --git a/Modules/Account/Tests/AccountTests/Miniflux/MinifluxStarredFallbackTests.swift b/Modules/Account/Tests/AccountTests/Miniflux/MinifluxStarredFallbackTests.swift index 6885d2d91..12d19b104 100644 --- a/Modules/Account/Tests/AccountTests/Miniflux/MinifluxStarredFallbackTests.swift +++ b/Modules/Account/Tests/AccountTests/Miniflux/MinifluxStarredFallbackTests.swift @@ -6,36 +6,33 @@ // Copyright © 2026 Ranchero Software, LLC. All rights reserved. // -import XCTest +import Foundation +import Testing import RSWeb import Secrets @testable import Account -@MainActor final class MinifluxStarredFallbackTests: XCTestCase { +@Suite(.isolatedWebserviceResponses) @MainActor struct MinifluxStarredFallbackTests { - override func setUp() { - TestingURLProtocol.reset() - } - - func testFallbackOnlyTogglesEntriesWhoseStateDiffers() async throws { + @Test func fallbackOnlyTogglesEntriesWhoseStateDiffers() async throws { let accountSettings = AccountSettings(accountID: UUID().uuidString, dataFolder: NSTemporaryDirectory()) defer { accountSettings.deleteSettings() } accountSettings.endpointURL = URL(string: "https://miniflux.test") - accountSettings.detectedServerVersion = "2.1.0" // Below entryIDsMinimumVersion. + accountSettings.detectedServerVersion = "2.1.0" let caller = MinifluxAPICaller() caller.credentials = Credentials(type: .minifluxAPIToken, username: "", secret: "token") caller.accountSettings = accountSettings - // 5001 is already starred; 5002 is not. + // 5001 is already starred, and 5002 isn’t. TestingURLProtocol.setResponse("/v1/entries/5001", file: "JSON/miniflux_entry_5001_starred.json") TestingURLProtocol.setResponse("/v1/entries/5002", file: "JSON/miniflux_entry_5002_unstarred.json") try await caller.updateEntries(entryIDs: [5001, 5002], starred: true) - XCTAssertEqual(TestingURLProtocol.requestCount(forURLContaining: "/entries/5001/bookmark"), 0) - XCTAssertGreaterThan(TestingURLProtocol.requestCount(forURLContaining: "/entries/5002/bookmark"), 0) + #expect(TestingURLProtocol.requestCount(forURLContaining: "/entries/5001/bookmark") == 0) + #expect(TestingURLProtocol.requestCount(forURLContaining: "/entries/5002/bookmark") > 0) } } diff --git a/Modules/Account/Tests/AccountTests/Miniflux/MinifluxSyncRegressionTests.swift b/Modules/Account/Tests/AccountTests/Miniflux/MinifluxSyncRegressionTests.swift index 30c84adc4..d4c86167c 100644 --- a/Modules/Account/Tests/AccountTests/Miniflux/MinifluxSyncRegressionTests.swift +++ b/Modules/Account/Tests/AccountTests/Miniflux/MinifluxSyncRegressionTests.swift @@ -6,24 +6,21 @@ // Copyright © 2026 Ranchero Software, LLC. All rights reserved. // -import XCTest +import Foundation +import Testing import RSWeb import SyncDatabase @testable import Account -@MainActor final class MinifluxSyncRegressionTests: XCTestCase { +@Suite(.isolatedWebserviceResponses) @MainActor struct MinifluxSyncRegressionTests { - override func setUp() { - TestingURLProtocol.reset() - } - - func testFailedStarredSendKeepsItsQueuedStatusAfterReadSendSucceeds() async throws { + @Test func failedStarredSendKeepsItsQueuedStatusAfterReadSendSucceeds() async throws { let account = TestAccountManager.shared.createAccount(type: .miniflux) defer { TestAccountManager.shared.deleteAccount(account) } account.endpointURL = URL(string: "https://miniflux.test") - let delegate = try XCTUnwrap(account.delegate as? MinifluxAccountDelegate) + let delegate = try #require(account.delegate as? MinifluxAccountDelegate) delegate.accountSettings?.detectedServerVersion = "2.1.0" let databasePath = (account.dataFolder as NSString).appendingPathComponent("Sync.sqlite3") @@ -35,23 +32,18 @@ import SyncDatabase TestingURLProtocol.setResponse(.init(statusCode: 204), forURLContaining: "/v1/entries", httpMethod: "PUT") TestingURLProtocol.setResponse(.init(statusCode: 500), forURLContaining: "/v1/entries/5001", httpMethod: "GET") - do { + await #expect(throws: (any Error).self) { try await account.sendArticleStatus() - XCTFail("Expected the starred update to fail") - } catch { - let pendingRead = try await database.selectPendingReadStatusArticleIDs() - let pendingStarred = try await database.selectPendingStarredStatusArticleIDs() - XCTAssertEqual(pendingRead, []) - XCTAssertEqual(pendingStarred, ["5001"]) } + + let pendingRead = try await database.selectPendingReadStatusArticleIDs() + let pendingStarred = try await database.selectPendingStarredStatusArticleIDs() + #expect(pendingRead == []) + #expect(pendingStarred == ["5001"]) } - func testFailedInitialReconciliationIsRetried() async throws { - TestingURLProtocol.setResponse("/v1/version", file: "JSON/miniflux_version.json") - TestingURLProtocol.setResponse("/v1/categories", file: "JSON/miniflux_categories_initial.json") - TestingURLProtocol.setResponse("/v1/feeds", file: "JSON/miniflux_feeds_initial.json") - TestingURLProtocol.setResponse("/v1/entries?", file: "JSON/miniflux_entries_page1.json") - TestingURLProtocol.setResponse(.init(statusCode: 500), forURLContaining: "/v1/entries/ids") + @Test func failedInitialReconciliationIsRetried() async throws { + setFailingReconciliationResponses() let account = TestAccountManager.shared.createAccount(type: .miniflux) defer { @@ -59,27 +51,20 @@ import SyncDatabase } account.endpointURL = URL(string: "https://miniflux.test") - do { + await #expect(throws: (any Error).self) { try await account.refreshAll() - XCTFail("Expected initial reconciliation to fail") - } catch { - // Expected: the first /v1/entries/ids request returns 500. } let firstAttemptCount = TestingURLProtocol.requestCount(forURLContaining: "/v1/entries/ids") - XCTAssertGreaterThan(firstAttemptCount, 0) + #expect(firstAttemptCount > 0) TestingURLProtocol.setResponse("/v1/entries/ids", file: "JSON/miniflux_entry_ids.json") try await account.refreshAll() - XCTAssertGreaterThan(TestingURLProtocol.requestCount(forURLContaining: "/v1/entries/ids"), firstAttemptCount) + #expect(TestingURLProtocol.requestCount(forURLContaining: "/v1/entries/ids") > firstAttemptCount) } - func testRefreshAfterFailedInitialSyncSendsChangedAfter() async throws { - TestingURLProtocol.setResponse("/v1/version", file: "JSON/miniflux_version.json") - TestingURLProtocol.setResponse("/v1/categories", file: "JSON/miniflux_categories_initial.json") - TestingURLProtocol.setResponse("/v1/feeds", file: "JSON/miniflux_feeds_initial.json") - TestingURLProtocol.setResponse("/v1/entries?", file: "JSON/miniflux_entries_page1.json") - TestingURLProtocol.setResponse(.init(statusCode: 500), forURLContaining: "/v1/entries/ids") + @Test func refreshAfterFailedInitialSyncSendsChangedAfter() async throws { + setFailingReconciliationResponses() let account = TestAccountManager.shared.createAccount(type: .miniflux) defer { @@ -87,20 +72,17 @@ import SyncDatabase } account.endpointURL = URL(string: "https://miniflux.test") - do { + await #expect(throws: (any Error).self) { try await account.refreshAll() - XCTFail("Expected initial reconciliation to fail") - } catch { - // Expected: the article fetch succeeds, then /v1/entries/ids returns 500. } - XCTAssertEqual(TestingURLProtocol.requestCount(forURLContaining: "changed_after"), 0) + #expect(TestingURLProtocol.requestCount(forURLContaining: "changed_after") == 0) try? await account.refreshAll() - XCTAssertGreaterThan(TestingURLProtocol.requestCount(forURLContaining: "changed_after"), 0) + #expect(TestingURLProtocol.requestCount(forURLContaining: "changed_after") > 0) } - func testMissingArticleHTTPErrorDoesNotFailRefresh() async throws { + @Test func missingArticleHTTPErrorDoesNotFailRefresh() async throws { TestingURLProtocol.setResponse("/v1/version", file: "JSON/miniflux_version.json") TestingURLProtocol.setResponse("/v1/categories", file: "JSON/miniflux_categories_initial.json") TestingURLProtocol.setResponse("/v1/feeds", file: "JSON/miniflux_feeds_initial.json") @@ -116,16 +98,16 @@ import SyncDatabase try await account.refreshAll() - XCTAssertGreaterThan(TestingURLProtocol.requestCount(forURLContaining: "/v1/entries/9001"), 0) - XCTAssertNotNil(account.lastRefreshCompletedDate) + #expect(TestingURLProtocol.requestCount(forURLContaining: "/v1/entries/9001") > 0) + #expect(account.lastRefreshCompletedDate != nil) } - func testInitialReconciliationPreservesPendingLocalStatus() async throws { + @Test func initialReconciliationPreservesPendingLocalStatus() async throws { let account = TestAccountManager.shared.createAccount(type: .miniflux) defer { TestAccountManager.shared.deleteAccount(account) } - let delegate = try XCTUnwrap(account.delegate as? MinifluxAccountDelegate) + let delegate = try #require(account.delegate as? MinifluxAccountDelegate) var markedOff = Set() let changedCount = await delegate.syncArticleState( @@ -139,7 +121,18 @@ import SyncDatabase } ) - XCTAssertTrue(markedOff.isEmpty) - XCTAssertEqual(changedCount, 0) + #expect(markedOff.isEmpty) + #expect(changedCount == 0) } } + +// MARK: - Helpers + +/// The article fetch succeeds, then `/v1/entries/ids` returns 500. +private func setFailingReconciliationResponses() { + TestingURLProtocol.setResponse("/v1/version", file: "JSON/miniflux_version.json") + TestingURLProtocol.setResponse("/v1/categories", file: "JSON/miniflux_categories_initial.json") + TestingURLProtocol.setResponse("/v1/feeds", file: "JSON/miniflux_feeds_initial.json") + TestingURLProtocol.setResponse("/v1/entries?", file: "JSON/miniflux_entries_page1.json") + TestingURLProtocol.setResponse(.init(statusCode: 500), forURLContaining: "/v1/entries/ids") +} diff --git a/Modules/Account/Tests/AccountTests/Miniflux/MinifluxVersionFallbackTests.swift b/Modules/Account/Tests/AccountTests/Miniflux/MinifluxVersionFallbackTests.swift index 499ce9b32..6a4b43b7f 100644 --- a/Modules/Account/Tests/AccountTests/Miniflux/MinifluxVersionFallbackTests.swift +++ b/Modules/Account/Tests/AccountTests/Miniflux/MinifluxVersionFallbackTests.swift @@ -6,20 +6,15 @@ // Copyright © 2026 Ranchero Software, LLC. All rights reserved. // -import XCTest +import Foundation +import Testing import RSWeb @testable import Account -@MainActor final class MinifluxVersionFallbackTests: XCTestCase { +@Suite(.isolatedWebserviceResponses) @MainActor struct MinifluxVersionFallbackTests { - override func setUp() { - TestingURLProtocol.reset() - } - - /// On a server older than `entryIDsMinimumVersion`, `/v1/entries/ids` isn’t stubbed at - /// all — if the gating logic wrongly tried to use it, `refreshAll()` would throw. Instead - /// the initial sync's reconciliation must fall back to paging `/v1/entries`. - func testInitialSyncOnOldServerFallsBackToPagedEntries() async throws { + /// `/v1/entries/ids` isn’t stubbed, so the refresh would throw if an old server used it. + @Test func initialSyncOnOldServerFallsBackToPagedEntries() async throws { TestingURLProtocol.setResponse("/v1/version", file: "JSON/miniflux_version_old.json") TestingURLProtocol.setResponse("/v1/categories", file: "JSON/miniflux_categories_initial.json") TestingURLProtocol.setResponse("/v1/feeds", file: "JSON/miniflux_feeds_initial.json") @@ -35,32 +30,7 @@ import RSWeb let unreadArticleIDs = await account.fetchUnreadArticleIDsAsync() let starredArticleIDs = await account.fetchStarredArticleIDsAsync() - XCTAssertTrue(unreadArticleIDs.contains("5001")) - XCTAssertTrue(starredArticleIDs.contains("5001")) - } - - /// On a current server, the initial sync's reconciliation should still use - /// `/v1/entries/ids` rather than the paged fallback. - func testInitialSyncOnCurrentServerStillUsesEntryIDsEndpoint() async throws { - TestingURLProtocol.setResponse("/v1/version", file: "JSON/miniflux_version.json") - TestingURLProtocol.setResponse("/v1/categories", file: "JSON/miniflux_categories_initial.json") - TestingURLProtocol.setResponse("/v1/feeds", file: "JSON/miniflux_feeds_initial.json") - TestingURLProtocol.setResponse("/v1/entries/ids", file: "JSON/miniflux_entry_ids.json") - TestingURLProtocol.setResponse("/v1/entries?", file: "JSON/miniflux_entries_page1.json") - - let account = TestAccountManager.shared.createAccount(type: .miniflux) - defer { - TestAccountManager.shared.deleteAccount(account) - } - account.endpointURL = URL(string: "https://miniflux.test") - - try await account.refreshAll() - - XCTAssertGreaterThan(TestingURLProtocol.requestCount(forURLContaining: "/v1/entries/ids"), 0) - - let unreadArticleIDs = await account.fetchUnreadArticleIDsAsync() - let starredArticleIDs = await account.fetchStarredArticleIDsAsync() - XCTAssertTrue(unreadArticleIDs.contains("5001")) - XCTAssertTrue(starredArticleIDs.contains("5001")) + #expect(unreadArticleIDs.contains("5001")) + #expect(starredArticleIDs.contains("5001")) } } diff --git a/Modules/Account/Tests/AccountTests/Miniflux/MinifluxVersionTests.swift b/Modules/Account/Tests/AccountTests/Miniflux/MinifluxVersionTests.swift index 1c88ecc28..1e2c0bdc6 100644 --- a/Modules/Account/Tests/AccountTests/Miniflux/MinifluxVersionTests.swift +++ b/Modules/Account/Tests/AccountTests/Miniflux/MinifluxVersionTests.swift @@ -6,36 +6,21 @@ // Copyright © 2026 Ranchero Software, LLC. All rights reserved. // -import XCTest +import Testing @testable import Account -final class MinifluxVersionTests: XCTestCase { +struct MinifluxVersionTests { - func testParsesSimpleVersionString() throws { - let version = try XCTUnwrap(MinifluxVersion(string: "2.3.2")) - XCTAssertGreaterThanOrEqual(version, MinifluxVersion(2, 3, 2)) - XCTAssertEqual(version, MinifluxVersion(2, 3, 2)) + @Test func comparesNumericallyNotLexicographically() { + #expect(MinifluxVersion(2, 3, 10) > MinifluxVersion(2, 3, 2)) } - func testComparesNumericallyNotLexicographically() { - XCTAssertGreaterThan(MinifluxVersion(2, 3, 10), MinifluxVersion(2, 3, 2)) + @Test func parsesDevSuffixAndMissingComponent() { + #expect(MinifluxVersion(string: "2.3.2-dev") == MinifluxVersion(2, 3, 2)) + #expect(MinifluxVersion(string: "2.3") == MinifluxVersion(2, 3, 0)) } - func testOlderMinorVersionIsLess() { - XCTAssertLessThan(MinifluxVersion(2, 2, 17), MinifluxVersion(2, 3, 2)) - } - - func testParsesNonNumericSuffixOnLastComponent() throws { - let version = try XCTUnwrap(MinifluxVersion(string: "2.3.2-dev")) - XCTAssertEqual(version, MinifluxVersion(2, 3, 2)) - } - - func testMissingComponentIsTreatedAsZero() throws { - let version = try XCTUnwrap(MinifluxVersion(string: "2.3")) - XCTAssertEqual(version, MinifluxVersion(2, 3, 0)) - } - - func testWhollyNonNumericStringFailsToParse() { - XCTAssertNil(MinifluxVersion(string: "dev")) + @Test func whollyNonNumericStringFailsToParse() { + #expect(MinifluxVersion(string: "dev") == nil) } }