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
| - restore_cache: | |
| key: 1-pods-{{ checksum "Podfile.lock" }} | |
| - run: | |
| name: Install CocoaPods | |
| command: | | |
| if [ ! -d "Pods" ] | |
| then | |
| curl https://cocoapods-specs.circleci.com/fetch-cocoapods-repo-from-s3.sh | bash -s cf | |
| bundle exec pod install | |
| fi |
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
| func testDecodingUnknownOrderItemsThrowsAnError() throws { | |
| let givenJsonData = #""" | |
| [ | |
| "unknownDelivery": "unknownValue" | |
| ] | |
| """#.data(using: .utf8)! | |
| XCTAssertThrowsError(try decoder.decode([OrderItem].self, from: givenJsonData)) | |
| } |
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
| func testDecodingFoodDeliveryWithoutRestaurantThrowsAnError() throws { | |
| let givenJsonData = #""" | |
| [ | |
| { | |
| "food": { | |
| "date": "2020-01-01", | |
| "totalCost": "8.00", | |
| "orders": [ | |
| { | |
| "name": "Pizza", |
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
| func testDecodingArrayWithPassengerDeliverySucceeds() throws { | |
| let givenJsonData = #""" | |
| [ | |
| { | |
| "food": { | |
| "date": "2020-01-01", | |
| "restaurantName": "Restaurant", | |
| "totalCost": "8.00", | |
| "orders": [ | |
| { |
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
| func testDecodingEmptyArraySucceeds() throws { | |
| let givenJsonData = #""" | |
| [] | |
| """#.data(using: .utf8)! | |
| let result = try decoder.decode([OrderItem].self, from: givenJsonData) | |
| let expected: [OrderItem] = [] | |
| XCTAssertEqual(result, expected) | |
| } |
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
| struct FoodDelivery: Codable, Equatable { | |
| struct Order: Codable, Equatable { | |
| let name: String | |
| let cost: String | |
| } | |
| let date: String | |
| let orders: [Order] | |
| let restaurantName: String | |
| let totalCost: String | |
| } |
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
| struct GenericOrderItem: Codable { | |
| // common between all the objects | |
| let date: String | |
| let totalCost: String | |
| let carType: PassengerDelivery.CarType? | |
| let restaurantName: String? | |
| let distance: String? | |
| let orders: [FoodDelivery.Order]? | |
| let size: String? |
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
| enum OrderItem: Decodable, Equatable { | |
| case food(FoodDelivery) | |
| case package(PackageDelivery) | |
| case passenger(PassengerDelivery) | |
| enum CodingKeys: CodingKey, CaseIterable { | |
| case food | |
| case package | |
| case passenger | |
| } |
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
| struct PackageDelivery: Codable, Equatable { | |
| let date: String | |
| let size: String | |
| let totalCost: String | |
| let weight: String | |
| } |
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
| struct PassengerDelivery: Codable, Equatable { | |
| struct CarType: Codable, Equatable { | |
| let name: String | |
| let distanceFare: String | |
| let timeFare: String | |
| } | |
| let carType: CarType | |
| let date: String | |
| let distance: String | |
| let time: String |
OlderNewer