Skip to content

Commit

Permalink
Unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Iron-Ham committed Mar 12, 2024
1 parent 9509c7e commit 8feda09
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Tests/ApolloPaginationTests/GraphQLQueryPagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,35 @@ final class GraphQLQueryPagerTests: XCTestCase {
await fulfillment(of: [callbackExpectation, secondPageExpectation], timeout: 1)
}

func test_equatable() {
let pagerA = GraphQLQueryPager(pager: createPager(), transform: { previous, initial, next in
let allPages = previous + [initial] + next
return allPages.flatMap { data in
data.hero.friendsConnection.friends.map { $0.name }
}
})

let pagerB = GraphQLQueryPager(pager: createPager(), transform: { previous, initial, next in
let allPages = previous + [initial] + next
return allPages.flatMap { data in
data.hero.friendsConnection.friends.map { $0.name }
}
})

XCTAssertEqual(pagerA, pagerB)

pagerA._subject.send(.success((["Al-Khwarizmi", "Al-Jaziri", "Charles Babbage", "Ada Lovelace"], .cache)))
XCTAssertNotEqual(pagerA, pagerB)

pagerB._subject.send(.success((["Al-Khwarizmi", "Al-Jaziri", "Charles Babbage", "Ada Lovelace"], .cache)))
XCTAssertEqual(pagerA, pagerB)

pagerA._subject.send(.success((["Al-Khwarizmi", "Al-Jaziri", "Charles Babbage", "Ada Lovelace"], .fetch)))
XCTAssertNotEqual(pagerA, pagerB)

pagerB._subject.send(.success((["Al-Khwarizmi", "Al-Jaziri", "Charles Babbage", "Ada Lovelace"], .fetch)))
pagerA.reset()
XCTAssertEqual(pagerA, pagerB)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ extension GraphQLQueryPager: Equatable where Model: Equatable {
return leftValue == rightValue && leftSource == rightSource
case (.failure(let leftError), .failure(let rightError)):
return leftError.localizedDescription == rightError.localizedDescription
case (.none, .none):
return true
default:
return false
}
Expand Down

0 comments on commit 8feda09

Please sign in to comment.