From 65631ae87f72f35955a22f63234c140ec4508419 Mon Sep 17 00:00:00 2001 From: David Christiandy <1299411+dvdchr@users.noreply.github.com> Date: Wed, 12 Jul 2023 23:24:33 +0700 Subject: [PATCH] Add tests --- .../JetpackSocialServiceTests.swift | 66 +++++++++++++++---- 1 file changed, 54 insertions(+), 12 deletions(-) diff --git a/WordPress/WordPressTest/JetpackSocialServiceTests.swift b/WordPress/WordPressTest/JetpackSocialServiceTests.swift index 5054b11b1187..579e4249d56f 100644 --- a/WordPress/WordPressTest/JetpackSocialServiceTests.swift +++ b/WordPress/WordPressTest/JetpackSocialServiceTests.swift @@ -60,9 +60,7 @@ class JetpackSocialServiceTests: CoreDataTestCase { // non-existing PublicizeInfo + nil RemotePublicizeInfo -> nothing changes func testSyncSharingLimitWithNilPublicizeInfo() { stub(condition: isPath(jetpackSocialPath)) { _ in - HTTPStubsResponse(jsonObject: [String: Any](), - statusCode: 200, - headers: nil) + HTTPStubsResponse(jsonObject: [String: Any](), statusCode: 200, headers: nil) } let expectation = expectation(description: "syncSharingLimit should succeed") @@ -110,9 +108,7 @@ class JetpackSocialServiceTests: CoreDataTestCase { func testSyncSharingLimitWithNilPublicizeInfoGivenPreExistingData() throws { try addPreExistingPublicizeInfo() stub(condition: isPath(jetpackSocialPath)) { _ in - HTTPStubsResponse(jsonObject: [String: Any](), - statusCode: 200, - headers: nil) + HTTPStubsResponse(jsonObject: [String: Any](), statusCode: 200, headers: nil) } let expectation = expectation(description: "syncSharingLimit should succeed") @@ -133,9 +129,7 @@ class JetpackSocialServiceTests: CoreDataTestCase { func testSyncSharingLimitWithNewPublicizeInfoGivenInvalidBlogID() { let invalidBlogID = 1002 stub(condition: isPath("/wpcom/v2/sites/\(invalidBlogID)/jetpack-social")) { _ in - HTTPStubsResponse(jsonObject: [String: Any](), - statusCode: 200, - headers: nil) + HTTPStubsResponse(jsonObject: [String: Any](), statusCode: 200, headers: nil) } let expectation = expectation(description: "syncSharingLimit should fail") @@ -154,9 +148,7 @@ class JetpackSocialServiceTests: CoreDataTestCase { func testSyncSharingLimitRemoteFetchFailure() { stub(condition: isPath(jetpackSocialPath)) { _ in - HTTPStubsResponse(jsonObject: [String: Any](), - statusCode: 500, - headers: nil) + HTTPStubsResponse(jsonObject: [String: Any](), statusCode: 500, headers: nil) } let expectation = expectation(description: "syncSharingLimit should fail") @@ -171,6 +163,56 @@ class JetpackSocialServiceTests: CoreDataTestCase { wait(for: [expectation], timeout: timeout) } + // MARK: syncSharingLimit Objective-C + + func testObjcSyncSharingLimitSuccess() async { + stub(condition: isPath(jetpackSocialPath)) { _ in + HTTPStubsResponse(jsonObject: [String: Any](), statusCode: 200, headers: nil) + } + + let syncSucceeded = await withCheckedContinuation { continuation in + service.syncSharingLimit(dotComID: NSNumber(value: blogID)) { + continuation.resume(returning: true) + } failure: { error in + continuation.resume(returning: false) + } + } + + XCTAssertTrue(syncSucceeded) + } + + func testObjcSyncSharingLimitNilIDFailure() async { + stub(condition: isPath(jetpackSocialPath)) { _ in + HTTPStubsResponse(jsonObject: [String: Any](), statusCode: 500, headers: nil) + } + + let syncSucceeded = await withCheckedContinuation { continuation in + service.syncSharingLimit(dotComID: NSNumber(value: blogID)) { + continuation.resume(returning: true) + } failure: { error in + continuation.resume(returning: false) + } + } + + XCTAssertFalse(syncSucceeded) + } + + func testObjcSyncSharingLimitRequestFailure() async { + stub(condition: isPath(jetpackSocialPath)) { _ in + HTTPStubsResponse(jsonObject: [String: Any](), statusCode: 500, headers: nil) + } + + let syncSucceeded = await withCheckedContinuation { continuation in + service.syncSharingLimit(dotComID: NSNumber(value: blogID)) { + continuation.resume(returning: true) + } failure: { error in + continuation.resume(returning: false) + } + } + + XCTAssertFalse(syncSucceeded) + } + } // MARK: - Helpers