diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlyAddNewFeedOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlyAddNewFeedOperationTests.swift index 20f6e1a69..fba479fd2 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlyAddNewFeedOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlyAddNewFeedOperationTests.swift @@ -164,7 +164,7 @@ class FeedlyAddNewFeedOperationTests: XCTestCase { XCTAssert(progress.isComplete) support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "feedStream", subdirectory: subdirectory) - support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds", subdirectory: subdirectory) + support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds", subdirectory: subdirectory, testCase: self) } class TestFeedlyAddFeedToCollectionService: FeedlyAddFeedToCollectionService { diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlySetStarredArticlesOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlySetStarredArticlesOperationTests.swift index 5f5ff0b6e..e86ba2de3 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlySetStarredArticlesOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlySetStarredArticlesOperationTests.swift @@ -48,9 +48,13 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let accountArticlesIDs = account.fetchStarredArticleIDs() - XCTAssertTrue(accountArticlesIDs.isEmpty) - XCTAssertEqual(accountArticlesIDs, testIds) + let fetchIdsExpectation = expectation(description: "Fetch Article Ids") + account.fetchStarredArticleIDs { accountArticlesIDs in + XCTAssertTrue(accountArticlesIDs.isEmpty) + XCTAssertEqual(accountArticlesIDs, testIds) + fetchIdsExpectation.fulfill() + } + waitForExpectations(timeout: 2) } func testSetOneArticleIdStarred() { @@ -68,8 +72,12 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let accountArticlesIDs = account.fetchStarredArticleIDs() - XCTAssertEqual(accountArticlesIDs.count, testIds.count) + let fetchIdsExpectation = expectation(description: "Fetch Article Ids") + account.fetchStarredArticleIDs { accountArticlesIDs in + XCTAssertEqual(accountArticlesIDs.count, testIds.count) + fetchIdsExpectation.fulfill() + } + waitForExpectations(timeout: 2) } func testSetManyArticleIdsStarred() { @@ -87,8 +95,12 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let accountArticlesIDs = account.fetchStarredArticleIDs() - XCTAssertEqual(accountArticlesIDs.count, testIds.count) + let fetchIdsExpectation = expectation(description: "Fetch Article Ids") + account.fetchStarredArticleIDs { accountArticlesIDs in + XCTAssertEqual(accountArticlesIDs.count, testIds.count) + fetchIdsExpectation.fulfill() + } + waitForExpectations(timeout: 2) } func testSetSomeArticleIdsUnstarred() { @@ -121,8 +133,12 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let remainingAccountArticlesIDs = account.fetchStarredArticleIDs() - XCTAssertEqual(remainingAccountArticlesIDs, remainingStarredIds) + let fetchIdsExpectation = expectation(description: "Fetch Article Ids") + account.fetchStarredArticleIDs { remainingAccountArticlesIDs in + XCTAssertEqual(remainingAccountArticlesIDs, remainingStarredIds) + fetchIdsExpectation.fulfill() + } + waitForExpectations(timeout: 2) } func testSetAllArticleIdsUnstarred() { @@ -155,8 +171,12 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let remainingAccountArticlesIDs = account.fetchStarredArticleIDs() - XCTAssertEqual(remainingAccountArticlesIDs, remainingStarredIds) + let fetchIdsExpectation = expectation(description: "Fetch Article Ids") + account.fetchStarredArticleIDs { remainingAccountArticlesIDs in + XCTAssertEqual(remainingAccountArticlesIDs, remainingStarredIds) + fetchIdsExpectation.fulfill() + } + waitForExpectations(timeout: 2) } // MARK: - Updating Article Unread Status @@ -200,15 +220,18 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let accountArticlesIDs = account.fetchStarredArticleIDs() - XCTAssertEqual(accountArticlesIDs, remainingStarredIds) - - let idsOfStarredArticles = Set(account - .fetchArticles(.articleIDs(remainingStarredIds)) - .filter { $0.status.boolStatus(forKey: .starred) == true } - .map { $0.articleID }) - - XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) + 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) + } + waitForExpectations(timeout: 2) } func testSetManyArticlesUnread() { @@ -250,15 +273,18 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let accountArticlesIDs = account.fetchStarredArticleIDs() - XCTAssertEqual(accountArticlesIDs, remainingStarredIds) - - let idsOfStarredArticles = Set(account - .fetchArticles(.articleIDs(remainingStarredIds)) - .filter { $0.status.boolStatus(forKey: .starred) == true } - .map { $0.articleID }) - - XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) + 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) + } + waitForExpectations(timeout: 2) } func testSetOneArticleUnread() { @@ -294,15 +320,19 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let accountArticlesIDs = account.fetchStarredArticleIDs() - XCTAssertEqual(accountArticlesIDs, remainingStarredIds) - - let idsOfStarredArticles = Set(account - .fetchArticles(.articleIDs(remainingStarredIds)) - .filter { $0.status.boolStatus(forKey: .starred) == true } - .map { $0.articleID }) - - XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) + 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() + } + waitForExpectations(timeout: 2) } func testSetNoArticlesRead() { @@ -337,15 +367,19 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let accountArticlesIDs = account.fetchStarredArticleIDs() - XCTAssertEqual(accountArticlesIDs, remainingStarredIds) - - let idsOfStarredArticles = Set(account - .fetchArticles(.articleIDs(remainingStarredIds)) - .filter { $0.status.boolStatus(forKey: .starred) == true } - .map { $0.articleID }) - - XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) + 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() + } + waitForExpectations(timeout: 2) } func testSetAllArticlesAndArticleIdsWithSomeArticlesIngested() { @@ -383,16 +417,21 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let accountArticlesIDs = account.fetchStarredArticleIDs() - XCTAssertEqual(accountArticlesIDs, remainingStarredIds) - - let someTestItems = Set(someItemsAndFeeds.flatMap { $0.value }) - let someRemainingStarredIdsOfIngestedArticles = Set(someTestItems.compactMap { $0.syncServiceID }) - let idsOfStarredArticles = Set(account - .fetchArticles(.articleIDs(someRemainingStarredIdsOfIngestedArticles)) - .filter { $0.status.boolStatus(forKey: .starred) == true } - .map { $0.articleID }) - - XCTAssertEqual(idsOfStarredArticles, someRemainingStarredIdsOfIngestedArticles) + 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() + } + waitForExpectations(timeout: 2) } } diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlySetUnreadArticlesOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlySetUnreadArticlesOperationTests.swift index 87b3746c0..e7e936e85 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlySetUnreadArticlesOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlySetUnreadArticlesOperationTests.swift @@ -48,9 +48,14 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let accountArticlesIDs = account.fetchUnreadArticleIDs() - XCTAssertTrue(accountArticlesIDs.isEmpty) - XCTAssertEqual(accountArticlesIDs.count, testIds.count) + let fetchIdsExpectation = expectation(description: "Fetched Articles Ids") + account.fetchUnreadArticleIDs { accountArticlesIDs in + XCTAssertTrue(accountArticlesIDs.isEmpty) + XCTAssertEqual(accountArticlesIDs.count, testIds.count) + fetchIdsExpectation.fulfill() + } + + waitForExpectations(timeout: 2) } func testSetOneArticleIdUnread() { @@ -68,8 +73,12 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let accountArticlesIDs = account.fetchUnreadArticleIDs() - XCTAssertEqual(accountArticlesIDs.count, testIds.count) + let fetchIdsExpectation = expectation(description: "Fetched Articles Ids") + account.fetchUnreadArticleIDs { accountArticlesIDs in + XCTAssertEqual(accountArticlesIDs.count, testIds.count) + fetchIdsExpectation.fulfill() + } + waitForExpectations(timeout: 2) } func testSetManyArticleIdsUnread() { @@ -87,8 +96,12 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let accountArticlesIDs = account.fetchUnreadArticleIDs() - XCTAssertEqual(accountArticlesIDs.count, testIds.count) + let fetchIdsExpectation = expectation(description: "Fetched Articles Ids") + account.fetchUnreadArticleIDs { accountArticlesIDs in + XCTAssertEqual(accountArticlesIDs.count, testIds.count) + fetchIdsExpectation.fulfill() + } + waitForExpectations(timeout: 2) } func testSetSomeArticleIdsRead() { @@ -121,8 +134,12 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let remainingAccountArticlesIDs = account.fetchUnreadArticleIDs() - XCTAssertEqual(remainingAccountArticlesIDs, remainingUnreadIds) + let fetchIdsExpectation = expectation(description: "Fetched Articles Ids") + account.fetchUnreadArticleIDs { remainingAccountArticlesIDs in + XCTAssertEqual(remainingAccountArticlesIDs, remainingUnreadIds) + fetchIdsExpectation.fulfill() + } + waitForExpectations(timeout: 2) } func testSetAllArticleIdsRead() { @@ -155,8 +172,12 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let remainingAccountArticlesIDs = account.fetchUnreadArticleIDs() - XCTAssertEqual(remainingAccountArticlesIDs, remainingUnreadIds) + let fetchIdsExpectation = expectation(description: "Fetched Articles Ids") + account.fetchUnreadArticleIDs { remainingAccountArticlesIDs in + XCTAssertEqual(remainingAccountArticlesIDs, remainingUnreadIds) + fetchIdsExpectation.fulfill() + } + waitForExpectations(timeout: 2) } // MARK: - Updating Article Unread Status @@ -200,15 +221,18 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let accountArticlesIDs = account.fetchUnreadArticleIDs() - XCTAssertEqual(accountArticlesIDs, remainingUnreadIds) - - let idsOfUnreadArticles = Set(account - .fetchArticles(.articleIDs(remainingUnreadIds)) - .filter { $0.status.boolStatus(forKey: .read) == false } - .map { $0.articleID }) - - XCTAssertEqual(idsOfUnreadArticles, remainingUnreadIds) + 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() + } + waitForExpectations(timeout: 2) } func testSetManyArticlesUnread() { @@ -250,15 +274,18 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let accountArticlesIDs = account.fetchUnreadArticleIDs() - XCTAssertEqual(accountArticlesIDs, remainingUnreadIds) - - let idsOfUnreadArticles = Set(account - .fetchArticles(.articleIDs(remainingUnreadIds)) - .filter { $0.status.boolStatus(forKey: .read) == false } - .map { $0.articleID }) - - XCTAssertEqual(idsOfUnreadArticles, remainingUnreadIds) + 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() + } } func testSetOneArticleUnread() { @@ -294,15 +321,19 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let accountArticlesIDs = account.fetchUnreadArticleIDs() - XCTAssertEqual(accountArticlesIDs, remainingUnreadIds) - - let idsOfUnreadArticles = Set(account - .fetchArticles(.articleIDs(remainingUnreadIds)) - .filter { $0.status.boolStatus(forKey: .read) == false } - .map { $0.articleID }) - - XCTAssertEqual(idsOfUnreadArticles, remainingUnreadIds) + 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() + } + waitForExpectations(timeout: 2) } func testSetNoArticlesRead() { @@ -337,15 +368,18 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let accountArticlesIDs = account.fetchUnreadArticleIDs() - XCTAssertEqual(accountArticlesIDs, remainingUnreadIds) - - let idsOfUnreadArticles = Set(account - .fetchArticles(.articleIDs(remainingUnreadIds)) - .filter { $0.status.boolStatus(forKey: .read) == false } - .map { $0.articleID }) - - XCTAssertEqual(idsOfUnreadArticles, remainingUnreadIds) + 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() + } } func testSetAllArticlesAndArticleIdsWithSomeArticlesIngested() { @@ -383,16 +417,19 @@ class FeedlySetUnreadArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let accountArticlesIDs = account.fetchUnreadArticleIDs() - XCTAssertEqual(accountArticlesIDs, remainingUnreadIds) - - let someTestItems = Set(someItemsAndFeeds.flatMap { $0.value }) - let someRemainingUnreadIdsOfIngestedArticles = Set(someTestItems.compactMap { $0.syncServiceID }) - let idsOfUnreadArticles = Set(account - .fetchArticles(.articleIDs(someRemainingUnreadIdsOfIngestedArticles)) - .filter { $0.status.boolStatus(forKey: .read) == false } - .map { $0.articleID }) - - XCTAssertEqual(idsOfUnreadArticles, someRemainingUnreadIdsOfIngestedArticles) + 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() + } } } diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlySyncAllOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlySyncAllOperationTests.swift index 26dcf3b3b..914c25e8a 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlySyncAllOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlySyncAllOperationTests.swift @@ -171,9 +171,9 @@ class FeedlySyncAllOperationTests: XCTestCase { 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) - support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds", subdirectory: subdirectory) - support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds@MTZkOTRhOTNhZTQ6MzExOjUzYjgyNmEy", subdirectory: subdirectory) - support.checkStarredStatuses(in: account, againstItemsInStreamInJSONNamed: "starred", 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) } @@ -187,9 +187,9 @@ class FeedlySyncAllOperationTests: XCTestCase { let subdirectory = "feedly-2-changestatuses" support.checkFoldersAndFeeds(in: account, againstCollectionsAndFeedsInJSONNamed: "collections", subdirectory: subdirectory) support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) - support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds", subdirectory: subdirectory) - support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds@MTZkOTJkNjIwM2Q6MTEzYjpkNDUwNjA3MQ==", subdirectory: subdirectory) - support.checkStarredStatuses(in: account, againstItemsInStreamInJSONNamed: "starred", 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) } @@ -203,9 +203,9 @@ class FeedlySyncAllOperationTests: XCTestCase { let subdirectory = "feedly-3-changestatusesagain" support.checkFoldersAndFeeds(in: account, againstCollectionsAndFeedsInJSONNamed: "collections", subdirectory: subdirectory) support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) - support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds", subdirectory: subdirectory) - support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds@MTZkOGRlMjVmM2M6M2YyOmQ0NTA2MDcx", subdirectory: subdirectory) - support.checkStarredStatuses(in: account, againstItemsInStreamInJSONNamed: "starred", 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) } @@ -219,9 +219,9 @@ class FeedlySyncAllOperationTests: XCTestCase { let subdirectory = "feedly-4-addfeedsandfolders" support.checkFoldersAndFeeds(in: account, againstCollectionsAndFeedsInJSONNamed: "collections", subdirectory: subdirectory) support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) - support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds", subdirectory: subdirectory) - support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds@MTZkOTE3YTRlMzQ6YWZjOmQ0NTA2MDcx", subdirectory: subdirectory) - support.checkStarredStatuses(in: account, againstItemsInStreamInJSONNamed: "starred", 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) } @@ -235,9 +235,9 @@ class FeedlySyncAllOperationTests: XCTestCase { let subdirectory = "feedly-5-removefeedsandfolders" support.checkFoldersAndFeeds(in: account, againstCollectionsAndFeedsInJSONNamed: "collections", subdirectory: subdirectory) support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) - support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds", subdirectory: subdirectory) - support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds@MTZkOGRlMjVmM2M6M2YxOmQ0NTA2MDcx", subdirectory: subdirectory) - support.checkStarredStatuses(in: account, againstItemsInStreamInJSONNamed: "starred", 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) } diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlySyncStarredArticlesOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlySyncStarredArticlesOperationTests.swift index 461b2d078..761dd8a01 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlySyncStarredArticlesOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlySyncStarredArticlesOperationTests.swift @@ -55,19 +55,24 @@ class FeedlySyncStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let expectedArticleIds = Set(items.map { $0.id }) - let starredArticleIds = account.fetchStarredArticleIDs() - 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 = account.fetchArticles(.articleIDs(expectedArticleIds)) - XCTAssertEqual(expectedArticles.count, expectedArticleIds.count, "Did not fetch all the articles.") - - let starredArticles = 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) + 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() + } + waitForExpectations(timeout: 2) } func testIngestsOnePageFailure() { @@ -98,8 +103,12 @@ class FeedlySyncStarredArticlesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let starredArticleIds = account.fetchStarredArticleIDs() - XCTAssertTrue(starredArticleIds.isEmpty) + let fetchIdsExpectation = expectation(description: "Fetch Article Ids") + account.fetchStarredArticleIDs { starredArticleIds in + XCTAssertTrue(starredArticleIds.isEmpty) + fetchIdsExpectation.fulfill() + } + waitForExpectations(timeout: 2) } func testIngestsManyPagesSuccess() { @@ -143,18 +152,23 @@ class FeedlySyncStarredArticlesOperationTests: XCTestCase { // Find articles inserted. let expectedArticleIds = Set(service.pages.values.map { $0.items }.flatMap { $0 }.map { $0.id }) - let starredArticleIds = account.fetchStarredArticleIDs() - 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 = account.fetchArticles(.articleIDs(expectedArticleIds)) - XCTAssertEqual(expectedArticles.count, expectedArticleIds.count, "Did not fetch all the articles.") - - let starredArticles = 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) + 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() + } + waitForExpectations(timeout: 2) } } diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlySyncUnreadStatusesOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlySyncUnreadStatusesOperationTests.swift index 2c4816d30..fa4864a73 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlySyncUnreadStatusesOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlySyncUnreadStatusesOperationTests.swift @@ -55,9 +55,13 @@ class FeedlySyncUnreadStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) let expectedArticleIds = Set(ids) - let unreadArticleIds = account.fetchUnreadArticleIDs() - let missingIds = expectedArticleIds.subtracting(unreadArticleIds) - XCTAssertTrue(missingIds.isEmpty, "These article ids were not marked as unread.") + 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() + } + waitForExpectations(timeout: 2) } func testIngestsOnePageFailure() { @@ -88,8 +92,12 @@ class FeedlySyncUnreadStatusesOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let unreadArticleIds = account.fetchUnreadArticleIDs() - XCTAssertTrue(unreadArticleIds.isEmpty) + let fetchIdsExpectation = expectation(description: "Fetch Article Ids") + account.fetchUnreadArticleIDs { unreadArticleIds in + XCTAssertTrue(unreadArticleIds.isEmpty) + fetchIdsExpectation.fulfill() + } + waitForExpectations(timeout: 2) } func testIngestsManyPagesSuccess() { @@ -133,8 +141,12 @@ class FeedlySyncUnreadStatusesOperationTests: XCTestCase { // Find statuses inserted. let expectedArticleIds = Set(service.pages.values.map { $0.ids }.flatMap { $0 }) - let unreadArticleIds = account.fetchUnreadArticleIDs() - let missingIds = expectedArticleIds.subtracting(unreadArticleIds) - XCTAssertTrue(missingIds.isEmpty, "These article ids were not marked as unread.") + 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() + } + waitForExpectations(timeout: 2) } } diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlyTestSupport.swift b/Frameworks/Account/AccountTests/Feedly/FeedlyTestSupport.swift index afa84b3c2..3e5ae30ff 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlyTestSupport.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlyTestSupport.swift @@ -212,33 +212,41 @@ class FeedlyTestSupport { } } - func checkUnreadStatuses(in account: Account, againstIdsInStreamInJSONNamed name: String, subdirectory: String? = nil) { + func checkUnreadStatuses(in account: Account, againstIdsInStreamInJSONNamed name: String, subdirectory: String? = nil, testCase: XCTestCase) { let streamIds = testJSON(named: name, subdirectory: subdirectory) as! [String:Any] - checkUnreadStatuses(in: account, correspondToIdsInJSONPayload: streamIds) + checkUnreadStatuses(in: account, correspondToIdsInJSONPayload: streamIds, testCase: testCase) } - func checkUnreadStatuses(in testAccount: Account, correspondToIdsInJSONPayload streamIds: [String: Any]) { + func checkUnreadStatuses(in testAccount: Account, correspondToIdsInJSONPayload streamIds: [String: Any], testCase: XCTestCase) { let ids = Set(streamIds["ids"] as! [String]) - let articleIds = testAccount.fetchUnreadArticleIDs() - // 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.") + 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() + } + testCase.wait(for: [fetchIdsExpectation], timeout: 2) } - func checkStarredStatuses(in account: Account, againstItemsInStreamInJSONNamed name: String, subdirectory: String? = nil) { + func checkStarredStatuses(in account: Account, againstItemsInStreamInJSONNamed name: String, subdirectory: String? = nil, testCase: XCTestCase) { let streamIds = testJSON(named: name, subdirectory: subdirectory) as! [String:Any] - checkStarredStatuses(in: account, correspondToStreamItemsIn: streamIds) + checkStarredStatuses(in: account, correspondToStreamItemsIn: streamIds, testCase: testCase) } - func checkStarredStatuses(in testAccount: Account, correspondToStreamItemsIn stream: [String: Any]) { + func checkStarredStatuses(in testAccount: Account, correspondToStreamItemsIn stream: [String: Any], testCase: XCTestCase) { let items = stream["items"] as! [[String: Any]] let ids = Set(items.map { $0["id"] as! String }) - let articleIds = testAccount.fetchStarredArticleIDs() - // 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.") + 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() + } + testCase.wait(for: [fetchIdsExpectation], timeout: 2) } func check(_ entries: [FeedlyEntry], correspondToStreamItemsIn stream: [String: Any]) { diff --git a/Frameworks/Account/Feedly/Operations/FeedlyAddNewFeedOperation.swift b/Frameworks/Account/Feedly/Operations/FeedlyAddNewFeedOperation.swift index 43acad907..bb98a7ada 100644 --- a/Frameworks/Account/Feedly/Operations/FeedlyAddNewFeedOperation.swift +++ b/Frameworks/Account/Feedly/Operations/FeedlyAddNewFeedOperation.swift @@ -93,7 +93,7 @@ class FeedlyAddNewFeedOperation: FeedlyOperation, FeedlyOperationDelegate, Feedl self.operationQueue.addOperation(createFeeds) let syncUnread = FeedlySyncUnreadStatusesOperation(account: account, credentials: credentials, service: syncUnreadIdsService, newerThan: nil, log: log) - syncUnread.addDependency(addRequest) + syncUnread.addDependency(createFeeds) syncUnread.downloadProgress = downloadProgress self.operationQueue.addOperation(syncUnread) diff --git a/Frameworks/Account/Feedly/Operations/FeedlySetStarredArticlesOperation.swift b/Frameworks/Account/Feedly/Operations/FeedlySetStarredArticlesOperation.swift index f32824587..17817ae70 100644 --- a/Frameworks/Account/Feedly/Operations/FeedlySetStarredArticlesOperation.swift +++ b/Frameworks/Account/Feedly/Operations/FeedlySetStarredArticlesOperation.swift @@ -32,39 +32,44 @@ final class FeedlySetStarredArticlesOperation: FeedlyOperation { return } - let group = DispatchGroup() - - let remoteStarredArticleIds = allStarredEntryIdsProvider.entryIds - account.fetchStarredArticleIDs { localStarredArticleIDs in - // Mark articles as starred - let deltaStarredArticleIDs = remoteStarredArticleIds.subtracting(localStarredArticleIDs) - let markStarredArticles = self.account.fetchArticles(.articleIDs(deltaStarredArticleIDs)) - self.account.update(markStarredArticles, statusKey: .starred, flag: true) - - // Save any starred statuses for articles we haven't yet received - let markStarredArticleIDs = Set(markStarredArticles.map { $0.articleID }) - let missingStarredArticleIDs = deltaStarredArticleIDs.subtracting(markStarredArticleIDs) - group.enter() - self.account.ensureStatuses(missingStarredArticleIDs, true, .starred, true) { - group.leave() - } - - // Mark articles as unstarred - let deltaUnstarredArticleIDs = localStarredArticleIDs.subtracting(remoteStarredArticleIds) - let markUnstarredArticles = self.account.fetchArticles(.articleIDs(deltaUnstarredArticleIDs)) - self.account.update(markUnstarredArticles, statusKey: .starred, flag: false) - - // Save any unstarred statuses for articles we haven't yet received - let markUnstarredArticleIDs = Set(markUnstarredArticles.map { $0.articleID }) - let missingUnstarredArticleIDs = deltaUnstarredArticleIDs.subtracting(markUnstarredArticleIDs) - group.enter() - self.account.ensureStatuses(missingUnstarredArticleIDs, true, .starred, false) { - group.leave() - } - - group.notify(queue: .main) { - self.didFinish() - } + account.fetchStarredArticleIDs(didFetchStarredArticleIDs(_:)) + } + + private func didFetchStarredArticleIDs(_ localStarredArticleIDs: Set) { + guard !isCancelled else { + didFinish() + return } + + let group = DispatchGroup() + let remoteStarredArticleIds = allStarredEntryIdsProvider.entryIds + + // Mark articles as starred + let deltaStarredArticleIDs = remoteStarredArticleIds.subtracting(localStarredArticleIDs) + let markStarredArticles = account.fetchArticles(.articleIDs(deltaStarredArticleIDs)) + account.update(markStarredArticles, statusKey: .starred, flag: true) + + // Save any starred statuses for articles we haven't yet received + let markStarredArticleIDs = Set(markStarredArticles.map { $0.articleID }) + let missingStarredArticleIDs = deltaStarredArticleIDs.subtracting(markStarredArticleIDs) + group.enter() + account.ensureStatuses(missingStarredArticleIDs, true, .starred, true) { + group.leave() + } + + // Mark articles as unstarred + let deltaUnstarredArticleIDs = localStarredArticleIDs.subtracting(remoteStarredArticleIds) + let markUnstarredArticles = account.fetchArticles(.articleIDs(deltaUnstarredArticleIDs)) + account.update(markUnstarredArticles, statusKey: .starred, flag: false) + + // Save any unstarred statuses for articles we haven't yet received + let markUnstarredArticleIDs = Set(markUnstarredArticles.map { $0.articleID }) + let missingUnstarredArticleIDs = deltaUnstarredArticleIDs.subtracting(markUnstarredArticleIDs) + group.enter() + account.ensureStatuses(missingUnstarredArticleIDs, true, .starred, false) { + group.leave() + } + + group.notify(queue: .main, execute: didFinish) } } diff --git a/Frameworks/Account/Feedly/Operations/FeedlySetUnreadArticlesOperation.swift b/Frameworks/Account/Feedly/Operations/FeedlySetUnreadArticlesOperation.swift index 3e431ea62..3dcc72326 100644 --- a/Frameworks/Account/Feedly/Operations/FeedlySetUnreadArticlesOperation.swift +++ b/Frameworks/Account/Feedly/Operations/FeedlySetUnreadArticlesOperation.swift @@ -32,41 +32,45 @@ final class FeedlySetUnreadArticlesOperation: FeedlyOperation { return } - let group = DispatchGroup() - - let remoteUnreadArticleIds = allUnreadIdsProvider.entryIds - //Set(entries.filter { $0.unread }.map { $0.id }) - account.fetchUnreadArticleIDs { localUnreadArticleIds in - // Mark articles as unread - let deltaUnreadArticleIds = remoteUnreadArticleIds.subtracting(localUnreadArticleIds) - let markUnreadArticles = self.account.fetchArticles(.articleIDs(deltaUnreadArticleIds)) - self.account.update(markUnreadArticles, statusKey: .read, flag: false) - - // Save any unread statuses for articles we haven't yet received - let markUnreadArticleIDs = Set(markUnreadArticles.map { $0.articleID }) - let missingUnreadArticleIDs = deltaUnreadArticleIds.subtracting(markUnreadArticleIDs) - - group.enter() - self.account.ensureStatuses(missingUnreadArticleIDs, true, .read, false) { - group.leave() - } - - // Mark articles as read - let deltaReadArticleIds = localUnreadArticleIds.subtracting(remoteUnreadArticleIds) - let markReadArticles = self.account.fetchArticles(.articleIDs(deltaReadArticleIds)) - self.account.update(markReadArticles, statusKey: .read, flag: true) - - // Save any read statuses for articles we haven't yet received - let markReadArticleIDs = Set(markReadArticles.map { $0.articleID }) - let missingReadArticleIDs = deltaReadArticleIds.subtracting(markReadArticleIDs) - group.enter() - self.account.ensureStatuses(missingReadArticleIDs, true, .read, true) { - group.leave() - } - - group.notify(queue: .main) { - self.didFinish() - } + account.fetchUnreadArticleIDs(didFetchUnreadArticleIDs(_:)) + } + + private func didFetchUnreadArticleIDs(_ localUnreadArticleIds: Set) { + guard !isCancelled else { + didFinish() + return } + + let group = DispatchGroup() + let remoteUnreadArticleIds = allUnreadIdsProvider.entryIds + + // Mark articles as unread + let deltaUnreadArticleIds = remoteUnreadArticleIds.subtracting(localUnreadArticleIds) + let markUnreadArticles = account.fetchArticles(.articleIDs(deltaUnreadArticleIds)) + account.update(markUnreadArticles, statusKey: .read, flag: false) + + // Save any unread statuses for articles we haven't yet received + let markUnreadArticleIDs = Set(markUnreadArticles.map { $0.articleID }) + let missingUnreadArticleIDs = deltaUnreadArticleIds.subtracting(markUnreadArticleIDs) + + group.enter() + account.ensureStatuses(missingUnreadArticleIDs, true, .read, false) { + group.leave() + } + + // Mark articles as read + let deltaReadArticleIds = localUnreadArticleIds.subtracting(remoteUnreadArticleIds) + let markReadArticles = account.fetchArticles(.articleIDs(deltaReadArticleIds)) + account.update(markReadArticles, statusKey: .read, flag: true) + + // Save any read statuses for articles we haven't yet received + let markReadArticleIDs = Set(markReadArticles.map { $0.articleID }) + let missingReadArticleIDs = deltaReadArticleIds.subtracting(markReadArticleIDs) + group.enter() + account.ensureStatuses(missingReadArticleIDs, true, .read, true) { + group.leave() + } + + group.notify(queue: .main, execute: didFinish) } } diff --git a/Frameworks/Account/Feedly/Operations/FeedlySyncAllOperation.swift b/Frameworks/Account/Feedly/Operations/FeedlySyncAllOperation.swift index 8acb5b8e9..9b58de533 100644 --- a/Frameworks/Account/Feedly/Operations/FeedlySyncAllOperation.swift +++ b/Frameworks/Account/Feedly/Operations/FeedlySyncAllOperation.swift @@ -35,13 +35,6 @@ final class FeedlySyncAllOperation: FeedlyOperation { sendArticleStatuses.downloadProgress = downloadProgress self.operationQueue.addOperation(sendArticleStatuses) - // Get each page of unread article ids in the global.all stream for the last 31 days (nil = Feedly API default). - let getUnread = FeedlySyncUnreadStatusesOperation(account: account, credentials: credentials, service: getUnreadService, newerThan: nil, log: log) - getUnread.delegate = self - getUnread.addDependency(sendArticleStatuses) - getUnread.downloadProgress = downloadProgress - self.operationQueue.addOperation(getUnread) - // Get all the Collections the user has. let getCollections = FeedlyGetCollectionsOperation(service: getCollectionsService, log: log) getCollections.delegate = self @@ -61,13 +54,18 @@ final class FeedlySyncAllOperation: FeedlyOperation { createFeedsOperation.addDependency(mirrorCollectionsAsFolders) self.operationQueue.addOperation(createFeedsOperation) + // Get each page of unread article ids in the global.all stream for the last 31 days (nil = Feedly API default). + let getUnread = FeedlySyncUnreadStatusesOperation(account: account, credentials: credentials, service: getUnreadService, newerThan: nil, log: log) + getUnread.delegate = self + getUnread.addDependency(createFeedsOperation) + getUnread.downloadProgress = downloadProgress + self.operationQueue.addOperation(getUnread) + // Get each page of the global.all stream until we get either the content from the last sync or the last 31 days. let getStreamContents = FeedlySyncStreamContentsOperation(account: account, credentials: credentials, service: getStreamContentsService, newerThan: lastSuccessfulFetchStartDate, log: log) getStreamContents.delegate = self getStreamContents.downloadProgress = downloadProgress - getStreamContents.addDependency(getCollections) getStreamContents.addDependency(getUnread) - getStreamContents.addDependency(createFeedsOperation) self.operationQueue.addOperation(getStreamContents) // Get each and every starred article. diff --git a/NetNewsWire.xcodeproj/xcshareddata/xcschemes/NetNewsWire.xcscheme b/NetNewsWire.xcodeproj/xcshareddata/xcschemes/NetNewsWire.xcscheme index 71944f145..3e3ec99e6 100644 --- a/NetNewsWire.xcodeproj/xcshareddata/xcschemes/NetNewsWire.xcscheme +++ b/NetNewsWire.xcodeproj/xcshareddata/xcschemes/NetNewsWire.xcscheme @@ -55,6 +55,26 @@ BlueprintName = "AccountTests" ReferencedContainer = "container:Frameworks/Account/Account.xcodeproj"> + + + + + + + + + + + + + +