Skip to content

Commit

Permalink
fix(pagination): fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bassrock committed Mar 10, 2023
1 parent 021569f commit d44acbe
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
7 changes: 0 additions & 7 deletions PocketKit/Sources/Sync/Source.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,11 @@ public protocol Source {
}

public extension Source {
func refreshSaves(completion: (() -> Void)?) {
self.refreshSaves(completion: completion)
}

func refreshSaves() {
self.refreshSaves(completion: nil)
}

func refreshArchive(completion: (() -> Void)?) {
self.refreshArchive(completion: completion)
}

func refreshArchive() {
self.refreshArchive(completion: nil)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class RefreshCoordinatorTests: XCTestCase {
taskScheduler.stubRegisterHandler { handler = $2; return true }
taskScheduler.stubSubmit { _ in }

source.stubRefreshSaves { _, completion in
source.stubRefreshSaves { completion in
completion?()
}

Expand All @@ -84,7 +84,7 @@ class RefreshCoordinatorTests: XCTestCase {
taskScheduler.stubRegisterHandler { handler = $2; return true }
taskScheduler.stubSubmit { _ in }

source.stubRefreshSaves { _, completion in
source.stubRefreshSaves { completion in
// completion callback never fires
}

Expand All @@ -105,8 +105,8 @@ class RefreshCoordinatorTests: XCTestCase {

func test_receivingAppWillEnterForegroundNotification_refreshesSource_andResolvesUnresolvedSavedItems() {
taskScheduler.stubRegisterHandler { _, _, _ in true }
source.stubRefreshSaves { _, _ in }
source.stubRefreshArchive { _, _ in }
source.stubRefreshSaves { _ in }
source.stubRefreshArchive { _ in }
source.stubResolveUnresolvedSavedItems { }

let coordinator = subject()
Expand All @@ -120,10 +120,10 @@ class RefreshCoordinatorTests: XCTestCase {
}

func test_coordinator_whenNoSession_doesNotRefreshSavesArchive() {
source.stubRefreshSaves { _, _ in
source.stubRefreshSaves { _ in
XCTFail("Should not fetch saves")
}
source.stubRefreshArchive { _, _ in
source.stubRefreshArchive { _ in
XCTFail("Should not fetch archive")
}
source.stubResolveUnresolvedSavedItems {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ class SavedItemsListViewModelTests: XCTestCase {
}

func test_refreshSaves_callsRetryImmediatelyOnSource() {
source.stubRefreshSaves { _, _ in }
source.stubRefreshSaves { _ in }
source.stubRetryImmediately { }

let viewModel = subject()
Expand Down
18 changes: 8 additions & 10 deletions PocketKit/Tests/PocketKitTests/Support/MockSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,26 @@ extension MockSource {
// MARK: - Refresh Saves
extension MockSource {
private static let refreshSaves = "refreshSaves"
typealias RefreshSavesImpl = (Int, (() -> Void)?) -> Void
typealias RefreshSavesImpl = ((() -> Void)?) -> Void

struct RefreshSavesCall {
let maxItems: Int
let completion: (() -> Void)?
}

func stubRefreshSaves(impl: @escaping RefreshSavesImpl) {
implementations[Self.refreshSaves] = impl
}

func refreshSaves(maxItems: Int, completion: (() -> Void)?) {
func refreshSaves(completion: (() -> Void)?) {
guard let impl = implementations[Self.refreshSaves] as? RefreshSavesImpl else {
fatalError("\(Self.self)#\(#function) has not been stubbed")
}

calls[Self.refreshSaves] = (calls[Self.refreshSaves] ?? []) + [
RefreshSavesCall(maxItems: maxItems, completion: completion)
RefreshSavesCall(completion: completion)
]

impl(maxItems, completion)
impl(completion)
}

func refreshSavesCall(at index: Int) -> RefreshSavesCall? {
Expand All @@ -92,27 +91,26 @@ extension MockSource {
// MARK: - Refresh Archive
extension MockSource {
private static let refreshArchive = "refreshArchive"
typealias RefreshArchiveImpl = (Int, (() -> Void)?) -> Void
typealias RefreshArchiveImpl = ((() -> Void)?) -> Void

struct RefreshArchiveCall {
let maxItems: Int
let completion: (() -> Void)?
}

func stubRefreshArchive(impl: @escaping RefreshArchiveImpl) {
implementations[Self.refreshArchive] = impl
}

func refreshArchive(maxItems: Int, completion: (() -> Void)?) {
func refreshArchive(completion: (() -> Void)?) {
guard let impl = implementations[Self.refreshArchive] as? RefreshArchiveImpl else {
fatalError("\(Self.self)#\(#function) has not been stubbed")
}

calls[Self.refreshArchive] = (calls[Self.refreshArchive] ?? []) + [
RefreshArchiveCall(maxItems: maxItems, completion: completion)
RefreshArchiveCall(completion: completion)
]

impl(maxItems, completion)
impl(completion)
}

func refreshArchiveCall(at index: Int) -> RefreshArchiveCall? {
Expand Down

0 comments on commit d44acbe

Please sign in to comment.