Created
March 28, 2020 12:58
-
-
Save tedgonzalez/10ae417529d7cefd2868230ef47915ca to your computer and use it in GitHub Desktop.
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": [ | |
| { | |
| "name": "Pizza", | |
| "cost": "100" | |
| } | |
| ] | |
| } | |
| }, | |
| { | |
| "passenger": { | |
| "carType": { | |
| "name": "SUV", | |
| "distanceFare": "1.00", | |
| "timeFare": "1.00" | |
| }, | |
| "date": "2020-01-01", | |
| "distance": "2 km", | |
| "time": "10 min", | |
| "totalCost": "8.00" | |
| } | |
| }, | |
| { | |
| "package": { | |
| "date": "2020-01-01", | |
| "totalCost": "8.00", | |
| "weight": "1 kg", | |
| "size": "SMALL" | |
| } | |
| } | |
| ] | |
| """#.data(using: .utf8)! | |
| let result = try decoder.decode([OrderItem].self, from: givenJsonData) | |
| let expected: [OrderItem] = [ | |
| OrderItem.food(FoodDelivery( | |
| date: "2020-01-01", | |
| orders: [ | |
| FoodDelivery.Order(name: "Pizza", cost: "100") | |
| ], | |
| restaurantName: "Restaurant", | |
| totalCost: "8.00" | |
| )), | |
| OrderItem.passenger(PassengerDelivery( | |
| carType: PassengerDelivery.CarType( | |
| name: "SUV", | |
| distanceFare: "1.00", | |
| timeFare: "1.00" | |
| ), | |
| date: "2020-01-01", | |
| distance: "2 km", | |
| time: "10 min", | |
| totalCost: "8.00" | |
| )), | |
| OrderItem.package(PackageDelivery( | |
| date: "2020-01-01", | |
| size: "SMALL", | |
| totalCost: "8.00", | |
| weight: "1 kg" | |
| )) | |
| ] | |
| XCTAssertEqual(result, expected) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment