Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save tedgonzalez/10ae417529d7cefd2868230ef47915ca to your computer and use it in GitHub Desktop.

Select an option

Save tedgonzalez/10ae417529d7cefd2868230ef47915ca to your computer and use it in GitHub Desktop.
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