Skip to content

Commit a3d03a6

Browse files
committed
Do not use mock in a CommentService unit test
1 parent 876b975 commit a3d03a6

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

WordPress/WordPressTest/BlockEditorSettingsServiceTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ extension BlockEditorSettingsServiceTests {
387387
service.fetchSettings { _ in
388388
waitExpectation.fulfill()
389389
}
390-
waitForExpectations(timeout: expectationTimeout)
390+
wait(for: [waitExpectation], timeout: expectationTimeout)
391391
HTTPStubs.removeStub(descriptor)
392392
}
393393
}

WordPress/WordPressTest/CommentService+RepliesTests.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,22 @@ final class CommentService_RepliesTests: CoreDataTestCase {
8686
}
8787

8888
func test_getReplies_addsCommentIdInParameter() {
89-
let (mockService, mockApi) = makeMockService()
89+
var request: URLRequest?
90+
stub(condition: { $0.url?.absoluteString.contains("/wp/v2/sites/\(self.siteID)/comments") == true }) {
91+
request = $0
92+
return HTTPStubsResponse(error: URLError(.networkConnectionLost))
93+
}
94+
9095
let parentKey = CommentServiceRemoteREST.RequestKeys.parent.rawValue
9196

92-
mockService.getLatestReplyID(for: commentID,
97+
self.commentService.getLatestReplyID(for: commentID,
9398
siteID: siteID,
9499
accountService: accountService,
95100
success: { _ in },
96101
failure: { _ in })
97102

98-
var parameters = [String: Any]()
99-
expect(mockApi.parametersPassedIn).toNot(beNil())
100-
expect { parameters = mockApi.parametersPassedIn! as! [String: Any] }.toNot(throwError())
101-
expect(parameters[parentKey] as? Int).to(equal(commentID))
103+
expect(request).toNotEventually(beNil())
104+
expect(request?.url?.query).to(contain("parent=\(commentID)"))
102105
}
103106

104107
func test_replyToPost_givenSuccessfulAPICall_insertsNewComment() throws {

0 commit comments

Comments
 (0)