Last active
December 13, 2018 00:08
-
-
Save eyeezzi/d491a5a96ae920a1987e31743650a244 to your computer and use it in GitHub Desktop.
Testing Models
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
public struct Customer: RemoteModelType { | |
// public init(email: String? = nil, phone: String? = nil, firstName: String? = nil, ...) {} | |
public var billingAddress: Address? { | |
if var address = self.defaultAddress ?? self.addresses.first { | |
address.firstName = address.firstName ?? self.firstName | |
return address.isValidForBilling() ? address : nil | |
} | |
return nil | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
@testable import Shopify_POS | |
@testable import CheckoutSDK | |
class CustomerTests: XCTestCase { | |
func testBillingAddressReturnsFirstDefaultAddress() { | |
var address1 = Address.Fixtures.beverlyHillsAddress() | |
address1.isDefault = false | |
var defaultAddress = Address.Fixtures.beverlyHillsAddressWithValidBillingAddress() | |
defaultAddress.isDefault = true | |
var address3 = Address.Fixtures.beverlyHillsAddress() | |
address3.isDefault = true | |
var customer = Customer(customer: SHPCustomer.minimumFixture()) | |
customer.addresses = [address1, defaultAddress, address3] | |
XCTAssertEqual(customer.billingAddress!, defaultAddress) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment