Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdchr committed Jul 12, 2023
1 parent 76078f7 commit 65631ae
Showing 1 changed file with 54 additions and 12 deletions.
66 changes: 54 additions & 12 deletions WordPress/WordPressTest/JetpackSocialServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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
Expand Down

0 comments on commit 65631ae

Please sign in to comment.