Fix errors in Feedly set starred operations tests

More of the same: completion blocks which take Results need
do/catch/Result.get().
This commit is contained in:
Tim Ekl
2019-12-31 19:23:12 -06:00
parent f12e8b4a4a
commit 13b227a461

View File

@@ -49,10 +49,15 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase {
waitForExpectations(timeout: 2) waitForExpectations(timeout: 2)
let fetchIdsExpectation = expectation(description: "Fetch Article Ids") let fetchIdsExpectation = expectation(description: "Fetch Article Ids")
account.fetchStarredArticleIDs { accountArticlesIDs in account.fetchStarredArticleIDs { accountArticlesIDsResult in
XCTAssertTrue(accountArticlesIDs.isEmpty) do {
XCTAssertEqual(accountArticlesIDs, testIds) let accountArticlesIDs = try accountArticlesIDsResult.get()
fetchIdsExpectation.fulfill() XCTAssertTrue(accountArticlesIDs.isEmpty)
XCTAssertEqual(accountArticlesIDs, testIds)
fetchIdsExpectation.fulfill()
} catch let e {
XCTFail("Error checking articles IDs: \(e)")
}
} }
waitForExpectations(timeout: 2) waitForExpectations(timeout: 2)
} }
@@ -73,9 +78,14 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase {
waitForExpectations(timeout: 2) waitForExpectations(timeout: 2)
let fetchIdsExpectation = expectation(description: "Fetch Article Ids") let fetchIdsExpectation = expectation(description: "Fetch Article Ids")
account.fetchStarredArticleIDs { accountArticlesIDs in account.fetchStarredArticleIDs { accountArticlesIDsResult in
XCTAssertEqual(accountArticlesIDs.count, testIds.count) do {
fetchIdsExpectation.fulfill() let accountArticlesIDs = try accountArticlesIDsResult.get()
XCTAssertEqual(accountArticlesIDs.count, testIds.count)
fetchIdsExpectation.fulfill()
} catch let e {
XCTFail("Error checking articles IDs: \(e)")
}
} }
waitForExpectations(timeout: 2) waitForExpectations(timeout: 2)
} }
@@ -96,9 +106,14 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase {
waitForExpectations(timeout: 2) waitForExpectations(timeout: 2)
let fetchIdsExpectation = expectation(description: "Fetch Article Ids") let fetchIdsExpectation = expectation(description: "Fetch Article Ids")
account.fetchStarredArticleIDs { accountArticlesIDs in account.fetchStarredArticleIDs { accountArticlesIDsResult in
XCTAssertEqual(accountArticlesIDs.count, testIds.count) do {
fetchIdsExpectation.fulfill() let accountArticlesIDs = try accountArticlesIDsResult.get()
XCTAssertEqual(accountArticlesIDs.count, testIds.count)
fetchIdsExpectation.fulfill()
} catch let e {
XCTFail("Error checking articles IDs: \(e)")
}
} }
waitForExpectations(timeout: 2) waitForExpectations(timeout: 2)
} }
@@ -134,9 +149,14 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase {
waitForExpectations(timeout: 2) waitForExpectations(timeout: 2)
let fetchIdsExpectation = expectation(description: "Fetch Article Ids") let fetchIdsExpectation = expectation(description: "Fetch Article Ids")
account.fetchStarredArticleIDs { remainingAccountArticlesIDs in account.fetchStarredArticleIDs { remainingAccountArticlesIDsResult in
XCTAssertEqual(remainingAccountArticlesIDs, remainingStarredIds) do {
fetchIdsExpectation.fulfill() let remainingAccountArticlesIDs = try remainingAccountArticlesIDsResult.get()
XCTAssertEqual(remainingAccountArticlesIDs, remainingStarredIds)
fetchIdsExpectation.fulfill()
} catch let e {
XCTFail("Error checking articles IDs: \(e)")
}
} }
waitForExpectations(timeout: 2) waitForExpectations(timeout: 2)
} }
@@ -172,9 +192,14 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase {
waitForExpectations(timeout: 2) waitForExpectations(timeout: 2)
let fetchIdsExpectation = expectation(description: "Fetch Article Ids") let fetchIdsExpectation = expectation(description: "Fetch Article Ids")
account.fetchStarredArticleIDs { remainingAccountArticlesIDs in account.fetchStarredArticleIDs { remainingAccountArticlesIDsResult in
XCTAssertEqual(remainingAccountArticlesIDs, remainingStarredIds) do {
fetchIdsExpectation.fulfill() let remainingAccountArticlesIDs = try remainingAccountArticlesIDsResult.get()
XCTAssertEqual(remainingAccountArticlesIDs, remainingStarredIds)
fetchIdsExpectation.fulfill()
} catch let e {
XCTFail("Error checking articles IDs: \(e)")
}
} }
waitForExpectations(timeout: 2) waitForExpectations(timeout: 2)
} }
@@ -221,15 +246,20 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase {
waitForExpectations(timeout: 2) waitForExpectations(timeout: 2)
let fetchIdsExpectation = expectation(description: "Fetch Article Ids") let fetchIdsExpectation = expectation(description: "Fetch Article Ids")
account.fetchStarredArticleIDs { accountArticlesIDs in account.fetchStarredArticleIDs { accountArticlesIDsResult in
XCTAssertEqual(accountArticlesIDs, remainingStarredIds) do {
let accountArticlesIDs = try accountArticlesIDsResult.get()
XCTAssertEqual(accountArticlesIDs, remainingStarredIds)
let idsOfStarredArticles = Set(self.account let idsOfStarredArticles = Set(try self.account
.fetchArticles(.articleIDs(remainingStarredIds)) .fetchArticles(.articleIDs(remainingStarredIds))
.filter { $0.status.boolStatus(forKey: .starred) == true } .filter { $0.status.boolStatus(forKey: .starred) == true }
.map { $0.articleID }) .map { $0.articleID })
XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) XCTAssertEqual(idsOfStarredArticles, remainingStarredIds)
} catch let e {
XCTFail("Error checking articles IDs: \(e)")
}
} }
waitForExpectations(timeout: 2) waitForExpectations(timeout: 2)
} }
@@ -274,15 +304,20 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase {
waitForExpectations(timeout: 2) waitForExpectations(timeout: 2)
let fetchIdsExpectation = expectation(description: "Fetch Article Ids") let fetchIdsExpectation = expectation(description: "Fetch Article Ids")
account.fetchStarredArticleIDs { accountArticlesIDs in account.fetchStarredArticleIDs { accountArticlesIDsResult in
XCTAssertEqual(accountArticlesIDs, remainingStarredIds) do {
let accountArticlesIDs = try accountArticlesIDsResult.get()
XCTAssertEqual(accountArticlesIDs, remainingStarredIds)
let idsOfStarredArticles = Set(self.account let idsOfStarredArticles = Set(try self.account
.fetchArticles(.articleIDs(remainingStarredIds)) .fetchArticles(.articleIDs(remainingStarredIds))
.filter { $0.status.boolStatus(forKey: .starred) == true } .filter { $0.status.boolStatus(forKey: .starred) == true }
.map { $0.articleID }) .map { $0.articleID })
XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) XCTAssertEqual(idsOfStarredArticles, remainingStarredIds)
} catch let e {
XCTFail("Error checking articles IDs: \(e)")
}
} }
waitForExpectations(timeout: 2) waitForExpectations(timeout: 2)
} }
@@ -321,16 +356,21 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase {
waitForExpectations(timeout: 2) waitForExpectations(timeout: 2)
let fetchIdsExpectation = expectation(description: "Fetch Article Ids") let fetchIdsExpectation = expectation(description: "Fetch Article Ids")
account.fetchStarredArticleIDs { accountArticlesIDs in account.fetchStarredArticleIDs { accountArticlesIDsResult in
XCTAssertEqual(accountArticlesIDs, remainingStarredIds) do {
let accountArticlesIDs = try accountArticlesIDsResult.get()
XCTAssertEqual(accountArticlesIDs, remainingStarredIds)
let idsOfStarredArticles = Set(self.account let idsOfStarredArticles = Set(try self.account
.fetchArticles(.articleIDs(remainingStarredIds)) .fetchArticles(.articleIDs(remainingStarredIds))
.filter { $0.status.boolStatus(forKey: .starred) == true } .filter { $0.status.boolStatus(forKey: .starred) == true }
.map { $0.articleID }) .map { $0.articleID })
XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) XCTAssertEqual(idsOfStarredArticles, remainingStarredIds)
fetchIdsExpectation.fulfill() fetchIdsExpectation.fulfill()
} catch let e {
XCTFail("Error checking articles IDs: \(e)")
}
} }
waitForExpectations(timeout: 2) waitForExpectations(timeout: 2)
} }
@@ -368,16 +408,21 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase {
waitForExpectations(timeout: 2) waitForExpectations(timeout: 2)
let fetchIdsExpectation = expectation(description: "Fetch Article Ids") let fetchIdsExpectation = expectation(description: "Fetch Article Ids")
account.fetchStarredArticleIDs { accountArticlesIDs in account.fetchStarredArticleIDs { accountArticlesIDsResult in
XCTAssertEqual(accountArticlesIDs, remainingStarredIds) do {
let accountArticlesIDs = try accountArticlesIDsResult.get()
XCTAssertEqual(accountArticlesIDs, remainingStarredIds)
let idsOfStarredArticles = Set(self.account let idsOfStarredArticles = Set(try self.account
.fetchArticles(.articleIDs(remainingStarredIds)) .fetchArticles(.articleIDs(remainingStarredIds))
.filter { $0.status.boolStatus(forKey: .starred) == true } .filter { $0.status.boolStatus(forKey: .starred) == true }
.map { $0.articleID }) .map { $0.articleID })
XCTAssertEqual(idsOfStarredArticles, remainingStarredIds) XCTAssertEqual(idsOfStarredArticles, remainingStarredIds)
fetchIdsExpectation.fulfill() fetchIdsExpectation.fulfill()
} catch let e {
XCTFail("Error checking articles IDs: \(e)")
}
} }
waitForExpectations(timeout: 2) waitForExpectations(timeout: 2)
} }
@@ -418,19 +463,24 @@ class FeedlySetStarredArticlesOperationTests: XCTestCase {
waitForExpectations(timeout: 2) waitForExpectations(timeout: 2)
let fetchIdsExpectation = expectation(description: "Fetch Article Ids") let fetchIdsExpectation = expectation(description: "Fetch Article Ids")
account.fetchStarredArticleIDs { accountArticlesIDs in account.fetchStarredArticleIDs { accountArticlesIDsResult in
XCTAssertEqual(accountArticlesIDs, remainingStarredIds) do {
let accountArticlesIDs = try accountArticlesIDsResult.get()
XCTAssertEqual(accountArticlesIDs, remainingStarredIds)
let someTestItems = Set(someItemsAndFeeds.flatMap { $0.value }) let someTestItems = Set(someItemsAndFeeds.flatMap { $0.value })
let someRemainingStarredIdsOfIngestedArticles = Set(someTestItems.compactMap { $0.syncServiceID }) let someRemainingStarredIdsOfIngestedArticles = Set(someTestItems.compactMap { $0.syncServiceID })
let idsOfStarredArticles = Set(self.account let idsOfStarredArticles = Set(try self.account
.fetchArticles(.articleIDs(someRemainingStarredIdsOfIngestedArticles)) .fetchArticles(.articleIDs(someRemainingStarredIdsOfIngestedArticles))
.filter { $0.status.boolStatus(forKey: .starred) == true } .filter { $0.status.boolStatus(forKey: .starred) == true }
.map { $0.articleID }) .map { $0.articleID })
XCTAssertEqual(idsOfStarredArticles, someRemainingStarredIdsOfIngestedArticles) XCTAssertEqual(idsOfStarredArticles, someRemainingStarredIdsOfIngestedArticles)
fetchIdsExpectation.fulfill() fetchIdsExpectation.fulfill()
} catch let e {
XCTFail("Error checking articles IDs: \(e)")
}
} }
waitForExpectations(timeout: 2) waitForExpectations(timeout: 2)
} }