2019-10-18 23:21:02 +02:00
|
|
|
//
|
|
|
|
// FeedlyOrganiseParsedItemsByFeedOperationTests.swift
|
|
|
|
// AccountTests
|
|
|
|
//
|
|
|
|
// Created by Kiel Gillard on 24/10/19.
|
|
|
|
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import XCTest
|
|
|
|
@testable import Account
|
2024-04-03 06:43:06 +02:00
|
|
|
import Parser
|
2019-10-18 23:21:02 +02:00
|
|
|
|
|
|
|
class FeedlyOrganiseParsedItemsByFeedOperationTests: XCTestCase {
|
|
|
|
|
|
|
|
private var account: Account!
|
|
|
|
private let support = FeedlyTestSupport()
|
|
|
|
|
|
|
|
override func setUp() {
|
|
|
|
super.setUp()
|
|
|
|
account = support.makeTestAccount()
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tearDown() {
|
|
|
|
if let account = account {
|
|
|
|
support.destroy(account)
|
|
|
|
}
|
|
|
|
super.tearDown()
|
|
|
|
}
|
|
|
|
|
|
|
|
struct TestParsedItemsProvider: FeedlyParsedItemProviding {
|
2020-01-09 06:24:47 +01:00
|
|
|
let parsedItemProviderName = "TestParsedItemsProvider"
|
2019-10-18 23:21:02 +02:00
|
|
|
var resource: FeedlyResourceId
|
|
|
|
var parsedEntries: Set<ParsedItem>
|
|
|
|
}
|
|
|
|
|
|
|
|
func testNoEntries() {
|
|
|
|
let entries = support.makeParsedItemTestDataFor(numberOfFeeds: 0, numberOfItemsInFeeds: 0)
|
|
|
|
let resource = FeedlyCategoryResourceId(id: "user/12345/category/6789")
|
|
|
|
let parsedEntries = Set(entries.values.flatMap { $0 })
|
|
|
|
let provider = TestParsedItemsProvider(resource: resource, parsedEntries: parsedEntries)
|
|
|
|
|
|
|
|
let organise = FeedlyOrganiseParsedItemsByFeedOperation(account: account, parsedItemProvider: provider, log: support.log)
|
|
|
|
|
|
|
|
let completionExpectation = expectation(description: "Did Finish")
|
2020-01-16 07:10:06 +01:00
|
|
|
organise.completionBlock = { _ in
|
2019-10-18 23:21:02 +02:00
|
|
|
completionExpectation.fulfill()
|
|
|
|
}
|
|
|
|
|
2020-08-04 19:43:29 +02:00
|
|
|
MainThreadOperationQueue.shared.add(organise)
|
2019-10-18 23:21:02 +02:00
|
|
|
|
|
|
|
waitForExpectations(timeout: 2)
|
|
|
|
|
|
|
|
let itemsAndFeedIds = organise.parsedItemsKeyedByFeedId
|
|
|
|
XCTAssertEqual(itemsAndFeedIds, entries)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testGroupsOneEntryByFeedId() {
|
|
|
|
let entries = support.makeParsedItemTestDataFor(numberOfFeeds: 1, numberOfItemsInFeeds: 1)
|
|
|
|
let resource = FeedlyCategoryResourceId(id: "user/12345/category/6789")
|
|
|
|
let parsedEntries = Set(entries.values.flatMap { $0 })
|
|
|
|
let provider = TestParsedItemsProvider(resource: resource, parsedEntries: parsedEntries)
|
|
|
|
|
|
|
|
let organise = FeedlyOrganiseParsedItemsByFeedOperation(account: account, parsedItemProvider: provider, log: support.log)
|
|
|
|
|
|
|
|
let completionExpectation = expectation(description: "Did Finish")
|
2020-01-16 07:10:06 +01:00
|
|
|
organise.completionBlock = { _ in
|
2019-10-18 23:21:02 +02:00
|
|
|
completionExpectation.fulfill()
|
|
|
|
}
|
|
|
|
|
2020-08-04 19:43:29 +02:00
|
|
|
MainThreadOperationQueue.shared.add(organise)
|
2019-10-18 23:21:02 +02:00
|
|
|
|
|
|
|
waitForExpectations(timeout: 2)
|
|
|
|
|
|
|
|
let itemsAndFeedIds = organise.parsedItemsKeyedByFeedId
|
|
|
|
XCTAssertEqual(itemsAndFeedIds, entries)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testGroupsManyEntriesByFeedId() {
|
|
|
|
let entries = support.makeParsedItemTestDataFor(numberOfFeeds: 100, numberOfItemsInFeeds: 100)
|
|
|
|
let resource = FeedlyCategoryResourceId(id: "user/12345/category/6789")
|
|
|
|
let parsedEntries = Set(entries.values.flatMap { $0 })
|
|
|
|
let provider = TestParsedItemsProvider(resource: resource, parsedEntries: parsedEntries)
|
|
|
|
|
|
|
|
let organise = FeedlyOrganiseParsedItemsByFeedOperation(account: account, parsedItemProvider: provider, log: support.log)
|
|
|
|
|
|
|
|
let completionExpectation = expectation(description: "Did Finish")
|
2020-01-16 07:10:06 +01:00
|
|
|
organise.completionBlock = { _ in
|
2019-10-18 23:21:02 +02:00
|
|
|
completionExpectation.fulfill()
|
|
|
|
}
|
|
|
|
|
2020-08-04 19:43:29 +02:00
|
|
|
MainThreadOperationQueue.shared.add(organise)
|
2019-10-18 23:21:02 +02:00
|
|
|
|
|
|
|
waitForExpectations(timeout: 2)
|
|
|
|
|
|
|
|
let itemsAndFeedIds = organise.parsedItemsKeyedByFeedId
|
|
|
|
XCTAssertEqual(itemsAndFeedIds, entries)
|
|
|
|
}
|
|
|
|
}
|