From f82be276668abd9a6ce6d64c89389df3ff68c0e0 Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Tue, 31 Dec 2019 15:52:54 -0600 Subject: [PATCH 01/12] Resolve errors in Feedly statuses operation tests Add `error` parameters to completion blocks which now pass them. Assert these errors are always nil in the existing tests. Flip calls to `selectPendingCount()` so they are async, with a completion block that asserts about the results instead of asserting about the return value. Since the closure takes a Result, unwrap it in a do/catch block at each site; `XCTAssertNoThrow` doesn't help us bubble a value out from `Result.get()`, and I'd rather not use `try!` here. There might be a stylistic discussion to be had about this unwrapping, though. --- ...dlySendArticleStatusesOperationTests.swift | 121 +++++++++++++++--- 1 file changed, 101 insertions(+), 20 deletions(-) diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlySendArticleStatusesOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlySendArticleStatusesOperationTests.swift index d508f6635..1aee58245 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlySendArticleStatusesOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlySendArticleStatusesOperationTests.swift @@ -50,7 +50,8 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { let statuses = articleIds.map { SyncStatus(articleID: $0, key: .read, flag: false) } let insertExpectation = expectation(description: "Inserted Statuses") - container.database.insertStatuses(statuses) { + container.database.insertStatuses(statuses) { error in + XCTAssertNil(error) insertExpectation.fulfill() } @@ -74,7 +75,14 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - XCTAssertEqual(container.database.selectPendingCount(), 0) + container.database.selectPendingCount { result in + do { + let statusCount = try result.get() + XCTAssertEqual(statusCount, 0) + } catch let e { + XCTFail("Error unwrapping database result: \(e)") + } + } } func testSendUnreadFailure() { @@ -82,7 +90,8 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { let statuses = articleIds.map { SyncStatus(articleID: $0, key: .read, flag: false) } let insertExpectation = expectation(description: "Inserted Statuses") - container.database.insertStatuses(statuses) { + container.database.insertStatuses(statuses) { error in + XCTAssertNil(error) insertExpectation.fulfill() } @@ -106,7 +115,14 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - XCTAssertEqual(container.database.selectPendingCount(), statuses.count) + container.database.selectPendingCount { result in + do { + let statusCount = try result.get() + XCTAssertEqual(statusCount, statuses.count) + } catch let e { + XCTFail("Error unwrapping database result: \(e)") + } + } } func testSendReadSuccess() { @@ -114,7 +130,8 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { let statuses = articleIds.map { SyncStatus(articleID: $0, key: .read, flag: true) } let insertExpectation = expectation(description: "Inserted Statuses") - container.database.insertStatuses(statuses) { + container.database.insertStatuses(statuses) { error in + XCTAssertNil(error) insertExpectation.fulfill() } @@ -138,7 +155,14 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - XCTAssertEqual(container.database.selectPendingCount(), 0) + container.database.selectPendingCount { result in + do { + let statusCount = try result.get() + XCTAssertEqual(statusCount, 0) + } catch let e { + XCTFail("Error unwrapping database result: \(e)") + } + } } func testSendReadFailure() { @@ -146,7 +170,8 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { let statuses = articleIds.map { SyncStatus(articleID: $0, key: .read, flag: true) } let insertExpectation = expectation(description: "Inserted Statuses") - container.database.insertStatuses(statuses) { + container.database.insertStatuses(statuses) { error in + XCTAssertNil(error) insertExpectation.fulfill() } @@ -170,7 +195,14 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - XCTAssertEqual(container.database.selectPendingCount(), statuses.count) + container.database.selectPendingCount { result in + do { + let statusCount = try result.get() + XCTAssertEqual(statusCount, statuses.count) + } catch let e { + XCTFail("Error unwrapping database result: \(e)") + } + } } func testSendStarredSuccess() { @@ -178,7 +210,8 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { let statuses = articleIds.map { SyncStatus(articleID: $0, key: .starred, flag: true) } let insertExpectation = expectation(description: "Inserted Statuses") - container.database.insertStatuses(statuses) { + container.database.insertStatuses(statuses) { error in + XCTAssertNil(error) insertExpectation.fulfill() } @@ -202,7 +235,14 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - XCTAssertEqual(container.database.selectPendingCount(), 0) + container.database.selectPendingCount { result in + do { + let statusCount = try result.get() + XCTAssertEqual(statusCount, 0) + } catch let e { + XCTFail("Error unwrapping database result: \(e)") + } + } } func testSendStarredFailure() { @@ -210,7 +250,8 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { let statuses = articleIds.map { SyncStatus(articleID: $0, key: .starred, flag: true) } let insertExpectation = expectation(description: "Inserted Statuses") - container.database.insertStatuses(statuses) { + container.database.insertStatuses(statuses) { error in + XCTAssertNil(error) insertExpectation.fulfill() } @@ -234,7 +275,14 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - XCTAssertEqual(container.database.selectPendingCount(), statuses.count) + container.database.selectPendingCount { result in + do { + let statusCount = try result.get() + XCTAssertEqual(statusCount, statuses.count) + } catch let e { + XCTFail("Error unwrapping database result: \(e)") + } + } } func testSendUnstarredSuccess() { @@ -242,7 +290,8 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { let statuses = articleIds.map { SyncStatus(articleID: $0, key: .starred, flag: false) } let insertExpectation = expectation(description: "Inserted Statuses") - container.database.insertStatuses(statuses) { + container.database.insertStatuses(statuses) { error in + XCTAssertNil(error) insertExpectation.fulfill() } @@ -266,7 +315,14 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - XCTAssertEqual(container.database.selectPendingCount(), 0) + container.database.selectPendingCount { result in + do { + let statusCount = try result.get() + XCTAssertEqual(statusCount, 0) + } catch let e { + XCTFail("Error unwrapping database result: \(e)") + } + } } func testSendUnstarredFailure() { @@ -274,7 +330,8 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { let statuses = articleIds.map { SyncStatus(articleID: $0, key: .starred, flag: false) } let insertExpectation = expectation(description: "Inserted Statuses") - container.database.insertStatuses(statuses) { + container.database.insertStatuses(statuses) { error in + XCTAssertNil(error) insertExpectation.fulfill() } @@ -298,7 +355,14 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - XCTAssertEqual(container.database.selectPendingCount(), statuses.count) + container.database.selectPendingCount { result in + do { + let expectedCount = try result.get() + XCTAssertEqual(expectedCount, statuses.count) + } catch let e { + XCTFail("Error unwrapping database result: \(e)") + } + } } func testSendAllSuccess() { @@ -313,7 +377,8 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { } let insertExpectation = expectation(description: "Inserted Statuses") - container.database.insertStatuses(statuses) { + container.database.insertStatuses(statuses) { error in + XCTAssertNil(error) insertExpectation.fulfill() } @@ -346,7 +411,15 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { OperationQueue.main.addOperation(send) waitForExpectations(timeout: 2) - XCTAssertEqual(container.database.selectPendingCount(), 0) + + container.database.selectPendingCount { result in + do { + let statusCount = try result.get() + XCTAssertEqual(statusCount, 0) + } catch let e { + XCTFail("Error unwrapping database result: \(e)") + } + } } func testSendAllFailure() { @@ -361,7 +434,8 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { } let insertExpectation = expectation(description: "Inserted Statuses") - container.database.insertStatuses(statuses) { + container.database.insertStatuses(statuses) { error in + XCTAssertNil(error) insertExpectation.fulfill() } @@ -396,6 +470,13 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - XCTAssertEqual(container.database.selectPendingCount(), statuses.count) + container.database.selectPendingCount { result in + do { + let statusCount = try result.get() + XCTAssertEqual(statusCount, statuses.count) + } catch let e { + XCTFail("Error unwrapping database result: \(e)") + } + } } } From ae1651fad1de420f1bce9273ac64fb3ae88516fb Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Tue, 31 Dec 2019 15:55:59 -0600 Subject: [PATCH 02/12] Fix errors in Feedly update-feeds operation tests Mark some throwing calls with `try`; mark the enclosing test functions with `throws`, letting the XCTest framework handle error reporting for us. --- ...dateAccountFeedsWithItemsOperationTests.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlyUpdateAccountFeedsWithItemsOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlyUpdateAccountFeedsWithItemsOperationTests.swift index 7e0b4d087..b828f86e5 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlyUpdateAccountFeedsWithItemsOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlyUpdateAccountFeedsWithItemsOperationTests.swift @@ -32,7 +32,7 @@ class FeedlyUpdateAccountFeedsWithItemsOperationTests: XCTestCase { var parsedItemsKeyedByFeedId: [String: Set] } - func testUpdateAccountWithEmptyItems() { + func testUpdateAccountWithEmptyItems() throws { let testItems = support.makeParsedItemTestDataFor(numberOfFeeds: 0, numberOfItemsInFeeds: 0) let resource = FeedlyCategoryResourceId(id: "user/12345/category/6789") let provider = TestItemsByFeedProvider(providerName: resource.id, parsedItemsKeyedByFeedId: testItems) @@ -52,11 +52,11 @@ class FeedlyUpdateAccountFeedsWithItemsOperationTests: XCTestCase { let articleIds = Set(entries.compactMap { $0.syncServiceID }) XCTAssertEqual(articleIds.count, entries.count, "Not every item has a value for \(\ParsedItem.syncServiceID).") - let accountArticles = account.fetchArticles(.articleIDs(articleIds)) + let accountArticles = try account.fetchArticles(.articleIDs(articleIds)) XCTAssertTrue(accountArticles.isEmpty) } - func testUpdateAccountWithOneItem() { + func testUpdateAccountWithOneItem() throws { let testItems = support.makeParsedItemTestDataFor(numberOfFeeds: 1, numberOfItemsInFeeds: 1) let resource = FeedlyCategoryResourceId(id: "user/12345/category/6789") let provider = TestItemsByFeedProvider(providerName: resource.id, parsedItemsKeyedByFeedId: testItems) @@ -76,7 +76,7 @@ class FeedlyUpdateAccountFeedsWithItemsOperationTests: XCTestCase { let articleIds = Set(entries.compactMap { $0.syncServiceID }) XCTAssertEqual(articleIds.count, entries.count, "Not every item has a value for \(\ParsedItem.syncServiceID).") - let accountArticles = account.fetchArticles(.articleIDs(articleIds)) + let accountArticles = try account.fetchArticles(.articleIDs(articleIds)) XCTAssertTrue(accountArticles.count == entries.count) let accountArticleIds = Set(accountArticles.map { $0.articleID }) @@ -84,7 +84,7 @@ class FeedlyUpdateAccountFeedsWithItemsOperationTests: XCTestCase { XCTAssertTrue(missingIds.isEmpty) } - func testUpdateAccountWithManyItems() { + func testUpdateAccountWithManyItems() throws { let testItems = support.makeParsedItemTestDataFor(numberOfFeeds: 100, numberOfItemsInFeeds: 100) let resource = FeedlyCategoryResourceId(id: "user/12345/category/6789") let provider = TestItemsByFeedProvider(providerName: resource.id, parsedItemsKeyedByFeedId: testItems) @@ -104,7 +104,7 @@ class FeedlyUpdateAccountFeedsWithItemsOperationTests: XCTestCase { let articleIds = Set(entries.compactMap { $0.syncServiceID }) XCTAssertEqual(articleIds.count, entries.count, "Not every item has a value for \(\ParsedItem.syncServiceID).") - let accountArticles = account.fetchArticles(.articleIDs(articleIds)) + let accountArticles = try account.fetchArticles(.articleIDs(articleIds)) XCTAssertTrue(accountArticles.count == entries.count) let accountArticleIds = Set(accountArticles.map { $0.articleID }) @@ -112,7 +112,7 @@ class FeedlyUpdateAccountFeedsWithItemsOperationTests: XCTestCase { XCTAssertTrue(missingIds.isEmpty) } - func testCancelUpdateAccount() { + func testCancelUpdateAccount() throws { let testItems = support.makeParsedItemTestDataFor(numberOfFeeds: 1, numberOfItemsInFeeds: 1) let resource = FeedlyCategoryResourceId(id: "user/12345/category/6789") let provider = TestItemsByFeedProvider(providerName: resource.id, parsedItemsKeyedByFeedId: testItems) @@ -134,7 +134,7 @@ class FeedlyUpdateAccountFeedsWithItemsOperationTests: XCTestCase { let articleIds = Set(entries.compactMap { $0.syncServiceID }) XCTAssertEqual(articleIds.count, entries.count, "Not every item has a value for \(\ParsedItem.syncServiceID).") - let accountArticles = account.fetchArticles(.articleIDs(articleIds)) + let accountArticles = try account.fetchArticles(.articleIDs(articleIds)) XCTAssertTrue(accountArticles.isEmpty) } } From 6583688e38712e06172fe085e00e975b03454e36 Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Tue, 31 Dec 2019 19:06:10 -0600 Subject: [PATCH 03/12] Fix errors in Feedly unread operations tests Most fetch completion blocks took a parameter that was expected to be some result data type, but is now a Result. Rename these parameters; wrap their existing bodies in do/catch blocks; and recreate the original underlying variable using the result of `Result.get()`. Prepend a few synchronous calls that started throwing with `try` along the way. --- ...eedlySetUnreadArticlesOperationTests.swift | 184 +++++++++++------- 1 file changed, 117 insertions(+), 67 deletions(-) diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlySetUnreadArticlesOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlySetUnreadArticlesOperationTests.swift index e7e936e85..04ebb191d 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlySetUnreadArticlesOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlySetUnreadArticlesOperationTests.swift @@ -49,10 +49,15 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetched Articles Ids") - account.fetchUnreadArticleIDs { accountArticlesIDs in - XCTAssertTrue(accountArticlesIDs.isEmpty) - XCTAssertEqual(accountArticlesIDs.count, testIds.count) - fetchIdsExpectation.fulfill() + account.fetchUnreadArticleIDs { accountArticlesIDsResult in + do { + let accountArticlesIDs = try accountArticlesIDsResult.get() + XCTAssertTrue(accountArticlesIDs.isEmpty) + XCTAssertEqual(accountArticlesIDs.count, testIds.count) + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking account articles IDs result: \(e)") + } } waitForExpectations(timeout: 2) @@ -74,9 +79,14 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetched Articles Ids") - account.fetchUnreadArticleIDs { accountArticlesIDs in - XCTAssertEqual(accountArticlesIDs.count, testIds.count) - fetchIdsExpectation.fulfill() + account.fetchUnreadArticleIDs { accountArticlesIDsResult in + do { + let accountArticlesIDs = try accountArticlesIDsResult.get() + XCTAssertEqual(accountArticlesIDs.count, testIds.count) + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking account articles IDs result: \(e)") + } } waitForExpectations(timeout: 2) } @@ -97,9 +107,14 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetched Articles Ids") - account.fetchUnreadArticleIDs { accountArticlesIDs in - XCTAssertEqual(accountArticlesIDs.count, testIds.count) - fetchIdsExpectation.fulfill() + account.fetchUnreadArticleIDs { accountArticlesIDsResult in + do { + let accountArticlesIDs = try accountArticlesIDsResult.get() + XCTAssertEqual(accountArticlesIDs.count, testIds.count) + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking account articles IDs result: \(e)") + } } waitForExpectations(timeout: 2) } @@ -135,9 +150,14 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetched Articles Ids") - account.fetchUnreadArticleIDs { remainingAccountArticlesIDs in - XCTAssertEqual(remainingAccountArticlesIDs, remainingUnreadIds) - fetchIdsExpectation.fulfill() + account.fetchUnreadArticleIDs { remainingAccountArticlesIDsResult in + do { + let remainingAccountArticlesIDs = try remainingAccountArticlesIDsResult.get() + XCTAssertEqual(remainingAccountArticlesIDs, remainingUnreadIds) + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking account articles IDs result: \(e)") + } } waitForExpectations(timeout: 2) } @@ -173,9 +193,14 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetched Articles Ids") - account.fetchUnreadArticleIDs { remainingAccountArticlesIDs in - XCTAssertEqual(remainingAccountArticlesIDs, remainingUnreadIds) - fetchIdsExpectation.fulfill() + account.fetchUnreadArticleIDs { remainingAccountArticlesIDsResult in + do { + let remainingAccountArticlesIDs = try remainingAccountArticlesIDsResult.get() + XCTAssertEqual(remainingAccountArticlesIDs, remainingUnreadIds) + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking account articles IDs result: \(e)") + } } waitForExpectations(timeout: 2) } @@ -222,15 +247,20 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetched Articles Ids") - account.fetchUnreadArticleIDs { accountArticlesIDs in - XCTAssertEqual(accountArticlesIDs, remainingUnreadIds) - let idsOfUnreadArticles = Set(self.account - .fetchArticles(.articleIDs(remainingUnreadIds)) - .filter { $0.status.boolStatus(forKey: .read) == false } - .map { $0.articleID }) - - XCTAssertEqual(idsOfUnreadArticles, remainingUnreadIds) - fetchIdsExpectation.fulfill() + account.fetchUnreadArticleIDs { accountArticlesIDsResult in + do { + let accountArticlesIDs = try accountArticlesIDsResult.get() + XCTAssertEqual(accountArticlesIDs, remainingUnreadIds) + let idsOfUnreadArticles = Set(try self.account + .fetchArticles(.articleIDs(remainingUnreadIds)) + .filter { $0.status.boolStatus(forKey: .read) == false } + .map { $0.articleID }) + + XCTAssertEqual(idsOfUnreadArticles, remainingUnreadIds) + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking account articles IDs result: \(e)") + } } waitForExpectations(timeout: 2) } @@ -275,16 +305,21 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetched Articles Ids") - account.fetchUnreadArticleIDs { accountArticlesIDs in - XCTAssertEqual(accountArticlesIDs, remainingUnreadIds) - - let idsOfUnreadArticles = Set(self.account - .fetchArticles(.articleIDs(remainingUnreadIds)) - .filter { $0.status.boolStatus(forKey: .read) == false } - .map { $0.articleID }) - - XCTAssertEqual(idsOfUnreadArticles, remainingUnreadIds) - fetchIdsExpectation.fulfill() + account.fetchUnreadArticleIDs { accountArticlesIDsResult in + do { + let accountArticlesIDs = try accountArticlesIDsResult.get() + XCTAssertEqual(accountArticlesIDs, remainingUnreadIds) + + let idsOfUnreadArticles = Set(try self.account + .fetchArticles(.articleIDs(remainingUnreadIds)) + .filter { $0.status.boolStatus(forKey: .read) == false } + .map { $0.articleID }) + + XCTAssertEqual(idsOfUnreadArticles, remainingUnreadIds) + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking account articles IDs result: \(e)") + } } } @@ -322,16 +357,21 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetched Articles Ids") - account.fetchUnreadArticleIDs { accountArticlesIDs in - XCTAssertEqual(accountArticlesIDs, remainingUnreadIds) - - let idsOfUnreadArticles = Set(self.account - .fetchArticles(.articleIDs(remainingUnreadIds)) - .filter { $0.status.boolStatus(forKey: .read) == false } - .map { $0.articleID }) - - XCTAssertEqual(idsOfUnreadArticles, remainingUnreadIds) - fetchIdsExpectation.fulfill() + account.fetchUnreadArticleIDs { accountArticlesIDsResult in + do { + let accountArticlesIDs = try accountArticlesIDsResult.get() + XCTAssertEqual(accountArticlesIDs, remainingUnreadIds) + + let idsOfUnreadArticles = Set(try self.account + .fetchArticles(.articleIDs(remainingUnreadIds)) + .filter { $0.status.boolStatus(forKey: .read) == false } + .map { $0.articleID }) + + XCTAssertEqual(idsOfUnreadArticles, remainingUnreadIds) + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking account articles IDs result: \(e)") + } } waitForExpectations(timeout: 2) } @@ -369,16 +409,21 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetched Articles Ids") - account.fetchUnreadArticleIDs { accountArticlesIDs in - XCTAssertEqual(accountArticlesIDs, remainingUnreadIds) - - let idsOfUnreadArticles = Set(self.account - .fetchArticles(.articleIDs(remainingUnreadIds)) - .filter { $0.status.boolStatus(forKey: .read) == false } - .map { $0.articleID }) - - XCTAssertEqual(idsOfUnreadArticles, remainingUnreadIds) - fetchIdsExpectation.fulfill() + account.fetchUnreadArticleIDs { accountArticlesIDsResult in + do { + let accountArticlesIDs = try accountArticlesIDsResult.get() + XCTAssertEqual(accountArticlesIDs, remainingUnreadIds) + + let idsOfUnreadArticles = Set(try self.account + .fetchArticles(.articleIDs(remainingUnreadIds)) + .filter { $0.status.boolStatus(forKey: .read) == false } + .map { $0.articleID }) + + XCTAssertEqual(idsOfUnreadArticles, remainingUnreadIds) + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking account articles IDs result: \(e)") + } } } @@ -418,18 +463,23 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetched Articles Ids") - account.fetchUnreadArticleIDs { accountArticlesIDs in - XCTAssertEqual(accountArticlesIDs, remainingUnreadIds) - - let someTestItems = Set(someItemsAndFeeds.flatMap { $0.value }) - let someRemainingUnreadIdsOfIngestedArticles = Set(someTestItems.compactMap { $0.syncServiceID }) - let idsOfUnreadArticles = Set(self.account - .fetchArticles(.articleIDs(someRemainingUnreadIdsOfIngestedArticles)) - .filter { $0.status.boolStatus(forKey: .read) == false } - .map { $0.articleID }) - - XCTAssertEqual(idsOfUnreadArticles, someRemainingUnreadIdsOfIngestedArticles) - fetchIdsExpectation.fulfill() + account.fetchUnreadArticleIDs { accountArticlesIDsResult in + do { + let accountArticlesIDs = try accountArticlesIDsResult.get() + XCTAssertEqual(accountArticlesIDs, remainingUnreadIds) + + let someTestItems = Set(someItemsAndFeeds.flatMap { $0.value }) + let someRemainingUnreadIdsOfIngestedArticles = Set(someTestItems.compactMap { $0.syncServiceID }) + let idsOfUnreadArticles = Set(try self.account + .fetchArticles(.articleIDs(someRemainingUnreadIdsOfIngestedArticles)) + .filter { $0.status.boolStatus(forKey: .read) == false } + .map { $0.articleID }) + + XCTAssertEqual(idsOfUnreadArticles, someRemainingUnreadIdsOfIngestedArticles) + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking account articles IDs result: \(e)") + } } } } From 6a4f3fb11e672ecae4eb7f30f1bb33542cafa656 Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Tue, 31 Dec 2019 19:08:29 -0600 Subject: [PATCH 04/12] Fix build errors in sync stream operations tests Prefix two throwing calls with `try`. Label the enclosing test functions with `throws` so the XCTest machinery helps us with error reporting. --- .../Feedly/FeedlySyncStreamContentsOperationTests.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlySyncStreamContentsOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlySyncStreamContentsOperationTests.swift index 52d03bef4..6a3f83d91 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlySyncStreamContentsOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlySyncStreamContentsOperationTests.swift @@ -26,7 +26,7 @@ class FeedlySyncStreamContentsOperationTests: XCTestCase { super.tearDown() } - func testIngestsOnePageSuccess() { + func testIngestsOnePageSuccess() throws { let service = TestGetStreamContentsService() let resource = FeedlyCategoryResourceId(id: "user/1234/category/5678") let newerThan: Date? = Date(timeIntervalSinceReferenceDate: 0) @@ -56,7 +56,7 @@ class FeedlySyncStreamContentsOperationTests: XCTestCase { waitForExpectations(timeout: 2) let expectedArticleIds = Set(items.map { $0.id }) - let expectedArticles = account.fetchArticles(.articleIDs(expectedArticleIds)) + let expectedArticles = try account.fetchArticles(.articleIDs(expectedArticleIds)) XCTAssertEqual(expectedArticles.count, expectedArticleIds.count, "Did not fetch all the articles.") } @@ -90,7 +90,7 @@ class FeedlySyncStreamContentsOperationTests: XCTestCase { waitForExpectations(timeout: 2) } - func testIngestsManyPagesSuccess() { + func testIngestsManyPagesSuccess() throws { let service = TestGetPagedStreamContentsService() let resource = FeedlyCategoryResourceId(id: "user/1234/category/5678") let newerThan: Date? = Date(timeIntervalSinceReferenceDate: 0) @@ -132,7 +132,7 @@ class FeedlySyncStreamContentsOperationTests: XCTestCase { // Find articles inserted. let articleIds = Set(service.pages.values.map { $0.items }.flatMap { $0 }.map { $0.id }) - let articles = account.fetchArticles(.articleIDs(articleIds)) + let articles = try account.fetchArticles(.articleIDs(articleIds)) XCTAssertEqual(articleIds.count, articles.count) } } From f12e8b4a4ab60f7bda4bf2765a59b0ab6bef317d Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Tue, 31 Dec 2019 19:11:37 -0600 Subject: [PATCH 05/12] Fix errors in starred articles operations tests Pull the same do/catch/Result.get() trick as previously for completion blocks which now take Results. `try` a few throwing calls. --- ...dlySyncStarredArticlesOperationTests.swift | 81 +++++++++++-------- 1 file changed, 48 insertions(+), 33 deletions(-) diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlySyncStarredArticlesOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlySyncStarredArticlesOperationTests.swift index 761dd8a01..cbefa2515 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlySyncStarredArticlesOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlySyncStarredArticlesOperationTests.swift @@ -56,21 +56,26 @@ class FeedlySyncStarredArticlesOperationTests: XCTestCase { let expectedArticleIds = Set(items.map { $0.id }) let fetchIdsExpectation = expectation(description: "Fetch Article Ids") - account.fetchStarredArticleIDs { starredArticleIds in - let missingIds = expectedArticleIds.subtracting(starredArticleIds) - XCTAssertTrue(missingIds.isEmpty, "These article ids were not marked as starred.") - - // Fetch articles directly because account.fetchArticles(.starred) fetches starred articles for feeds subscribed to. - let expectedArticles = self.account.fetchArticles(.articleIDs(expectedArticleIds)) - XCTAssertEqual(expectedArticles.count, expectedArticleIds.count, "Did not fetch all the articles.") - - let starredArticles = self.account.fetchArticles(.articleIDs(starredArticleIds)) - XCTAssertEqual(expectedArticleIds.count, expectedArticles.count) - let missingArticles = expectedArticles.subtracting(starredArticles) - XCTAssertTrue(missingArticles.isEmpty, "These articles should be starred and fetched.") - XCTAssertEqual(expectedArticles, starredArticles) - - fetchIdsExpectation.fulfill() + account.fetchStarredArticleIDs { starredArticleIdsResult in + do { + let starredArticleIds = try starredArticleIdsResult.get() + let missingIds = expectedArticleIds.subtracting(starredArticleIds) + XCTAssertTrue(missingIds.isEmpty, "These article ids were not marked as starred.") + + // Fetch articles directly because account.fetchArticles(.starred) fetches starred articles for feeds subscribed to. + let expectedArticles = try self.account.fetchArticles(.articleIDs(expectedArticleIds)) + XCTAssertEqual(expectedArticles.count, expectedArticleIds.count, "Did not fetch all the articles.") + + let starredArticles = try self.account.fetchArticles(.articleIDs(starredArticleIds)) + XCTAssertEqual(expectedArticleIds.count, expectedArticles.count) + let missingArticles = expectedArticles.subtracting(starredArticles) + XCTAssertTrue(missingArticles.isEmpty, "These articles should be starred and fetched.") + XCTAssertEqual(expectedArticles, starredArticles) + + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking starred article IDs: \(e)") + } } waitForExpectations(timeout: 2) } @@ -104,9 +109,14 @@ class FeedlySyncStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetch Article Ids") - account.fetchStarredArticleIDs { starredArticleIds in - XCTAssertTrue(starredArticleIds.isEmpty) - fetchIdsExpectation.fulfill() + account.fetchStarredArticleIDs { starredArticleIdsResult in + do { + let starredArticleIds = try starredArticleIdsResult.get() + XCTAssertTrue(starredArticleIds.isEmpty) + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking starred article IDs: \(e)") + } } waitForExpectations(timeout: 2) } @@ -153,21 +163,26 @@ class FeedlySyncStarredArticlesOperationTests: XCTestCase { // Find articles inserted. let expectedArticleIds = Set(service.pages.values.map { $0.items }.flatMap { $0 }.map { $0.id }) let fetchIdsExpectation = expectation(description: "Fetch Article Ids") - account.fetchStarredArticleIDs { starredArticleIds in - let missingIds = expectedArticleIds.subtracting(starredArticleIds) - XCTAssertTrue(missingIds.isEmpty, "These article ids were not marked as starred.") - - // Fetch articles directly because account.fetchArticles(.starred) fetches starred articles for feeds subscribed to. - let expectedArticles = self.account.fetchArticles(.articleIDs(expectedArticleIds)) - XCTAssertEqual(expectedArticles.count, expectedArticleIds.count, "Did not fetch all the articles.") - - let starredArticles = self.account.fetchArticles(.articleIDs(starredArticleIds)) - XCTAssertEqual(expectedArticleIds.count, expectedArticles.count) - let missingArticles = expectedArticles.subtracting(starredArticles) - XCTAssertTrue(missingArticles.isEmpty, "These articles should be starred and fetched.") - XCTAssertEqual(expectedArticles, starredArticles) - - fetchIdsExpectation.fulfill() + account.fetchStarredArticleIDs { starredArticleIdsResult in + do { + let starredArticleIds = try starredArticleIdsResult.get() + let missingIds = expectedArticleIds.subtracting(starredArticleIds) + XCTAssertTrue(missingIds.isEmpty, "These article ids were not marked as starred.") + + // Fetch articles directly because account.fetchArticles(.starred) fetches starred articles for feeds subscribed to. + let expectedArticles = try self.account.fetchArticles(.articleIDs(expectedArticleIds)) + XCTAssertEqual(expectedArticles.count, expectedArticleIds.count, "Did not fetch all the articles.") + + let starredArticles = try self.account.fetchArticles(.articleIDs(starredArticleIds)) + XCTAssertEqual(expectedArticleIds.count, expectedArticles.count) + let missingArticles = expectedArticles.subtracting(starredArticles) + XCTAssertTrue(missingArticles.isEmpty, "These articles should be starred and fetched.") + XCTAssertEqual(expectedArticles, starredArticles) + + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking starred article IDs: \(e)") + } } waitForExpectations(timeout: 2) } From 13b227a461efa3e6d1af299c361df875645caaf3 Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Tue, 31 Dec 2019 19:23:12 -0600 Subject: [PATCH 06/12] Fix errors in Feedly set starred operations tests More of the same: completion blocks which take Results need do/catch/Result.get(). --- ...edlySetStarredArticlesOperationTests.swift | 184 +++++++++++------- 1 file changed, 117 insertions(+), 67 deletions(-) diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlySetStarredArticlesOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlySetStarredArticlesOperationTests.swift index e86ba2de3..28e376cda 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlySetStarredArticlesOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlySetStarredArticlesOperationTests.swift @@ -49,10 +49,15 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetch Article Ids") - account.fetchStarredArticleIDs { accountArticlesIDs in - XCTAssertTrue(accountArticlesIDs.isEmpty) - XCTAssertEqual(accountArticlesIDs, testIds) - fetchIdsExpectation.fulfill() + account.fetchStarredArticleIDs { accountArticlesIDsResult in + do { + let accountArticlesIDs = try accountArticlesIDsResult.get() + XCTAssertTrue(accountArticlesIDs.isEmpty) + XCTAssertEqual(accountArticlesIDs, testIds) + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking articles IDs: \(e)") + } } waitForExpectations(timeout: 2) } @@ -73,9 +78,14 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetch Article Ids") - account.fetchStarredArticleIDs { accountArticlesIDs in - XCTAssertEqual(accountArticlesIDs.count, testIds.count) - fetchIdsExpectation.fulfill() + account.fetchStarredArticleIDs { accountArticlesIDsResult in + do { + let accountArticlesIDs = try accountArticlesIDsResult.get() + XCTAssertEqual(accountArticlesIDs.count, testIds.count) + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking articles IDs: \(e)") + } } waitForExpectations(timeout: 2) } @@ -96,9 +106,14 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetch Article Ids") - account.fetchStarredArticleIDs { accountArticlesIDs in - XCTAssertEqual(accountArticlesIDs.count, testIds.count) - fetchIdsExpectation.fulfill() + account.fetchStarredArticleIDs { accountArticlesIDsResult in + do { + let accountArticlesIDs = try accountArticlesIDsResult.get() + XCTAssertEqual(accountArticlesIDs.count, testIds.count) + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking articles IDs: \(e)") + } } waitForExpectations(timeout: 2) } @@ -134,9 +149,14 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetch Article Ids") - account.fetchStarredArticleIDs { remainingAccountArticlesIDs in - XCTAssertEqual(remainingAccountArticlesIDs, remainingStarredIds) - fetchIdsExpectation.fulfill() + account.fetchStarredArticleIDs { remainingAccountArticlesIDsResult in + do { + let remainingAccountArticlesIDs = try remainingAccountArticlesIDsResult.get() + XCTAssertEqual(remainingAccountArticlesIDs, remainingStarredIds) + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking articles IDs: \(e)") + } } waitForExpectations(timeout: 2) } @@ -172,9 +192,14 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetch Article Ids") - account.fetchStarredArticleIDs { remainingAccountArticlesIDs in - XCTAssertEqual(remainingAccountArticlesIDs, remainingStarredIds) - fetchIdsExpectation.fulfill() + account.fetchStarredArticleIDs { remainingAccountArticlesIDsResult in + do { + let remainingAccountArticlesIDs = try remainingAccountArticlesIDsResult.get() + XCTAssertEqual(remainingAccountArticlesIDs, remainingStarredIds) + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking articles IDs: \(e)") + } } waitForExpectations(timeout: 2) } @@ -221,15 +246,20 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetch Article Ids") - account.fetchStarredArticleIDs { accountArticlesIDs in - XCTAssertEqual(accountArticlesIDs, remainingStarredIds) - - let idsOfStarredArticles = Set(self.account - .fetchArticles(.articleIDs(remainingStarredIds)) - .filter { $0.status.boolStatus(forKey: .starred) == true } - .map { $0.articleID }) - - XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) + account.fetchStarredArticleIDs { accountArticlesIDsResult in + do { + let accountArticlesIDs = try accountArticlesIDsResult.get() + XCTAssertEqual(accountArticlesIDs, remainingStarredIds) + + let idsOfStarredArticles = Set(try self.account + .fetchArticles(.articleIDs(remainingStarredIds)) + .filter { $0.status.boolStatus(forKey: .starred) == true } + .map { $0.articleID }) + + XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) + } catch let e { + XCTFail("Error checking articles IDs: \(e)") + } } waitForExpectations(timeout: 2) } @@ -274,15 +304,20 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetch Article Ids") - account.fetchStarredArticleIDs { accountArticlesIDs in - XCTAssertEqual(accountArticlesIDs, remainingStarredIds) - - let idsOfStarredArticles = Set(self.account - .fetchArticles(.articleIDs(remainingStarredIds)) - .filter { $0.status.boolStatus(forKey: .starred) == true } - .map { $0.articleID }) - - XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) + account.fetchStarredArticleIDs { accountArticlesIDsResult in + do { + let accountArticlesIDs = try accountArticlesIDsResult.get() + XCTAssertEqual(accountArticlesIDs, remainingStarredIds) + + let idsOfStarredArticles = Set(try self.account + .fetchArticles(.articleIDs(remainingStarredIds)) + .filter { $0.status.boolStatus(forKey: .starred) == true } + .map { $0.articleID }) + + XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) + } catch let e { + XCTFail("Error checking articles IDs: \(e)") + } } waitForExpectations(timeout: 2) } @@ -321,16 +356,21 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetch Article Ids") - account.fetchStarredArticleIDs { accountArticlesIDs in - XCTAssertEqual(accountArticlesIDs, remainingStarredIds) - - let idsOfStarredArticles = Set(self.account - .fetchArticles(.articleIDs(remainingStarredIds)) - .filter { $0.status.boolStatus(forKey: .starred) == true } - .map { $0.articleID }) - - XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) - fetchIdsExpectation.fulfill() + account.fetchStarredArticleIDs { accountArticlesIDsResult in + do { + let accountArticlesIDs = try accountArticlesIDsResult.get() + XCTAssertEqual(accountArticlesIDs, remainingStarredIds) + + let idsOfStarredArticles = Set(try self.account + .fetchArticles(.articleIDs(remainingStarredIds)) + .filter { $0.status.boolStatus(forKey: .starred) == true } + .map { $0.articleID }) + + XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking articles IDs: \(e)") + } } waitForExpectations(timeout: 2) } @@ -368,16 +408,21 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetch Article Ids") - account.fetchStarredArticleIDs { accountArticlesIDs in - XCTAssertEqual(accountArticlesIDs, remainingStarredIds) - - let idsOfStarredArticles = Set(self.account - .fetchArticles(.articleIDs(remainingStarredIds)) - .filter { $0.status.boolStatus(forKey: .starred) == true } - .map { $0.articleID }) - - XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) - fetchIdsExpectation.fulfill() + account.fetchStarredArticleIDs { accountArticlesIDsResult in + do { + let accountArticlesIDs = try accountArticlesIDsResult.get() + XCTAssertEqual(accountArticlesIDs, remainingStarredIds) + + let idsOfStarredArticles = Set(try self.account + .fetchArticles(.articleIDs(remainingStarredIds)) + .filter { $0.status.boolStatus(forKey: .starred) == true } + .map { $0.articleID }) + + XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking articles IDs: \(e)") + } } waitForExpectations(timeout: 2) } @@ -418,19 +463,24 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetch Article Ids") - account.fetchStarredArticleIDs { accountArticlesIDs in - XCTAssertEqual(accountArticlesIDs, remainingStarredIds) - - let someTestItems = Set(someItemsAndFeeds.flatMap { $0.value }) - let someRemainingStarredIdsOfIngestedArticles = Set(someTestItems.compactMap { $0.syncServiceID }) - let idsOfStarredArticles = Set(self.account - .fetchArticles(.articleIDs(someRemainingStarredIdsOfIngestedArticles)) - .filter { $0.status.boolStatus(forKey: .starred) == true } - .map { $0.articleID }) - - XCTAssertEqual(idsOfStarredArticles, someRemainingStarredIdsOfIngestedArticles) - - fetchIdsExpectation.fulfill() + account.fetchStarredArticleIDs { accountArticlesIDsResult in + do { + let accountArticlesIDs = try accountArticlesIDsResult.get() + XCTAssertEqual(accountArticlesIDs, remainingStarredIds) + + let someTestItems = Set(someItemsAndFeeds.flatMap { $0.value }) + let someRemainingStarredIdsOfIngestedArticles = Set(someTestItems.compactMap { $0.syncServiceID }) + let idsOfStarredArticles = Set(try self.account + .fetchArticles(.articleIDs(someRemainingStarredIdsOfIngestedArticles)) + .filter { $0.status.boolStatus(forKey: .starred) == true } + .map { $0.articleID }) + + XCTAssertEqual(idsOfStarredArticles, someRemainingStarredIdsOfIngestedArticles) + + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking articles IDs: \(e)") + } } waitForExpectations(timeout: 2) } From 152b1f2b8a5d95ab33cc12b9159ff267542bfd87 Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Tue, 31 Dec 2019 19:27:47 -0600 Subject: [PATCH 07/12] Fix errors in Feedly sync unread operations tests Yet more completion blocks with Results; apply the usual do/catch/Result.get() dance. --- ...edlySyncUnreadStatusesOperationTests.swift | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlySyncUnreadStatusesOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlySyncUnreadStatusesOperationTests.swift index fa4864a73..67b9dd4e9 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlySyncUnreadStatusesOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlySyncUnreadStatusesOperationTests.swift @@ -56,10 +56,15 @@ class FeedlySyncUnreadStatusesOperationTests: XCTestCase { let expectedArticleIds = Set(ids) let fetchIdsExpectation = expectation(description: "Fetch Article Ids") - account.fetchUnreadArticleIDs { unreadArticleIds in - let missingIds = expectedArticleIds.subtracting(unreadArticleIds) - XCTAssertTrue(missingIds.isEmpty, "These article ids were not marked as unread.") - fetchIdsExpectation.fulfill() + account.fetchUnreadArticleIDs { unreadArticleIdsResult in + do { + let unreadArticleIds = try unreadArticleIdsResult.get() + let missingIds = expectedArticleIds.subtracting(unreadArticleIds) + XCTAssertTrue(missingIds.isEmpty, "These article ids were not marked as unread.") + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking unread article IDs: \(e)") + } } waitForExpectations(timeout: 2) } @@ -93,9 +98,14 @@ class FeedlySyncUnreadStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let fetchIdsExpectation = expectation(description: "Fetch Article Ids") - account.fetchUnreadArticleIDs { unreadArticleIds in - XCTAssertTrue(unreadArticleIds.isEmpty) - fetchIdsExpectation.fulfill() + account.fetchUnreadArticleIDs { unreadArticleIdsResult in + do { + let unreadArticleIds = try unreadArticleIdsResult.get() + XCTAssertTrue(unreadArticleIds.isEmpty) + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking unread article IDs: \(e)") + } } waitForExpectations(timeout: 2) } @@ -142,10 +152,15 @@ class FeedlySyncUnreadStatusesOperationTests: XCTestCase { // Find statuses inserted. let expectedArticleIds = Set(service.pages.values.map { $0.ids }.flatMap { $0 }) let fetchIdsExpectation = expectation(description: "Fetch Article Ids") - account.fetchUnreadArticleIDs { unreadArticleIds in - let missingIds = expectedArticleIds.subtracting(unreadArticleIds) - XCTAssertTrue(missingIds.isEmpty, "These article ids were not marked as unread.") - fetchIdsExpectation.fulfill() + account.fetchUnreadArticleIDs { unreadArticleIdsResult in + do { + let unreadArticleIds = try unreadArticleIdsResult.get() + let missingIds = expectedArticleIds.subtracting(unreadArticleIds) + XCTAssertTrue(missingIds.isEmpty, "These article ids were not marked as unread.") + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error checking unread article IDs: \(e)") + } } waitForExpectations(timeout: 2) } From 711aca3d1b9ba9df5e1effddef8204a9c070bdb8 Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Tue, 31 Dec 2019 19:29:44 -0600 Subject: [PATCH 08/12] Fix build errors in Feedly test support Two more cases of completion blocks taking Results, requiring a do/catch/Result.get() to unwrap. This commit deliberately leaves one build error for a more comprehensive fix, since it occurs in a helper function that will have broader fallout. --- .../Feedly/FeedlyTestSupport.swift | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlyTestSupport.swift b/Frameworks/Account/AccountTests/Feedly/FeedlyTestSupport.swift index 3e5ae30ff..fb52eb781 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlyTestSupport.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlyTestSupport.swift @@ -220,12 +220,17 @@ class FeedlyTestSupport { func checkUnreadStatuses(in testAccount: Account, correspondToIdsInJSONPayload streamIds: [String: Any], testCase: XCTestCase) { let ids = Set(streamIds["ids"] as! [String]) let fetchIdsExpectation = testCase.expectation(description: "Fetch Article Ids") - testAccount.fetchUnreadArticleIDs { articleIds in - // Unread statuses can be paged from Feedly. - // Instead of joining test data, the best we can do is - // make sure that these ids are marked as unread (a subset of the total). - XCTAssertTrue(ids.isSubset(of: articleIds), "Some articles in `ids` are not marked as unread.") - fetchIdsExpectation.fulfill() + testAccount.fetchUnreadArticleIDs { articleIdsResult in + do { + let articleIds = try articleIdsResult.get() + // Unread statuses can be paged from Feedly. + // Instead of joining test data, the best we can do is + // make sure that these ids are marked as unread (a subset of the total). + XCTAssertTrue(ids.isSubset(of: articleIds), "Some articles in `ids` are not marked as unread.") + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error unwrapping article IDs: \(e)") + } } testCase.wait(for: [fetchIdsExpectation], timeout: 2) } @@ -239,12 +244,17 @@ class FeedlyTestSupport { let items = stream["items"] as! [[String: Any]] let ids = Set(items.map { $0["id"] as! String }) let fetchIdsExpectation = testCase.expectation(description: "Fetch Article Ids") - testAccount.fetchStarredArticleIDs { articleIds in - // Starred articles can be paged from Feedly. - // Instead of joining test data, the best we can do is - // make sure that these articles are marked as starred (a subset of the total). - XCTAssertTrue(ids.isSubset(of: articleIds), "Some articles in `ids` are not marked as starred.") - fetchIdsExpectation.fulfill() + testAccount.fetchStarredArticleIDs { articleIdsResult in + do { + let articleIds = try articleIdsResult.get() + // Starred articles can be paged from Feedly. + // Instead of joining test data, the best we can do is + // make sure that these articles are marked as starred (a subset of the total). + XCTAssertTrue(ids.isSubset(of: articleIds), "Some articles in `ids` are not marked as starred.") + fetchIdsExpectation.fulfill() + } catch let e { + XCTFail("Error unwrapping article IDs: \(e)") + } } testCase.wait(for: [fetchIdsExpectation], timeout: 2) } From 6c10774c4a317560157b8bf6b1ef48024f5b986e Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Tue, 31 Dec 2019 19:36:42 -0600 Subject: [PATCH 09/12] Fix build errors stemming from FeedlyTestSupport MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There was one call to a throwing function inside `checkArticles(in:correspondToStreamItemsIn:)` which was not appropriately marked with `try`. Add that keyword, and then bubble out the chain of errors through additional layers of helpers to the enclosing test: * This `checkArticles` variant was called by two others * …one of which was used in `testAddNewFeedSuccess()` * …another of which was used in various `verify` sync helpers * …which were referenced from `testSyncing()`, a test case method None of these involved any particular async hoops to jump through, and since the top-level callers were all test functions, we can count on XCTest to handle any errors thrown — no additional `catch` or handling on our part is necessary. --- .../FeedlyAddNewFeedOperationTests.swift | 4 +- .../Feedly/FeedlySyncAllOperationTests.swift | 42 +++++++++---------- .../Feedly/FeedlyTestSupport.swift | 12 +++--- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlyAddNewFeedOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlyAddNewFeedOperationTests.swift index c218e8f07..396cc8783 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlyAddNewFeedOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlyAddNewFeedOperationTests.swift @@ -120,7 +120,7 @@ class FeedlyAddNewFeedOperationTests: XCTestCase { XCTAssert(progress.isComplete) } - func testAddNewFeedSuccess() { + func testAddNewFeedSuccess() throws { guard let folder = getFolderByLoadingInitialContent() else { return } @@ -163,7 +163,7 @@ class FeedlyAddNewFeedOperationTests: XCTestCase { XCTAssert(progress.isComplete) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "feedStream", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "feedStream", subdirectory: subdirectory) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds", subdirectory: subdirectory, testCase: self) } diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlySyncAllOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlySyncAllOperationTests.swift index 914c25e8a..403250314 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlySyncAllOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlySyncAllOperationTests.swift @@ -114,18 +114,18 @@ class FeedlySyncAllOperationTests: XCTestCase { return caller }() - func testSyncing() { + func testSyncing() throws { performInitialSync() - verifyInitialSync() + try verifyInitialSync() performChangeStatuses() - verifyChangeStatuses() + try verifyChangeStatuses() performChangeStatusesAgain() - verifyChangeStatusesAgain() + try verifyChangeStatusesAgain() performAddFeedsAndFolders() - verifyAddFeedsAndFolders() + try verifyAddFeedsAndFolders() } // MARK: 1 - Initial Sync @@ -166,15 +166,15 @@ class FeedlySyncAllOperationTests: XCTestCase { loadMockData(inSubdirectoryNamed: "feedly-1-initial") } - func verifyInitialSync() { + func verifyInitialSync() throws { let subdirectory = "feedly-1-initial" support.checkFoldersAndFeeds(in: account, againstCollectionsAndFeedsInJSONNamed: "collections", subdirectory: subdirectory) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all@MTZkOTdkZWQ1NzM6NTE2OjUzYjgyNmEy", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all@MTZkOTdkZWQ1NzM6NTE2OjUzYjgyNmEy", subdirectory: subdirectory) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds", subdirectory: subdirectory, testCase: self) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds@MTZkOTRhOTNhZTQ6MzExOjUzYjgyNmEy", subdirectory: subdirectory, testCase: self) support.checkStarredStatuses(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory, testCase: self) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory) } // MARK: 2 - Change Statuses @@ -183,14 +183,14 @@ class FeedlySyncAllOperationTests: XCTestCase { loadMockData(inSubdirectoryNamed: "feedly-2-changestatuses") } - func verifyChangeStatuses() { + func verifyChangeStatuses() throws { let subdirectory = "feedly-2-changestatuses" support.checkFoldersAndFeeds(in: account, againstCollectionsAndFeedsInJSONNamed: "collections", subdirectory: subdirectory) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds", subdirectory: subdirectory, testCase: self) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds@MTZkOTJkNjIwM2Q6MTEzYjpkNDUwNjA3MQ==", subdirectory: subdirectory, testCase: self) support.checkStarredStatuses(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory, testCase: self) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory) } // MARK: 3 - Change Statuses Again @@ -199,14 +199,14 @@ class FeedlySyncAllOperationTests: XCTestCase { loadMockData(inSubdirectoryNamed: "feedly-3-changestatusesagain") } - func verifyChangeStatusesAgain() { + func verifyChangeStatusesAgain() throws { let subdirectory = "feedly-3-changestatusesagain" support.checkFoldersAndFeeds(in: account, againstCollectionsAndFeedsInJSONNamed: "collections", subdirectory: subdirectory) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds", subdirectory: subdirectory, testCase: self) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds@MTZkOGRlMjVmM2M6M2YyOmQ0NTA2MDcx", subdirectory: subdirectory, testCase: self) support.checkStarredStatuses(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory, testCase: self) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory) } // MARK: 4 - Add Feeds and Folders @@ -215,14 +215,14 @@ class FeedlySyncAllOperationTests: XCTestCase { loadMockData(inSubdirectoryNamed: "feedly-4-addfeedsandfolders") } - func verifyAddFeedsAndFolders() { + func verifyAddFeedsAndFolders() throws { let subdirectory = "feedly-4-addfeedsandfolders" support.checkFoldersAndFeeds(in: account, againstCollectionsAndFeedsInJSONNamed: "collections", subdirectory: subdirectory) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds", subdirectory: subdirectory, testCase: self) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds@MTZkOTE3YTRlMzQ6YWZjOmQ0NTA2MDcx", subdirectory: subdirectory, testCase: self) support.checkStarredStatuses(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory, testCase: self) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory) } // MARK: 5 - Remove Feeds and Folders @@ -231,14 +231,14 @@ class FeedlySyncAllOperationTests: XCTestCase { loadMockData(inSubdirectoryNamed: "feedly-5-removefeedsandfolders") } - func verifyRemoveFeedsAndFolders() { + func verifyRemoveFeedsAndFolders() throws { let subdirectory = "feedly-5-removefeedsandfolders" support.checkFoldersAndFeeds(in: account, againstCollectionsAndFeedsInJSONNamed: "collections", subdirectory: subdirectory) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds", subdirectory: subdirectory, testCase: self) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds@MTZkOGRlMjVmM2M6M2YxOmQ0NTA2MDcx", subdirectory: subdirectory, testCase: self) support.checkStarredStatuses(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory, testCase: self) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory) } // MARK: Downloading Test Data diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlyTestSupport.swift b/Frameworks/Account/AccountTests/Feedly/FeedlyTestSupport.swift index fb52eb781..4e3ef6d87 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlyTestSupport.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlyTestSupport.swift @@ -141,13 +141,13 @@ class FeedlyTestSupport { XCTAssertTrue(missingFeedIds.isEmpty, "Feeds with these ids were not found in the \"\(label)\" folder.") } - func checkArticles(in account: Account, againstItemsInStreamInJSONNamed name: String, subdirectory: String? = nil) { + func checkArticles(in account: Account, againstItemsInStreamInJSONNamed name: String, subdirectory: String? = nil) throws { let stream = testJSON(named: name, subdirectory: subdirectory) as! [String:Any] - checkArticles(in: account, againstItemsInStreamInJSONPayload: stream) + try checkArticles(in: account, againstItemsInStreamInJSONPayload: stream) } - func checkArticles(in account: Account, againstItemsInStreamInJSONPayload stream: [String: Any]) { - checkArticles(in: account, correspondToStreamItemsIn: stream) + func checkArticles(in account: Account, againstItemsInStreamInJSONPayload stream: [String: Any]) throws { + try checkArticles(in: account, correspondToStreamItemsIn: stream) } private struct ArticleItem { @@ -188,13 +188,13 @@ class FeedlyTestSupport { } /// Awkwardly titled to make it clear the JSON given is from a stream response. - func checkArticles(in testAccount: Account, correspondToStreamItemsIn stream: [String: Any]) { + func checkArticles(in testAccount: Account, correspondToStreamItemsIn stream: [String: Any]) throws { let items = stream["items"] as! [[String: Any]] let articleItems = items.map { ArticleItem(item: $0) } let itemIds = Set(articleItems.map { $0.id }) - let articles = testAccount.fetchArticles(.articleIDs(itemIds)) + let articles = try testAccount.fetchArticles(.articleIDs(itemIds)) let articleIds = Set(articles.map { $0.articleID }) let missing = itemIds.subtracting(articleIds) From e4c84bc5016b62209a225da8cff5d24d89a7ef8a Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Tue, 31 Dec 2019 19:41:32 -0600 Subject: [PATCH 10/12] Add two missing expectation fulfillments It looks like two tests in FeedlySetStarredArticlesOperationTests created but never referenced XCTestExpectation instances. Based on the other nearby tests, add a call to `fulfill()` inside the associated completion block after the rest of our test assertions are done. --- .../Feedly/FeedlySetStarredArticlesOperationTests.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlySetStarredArticlesOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlySetStarredArticlesOperationTests.swift index 28e376cda..59a58a2a4 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlySetStarredArticlesOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlySetStarredArticlesOperationTests.swift @@ -257,6 +257,7 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { .map { $0.articleID }) XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) + fetchIdsExpectation.fulfill() } catch let e { XCTFail("Error checking articles IDs: \(e)") } @@ -315,6 +316,7 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { .map { $0.articleID }) XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) + fetchIdsExpectation.fulfill() } catch let e { XCTFail("Error checking articles IDs: \(e)") } From 5ac18b14a7a316952bf32ecbc34dc35d849d7f50 Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Wed, 1 Jan 2020 13:39:17 -0800 Subject: [PATCH 11/12] Add missing expectations to send statuses tests f82be27666 flipped around calls to `selectPendingCount(_:)` so that it respected the new async nature of the method; however, it neglected to add enough XCTestExpectations to keep the test methods running through the callbacks. Add those here. --- ...dlySendArticleStatusesOperationTests.swift | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlySendArticleStatusesOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlySendArticleStatusesOperationTests.swift index 1aee58245..d316b688c 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlySendArticleStatusesOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlySendArticleStatusesOperationTests.swift @@ -75,14 +75,17 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) + let selectPendingCountExpectation = expectation(description: "Did Select Pending Count") container.database.selectPendingCount { result in do { let statusCount = try result.get() XCTAssertEqual(statusCount, 0) + selectPendingCountExpectation.fulfill() } catch let e { XCTFail("Error unwrapping database result: \(e)") } } + waitForExpectations(timeout: 2) } func testSendUnreadFailure() { @@ -115,14 +118,17 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) + let selectPendingCountExpectation = expectation(description: "Did Select Pending Count") container.database.selectPendingCount { result in do { let statusCount = try result.get() XCTAssertEqual(statusCount, statuses.count) + selectPendingCountExpectation.fulfill() } catch let e { XCTFail("Error unwrapping database result: \(e)") } } + waitForExpectations(timeout: 2) } func testSendReadSuccess() { @@ -155,14 +161,17 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) + let selectPendingCountExpectation = expectation(description: "Did Select Pending Count") container.database.selectPendingCount { result in do { let statusCount = try result.get() XCTAssertEqual(statusCount, 0) + selectPendingCountExpectation.fulfill() } catch let e { XCTFail("Error unwrapping database result: \(e)") } } + waitForExpectations(timeout: 2) } func testSendReadFailure() { @@ -195,14 +204,17 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) + let selectPendingCountExpectation = expectation(description: "Did Select Pending Count") container.database.selectPendingCount { result in do { let statusCount = try result.get() XCTAssertEqual(statusCount, statuses.count) + selectPendingCountExpectation.fulfill() } catch let e { XCTFail("Error unwrapping database result: \(e)") } } + waitForExpectations(timeout: 2) } func testSendStarredSuccess() { @@ -235,14 +247,17 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) + let selectPendingCountExpectation = expectation(description: "Did Select Pending Count") container.database.selectPendingCount { result in do { let statusCount = try result.get() XCTAssertEqual(statusCount, 0) + selectPendingCountExpectation.fulfill() } catch let e { XCTFail("Error unwrapping database result: \(e)") } } + waitForExpectations(timeout: 2) } func testSendStarredFailure() { @@ -275,14 +290,17 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) + let selectPendingCountExpectation = expectation(description: "Did Select Pending Count") container.database.selectPendingCount { result in do { let statusCount = try result.get() XCTAssertEqual(statusCount, statuses.count) + selectPendingCountExpectation.fulfill() } catch let e { XCTFail("Error unwrapping database result: \(e)") } } + waitForExpectations(timeout: 2) } func testSendUnstarredSuccess() { @@ -315,14 +333,17 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) + let selectPendingCountExpectation = expectation(description: "Did Select Pending Count") container.database.selectPendingCount { result in do { let statusCount = try result.get() XCTAssertEqual(statusCount, 0) + selectPendingCountExpectation.fulfill() } catch let e { XCTFail("Error unwrapping database result: \(e)") } } + waitForExpectations(timeout: 2) } func testSendUnstarredFailure() { @@ -355,14 +376,17 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) + let selectPendingCountExpectation = expectation(description: "Did Select Pending Count") container.database.selectPendingCount { result in do { let expectedCount = try result.get() XCTAssertEqual(expectedCount, statuses.count) + selectPendingCountExpectation.fulfill() } catch let e { XCTFail("Error unwrapping database result: \(e)") } } + waitForExpectations(timeout: 2) } func testSendAllSuccess() { @@ -412,14 +436,17 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) + let selectPendingCountExpectation = expectation(description: "Did Select Pending Count") container.database.selectPendingCount { result in do { let statusCount = try result.get() XCTAssertEqual(statusCount, 0) + selectPendingCountExpectation.fulfill() } catch let e { XCTFail("Error unwrapping database result: \(e)") } } + waitForExpectations(timeout: 2) } func testSendAllFailure() { @@ -470,13 +497,16 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) + let selectPendingCountExpectation = expectation(description: "Did Select Pending Count") container.database.selectPendingCount { result in do { let statusCount = try result.get() XCTAssertEqual(statusCount, statuses.count) + selectPendingCountExpectation.fulfill() } catch let e { XCTFail("Error unwrapping database result: \(e)") } } + waitForExpectations(timeout: 2) } } From 44e920b18b91988033793f59661aac40719ba318 Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Thu, 2 Jan 2020 13:31:06 -0800 Subject: [PATCH 12/12] Don't explicitly name error variables Following the resolution of #1512, start using the implicit `error` variable inside `catch` blocks instead of explicitly declaring `e` everywhere. --- ...dlySendArticleStatusesOperationTests.swift | 40 +++++++++---------- ...edlySetStarredArticlesOperationTests.swift | 40 +++++++++---------- ...eedlySetUnreadArticlesOperationTests.swift | 40 +++++++++---------- ...dlySyncStarredArticlesOperationTests.swift | 12 +++--- ...edlySyncUnreadStatusesOperationTests.swift | 12 +++--- .../Feedly/FeedlyTestSupport.swift | 8 ++-- 6 files changed, 76 insertions(+), 76 deletions(-) diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlySendArticleStatusesOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlySendArticleStatusesOperationTests.swift index d316b688c..c35a71670 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlySendArticleStatusesOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlySendArticleStatusesOperationTests.swift @@ -81,8 +81,8 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { let statusCount = try result.get() XCTAssertEqual(statusCount, 0) selectPendingCountExpectation.fulfill() - } catch let e { - XCTFail("Error unwrapping database result: \(e)") + } catch { + XCTFail("Error unwrapping database result: \(error)") } } waitForExpectations(timeout: 2) @@ -124,8 +124,8 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { let statusCount = try result.get() XCTAssertEqual(statusCount, statuses.count) selectPendingCountExpectation.fulfill() - } catch let e { - XCTFail("Error unwrapping database result: \(e)") + } catch { + XCTFail("Error unwrapping database result: \(error)") } } waitForExpectations(timeout: 2) @@ -167,8 +167,8 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { let statusCount = try result.get() XCTAssertEqual(statusCount, 0) selectPendingCountExpectation.fulfill() - } catch let e { - XCTFail("Error unwrapping database result: \(e)") + } catch { + XCTFail("Error unwrapping database result: \(error)") } } waitForExpectations(timeout: 2) @@ -210,8 +210,8 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { let statusCount = try result.get() XCTAssertEqual(statusCount, statuses.count) selectPendingCountExpectation.fulfill() - } catch let e { - XCTFail("Error unwrapping database result: \(e)") + } catch { + XCTFail("Error unwrapping database result: \(error)") } } waitForExpectations(timeout: 2) @@ -253,8 +253,8 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { let statusCount = try result.get() XCTAssertEqual(statusCount, 0) selectPendingCountExpectation.fulfill() - } catch let e { - XCTFail("Error unwrapping database result: \(e)") + } catch { + XCTFail("Error unwrapping database result: \(error)") } } waitForExpectations(timeout: 2) @@ -296,8 +296,8 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { let statusCount = try result.get() XCTAssertEqual(statusCount, statuses.count) selectPendingCountExpectation.fulfill() - } catch let e { - XCTFail("Error unwrapping database result: \(e)") + } catch { + XCTFail("Error unwrapping database result: \(error)") } } waitForExpectations(timeout: 2) @@ -339,8 +339,8 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { let statusCount = try result.get() XCTAssertEqual(statusCount, 0) selectPendingCountExpectation.fulfill() - } catch let e { - XCTFail("Error unwrapping database result: \(e)") + } catch { + XCTFail("Error unwrapping database result: \(error)") } } waitForExpectations(timeout: 2) @@ -382,8 +382,8 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { let expectedCount = try result.get() XCTAssertEqual(expectedCount, statuses.count) selectPendingCountExpectation.fulfill() - } catch let e { - XCTFail("Error unwrapping database result: \(e)") + } catch { + XCTFail("Error unwrapping database result: \(error)") } } waitForExpectations(timeout: 2) @@ -442,8 +442,8 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { let statusCount = try result.get() XCTAssertEqual(statusCount, 0) selectPendingCountExpectation.fulfill() - } catch let e { - XCTFail("Error unwrapping database result: \(e)") + } catch { + XCTFail("Error unwrapping database result: \(error)") } } waitForExpectations(timeout: 2) @@ -503,8 +503,8 @@ class FeedlySendArticleStatusesOperationTests: XCTestCase { let statusCount = try result.get() XCTAssertEqual(statusCount, statuses.count) selectPendingCountExpectation.fulfill() - } catch let e { - XCTFail("Error unwrapping database result: \(e)") + } catch { + XCTFail("Error unwrapping database result: \(error)") } } waitForExpectations(timeout: 2) diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlySetStarredArticlesOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlySetStarredArticlesOperationTests.swift index 59a58a2a4..cdc0be0ad 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlySetStarredArticlesOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlySetStarredArticlesOperationTests.swift @@ -55,8 +55,8 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { XCTAssertTrue(accountArticlesIDs.isEmpty) XCTAssertEqual(accountArticlesIDs, testIds) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking articles IDs: \(e)") + } catch { + XCTFail("Error checking articles IDs: \(error)") } } waitForExpectations(timeout: 2) @@ -83,8 +83,8 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { let accountArticlesIDs = try accountArticlesIDsResult.get() XCTAssertEqual(accountArticlesIDs.count, testIds.count) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking articles IDs: \(e)") + } catch { + XCTFail("Error checking articles IDs: \(error)") } } waitForExpectations(timeout: 2) @@ -111,8 +111,8 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { let accountArticlesIDs = try accountArticlesIDsResult.get() XCTAssertEqual(accountArticlesIDs.count, testIds.count) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking articles IDs: \(e)") + } catch { + XCTFail("Error checking articles IDs: \(error)") } } waitForExpectations(timeout: 2) @@ -154,8 +154,8 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { let remainingAccountArticlesIDs = try remainingAccountArticlesIDsResult.get() XCTAssertEqual(remainingAccountArticlesIDs, remainingStarredIds) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking articles IDs: \(e)") + } catch { + XCTFail("Error checking articles IDs: \(error)") } } waitForExpectations(timeout: 2) @@ -197,8 +197,8 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { let remainingAccountArticlesIDs = try remainingAccountArticlesIDsResult.get() XCTAssertEqual(remainingAccountArticlesIDs, remainingStarredIds) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking articles IDs: \(e)") + } catch { + XCTFail("Error checking articles IDs: \(error)") } } waitForExpectations(timeout: 2) @@ -258,8 +258,8 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking articles IDs: \(e)") + } catch { + XCTFail("Error checking articles IDs: \(error)") } } waitForExpectations(timeout: 2) @@ -317,8 +317,8 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking articles IDs: \(e)") + } catch { + XCTFail("Error checking articles IDs: \(error)") } } waitForExpectations(timeout: 2) @@ -370,8 +370,8 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking articles IDs: \(e)") + } catch { + XCTFail("Error checking articles IDs: \(error)") } } waitForExpectations(timeout: 2) @@ -422,8 +422,8 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking articles IDs: \(e)") + } catch { + XCTFail("Error checking articles IDs: \(error)") } } waitForExpectations(timeout: 2) @@ -480,8 +480,8 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { XCTAssertEqual(idsOfStarredArticles, someRemainingStarredIdsOfIngestedArticles) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking articles IDs: \(e)") + } catch { + XCTFail("Error checking articles IDs: \(error)") } } waitForExpectations(timeout: 2) diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlySetUnreadArticlesOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlySetUnreadArticlesOperationTests.swift index 04ebb191d..4126d6003 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlySetUnreadArticlesOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlySetUnreadArticlesOperationTests.swift @@ -55,8 +55,8 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { XCTAssertTrue(accountArticlesIDs.isEmpty) XCTAssertEqual(accountArticlesIDs.count, testIds.count) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking account articles IDs result: \(e)") + } catch { + XCTFail("Error checking account articles IDs result: \(error)") } } @@ -84,8 +84,8 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { let accountArticlesIDs = try accountArticlesIDsResult.get() XCTAssertEqual(accountArticlesIDs.count, testIds.count) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking account articles IDs result: \(e)") + } catch { + XCTFail("Error checking account articles IDs result: \(error)") } } waitForExpectations(timeout: 2) @@ -112,8 +112,8 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { let accountArticlesIDs = try accountArticlesIDsResult.get() XCTAssertEqual(accountArticlesIDs.count, testIds.count) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking account articles IDs result: \(e)") + } catch { + XCTFail("Error checking account articles IDs result: \(error)") } } waitForExpectations(timeout: 2) @@ -155,8 +155,8 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { let remainingAccountArticlesIDs = try remainingAccountArticlesIDsResult.get() XCTAssertEqual(remainingAccountArticlesIDs, remainingUnreadIds) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking account articles IDs result: \(e)") + } catch { + XCTFail("Error checking account articles IDs result: \(error)") } } waitForExpectations(timeout: 2) @@ -198,8 +198,8 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { let remainingAccountArticlesIDs = try remainingAccountArticlesIDsResult.get() XCTAssertEqual(remainingAccountArticlesIDs, remainingUnreadIds) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking account articles IDs result: \(e)") + } catch { + XCTFail("Error checking account articles IDs result: \(error)") } } waitForExpectations(timeout: 2) @@ -258,8 +258,8 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { XCTAssertEqual(idsOfUnreadArticles, remainingUnreadIds) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking account articles IDs result: \(e)") + } catch { + XCTFail("Error checking account articles IDs result: \(error)") } } waitForExpectations(timeout: 2) @@ -317,8 +317,8 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { XCTAssertEqual(idsOfUnreadArticles, remainingUnreadIds) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking account articles IDs result: \(e)") + } catch { + XCTFail("Error checking account articles IDs result: \(error)") } } } @@ -369,8 +369,8 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { XCTAssertEqual(idsOfUnreadArticles, remainingUnreadIds) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking account articles IDs result: \(e)") + } catch { + XCTFail("Error checking account articles IDs result: \(error)") } } waitForExpectations(timeout: 2) @@ -421,8 +421,8 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { XCTAssertEqual(idsOfUnreadArticles, remainingUnreadIds) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking account articles IDs result: \(e)") + } catch { + XCTFail("Error checking account articles IDs result: \(error)") } } } @@ -477,8 +477,8 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { XCTAssertEqual(idsOfUnreadArticles, someRemainingUnreadIdsOfIngestedArticles) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking account articles IDs result: \(e)") + } catch { + XCTFail("Error checking account articles IDs result: \(error)") } } } diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlySyncStarredArticlesOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlySyncStarredArticlesOperationTests.swift index cbefa2515..40d0c39ff 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlySyncStarredArticlesOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlySyncStarredArticlesOperationTests.swift @@ -73,8 +73,8 @@ class FeedlySyncStarredArticlesOperationTests: XCTestCase { XCTAssertEqual(expectedArticles, starredArticles) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking starred article IDs: \(e)") + } catch { + XCTFail("Error checking starred article IDs: \(error)") } } waitForExpectations(timeout: 2) @@ -114,8 +114,8 @@ class FeedlySyncStarredArticlesOperationTests: XCTestCase { let starredArticleIds = try starredArticleIdsResult.get() XCTAssertTrue(starredArticleIds.isEmpty) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking starred article IDs: \(e)") + } catch { + XCTFail("Error checking starred article IDs: \(error)") } } waitForExpectations(timeout: 2) @@ -180,8 +180,8 @@ class FeedlySyncStarredArticlesOperationTests: XCTestCase { XCTAssertEqual(expectedArticles, starredArticles) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking starred article IDs: \(e)") + } catch { + XCTFail("Error checking starred article IDs: \(error)") } } waitForExpectations(timeout: 2) diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlySyncUnreadStatusesOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlySyncUnreadStatusesOperationTests.swift index 67b9dd4e9..09a8ec57a 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlySyncUnreadStatusesOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlySyncUnreadStatusesOperationTests.swift @@ -62,8 +62,8 @@ class FeedlySyncUnreadStatusesOperationTests: XCTestCase { let missingIds = expectedArticleIds.subtracting(unreadArticleIds) XCTAssertTrue(missingIds.isEmpty, "These article ids were not marked as unread.") fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking unread article IDs: \(e)") + } catch { + XCTFail("Error checking unread article IDs: \(error)") } } waitForExpectations(timeout: 2) @@ -103,8 +103,8 @@ class FeedlySyncUnreadStatusesOperationTests: XCTestCase { let unreadArticleIds = try unreadArticleIdsResult.get() XCTAssertTrue(unreadArticleIds.isEmpty) fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking unread article IDs: \(e)") + } catch { + XCTFail("Error checking unread article IDs: \(error)") } } waitForExpectations(timeout: 2) @@ -158,8 +158,8 @@ class FeedlySyncUnreadStatusesOperationTests: XCTestCase { let missingIds = expectedArticleIds.subtracting(unreadArticleIds) XCTAssertTrue(missingIds.isEmpty, "These article ids were not marked as unread.") fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error checking unread article IDs: \(e)") + } catch { + XCTFail("Error checking unread article IDs: \(error)") } } waitForExpectations(timeout: 2) diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlyTestSupport.swift b/Frameworks/Account/AccountTests/Feedly/FeedlyTestSupport.swift index 4e3ef6d87..46117de80 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlyTestSupport.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlyTestSupport.swift @@ -228,8 +228,8 @@ class FeedlyTestSupport { // make sure that these ids are marked as unread (a subset of the total). XCTAssertTrue(ids.isSubset(of: articleIds), "Some articles in `ids` are not marked as unread.") fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error unwrapping article IDs: \(e)") + } catch { + XCTFail("Error unwrapping article IDs: \(error)") } } testCase.wait(for: [fetchIdsExpectation], timeout: 2) @@ -252,8 +252,8 @@ class FeedlyTestSupport { // make sure that these articles are marked as starred (a subset of the total). XCTAssertTrue(ids.isSubset(of: articleIds), "Some articles in `ids` are not marked as starred.") fetchIdsExpectation.fulfill() - } catch let e { - XCTFail("Error unwrapping article IDs: \(e)") + } catch { + XCTFail("Error unwrapping article IDs: \(error)") } } testCase.wait(for: [fetchIdsExpectation], timeout: 2)