Skip to content

Commit

Permalink
Add test_loadOriginAddresses_returns_addresses_on_success and test_lo…
Browse files Browse the repository at this point in the history
…adOriginAddresses_returns_error_failure
  • Loading branch information
bozidarsevo committed Dec 20, 2024
1 parent 261ad63 commit 55c1bb5
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Fakes/Fakes/Networking.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2864,6 +2864,26 @@ extension Networking.WooShippingSavedPredefinedPackage {
)
}
}
extension Networking.WooShippingOriginAddress {
/// Returns a "ready to use" type filled with fake values.
///
public static func fake() -> Networking.WooShippingOriginAddress {
.init(id: .fake(),
company: .fake(),
address1: .fake(),
address2: .fake(),
city: .fake(),
state: .fake(),
postcode: .fake(),
country: .fake(),
phone: .fake(),
firstName: .fake(),
lastName: .fake(),
email: .fake(),
defaultAddress: .fake(),
isVerified: .fake())
}
}
extension Networking.WordPressMedia {
/// Returns a "ready to use" type filled with fake values.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,37 @@ public struct WooShippingOriginAddress: Equatable, GeneratedFakeable, GeneratedC
public let email: String
public let defaultAddress: Bool
public let isVerified: Bool

public init(id: String,
company: String,
address1: String,
address2: String,
city: String,
state: String,
postcode: String,
country: String,
phone: String,
firstName: String,
lastName: String,
email: String,
defaultAddress:
Bool,
isVerified: Bool) {
self.id = id
self.company = company
self.address1 = address1
self.address2 = address2
self.city = city
self.state = state
self.postcode = postcode
self.country = country
self.phone = phone
self.firstName = firstName
self.lastName = lastName
self.email = email
self.defaultAddress = defaultAddress
self.isVerified = isVerified
}
}

// MARK: Decodable
Expand Down
46 changes: 46 additions & 0 deletions Yosemite/YosemiteTests/Stores/WooShippingStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,52 @@ final class WooShippingStoreTests: XCTestCase {
// Then
XCTAssertEqual(error as? NetworkError, expectedError)
}

func test_loadOriginAddresses_returns_addresses_on_success() {
// Given
let expectedAddresses: [WooShippingOriginAddress] = [WooShippingOriginAddress.fake()]
let remote = MockWooShippingRemote()
remote.whenOriginAddresses(siteID: sampleSiteID, thenReturn: .success(expectedAddresses))
let store = WooShippingStore(dispatcher: dispatcher, storageManager: storageManager, network: network, remote: remote)

// When
let addresses: [WooShippingOriginAddress] = waitFor { promise in
let action = WooShippingAction.loadOriginAddresses(siteID: self.sampleSiteID) { result in
guard let printData = try? result.get() else {
XCTFail("Error loading origin addresses for shipping label: \(String(describing: result.failure))")
return
}
promise(printData)
}
store.onAction(action)
}

// Then
XCTAssertEqual(addresses, expectedAddresses)
}

func test_loadOriginAddresses_returns_error_failure() {
// Given
let expectedError = NetworkError.timeout()
let remote = MockWooShippingRemote()
remote.whenOriginAddresses(siteID: sampleSiteID, thenReturn: .failure(expectedError))
let store = WooShippingStore(dispatcher: dispatcher, storageManager: storageManager, network: network, remote: remote)

// When
let error: Error = waitFor { promise in
let action = WooShippingAction.loadOriginAddresses(siteID: self.sampleSiteID) { result in
guard let printData = result.failure else {
XCTFail("Unexpected result when printing shipping label: \(result)")
return
}
promise(printData)
}
store.onAction(action)
}

// Then
XCTAssertEqual(error as? NetworkError, expectedError)
}
}

private extension WooShippingStoreTests {
Expand Down

0 comments on commit 55c1bb5

Please sign in to comment.