Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Fakes/Fakes/Networking.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,8 @@ extension Networking.OrderStatsV4Totals {
taxes: .fake(),
shipping: .fake(),
netRevenue: .fake(),
totalProducts: .fake()
totalProducts: .fake(),
averageOrderValue: .fake()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,8 @@ extension Networking.OrderStatsV4Totals {
taxes: CopiableProp<Decimal> = .copy,
shipping: CopiableProp<Decimal> = .copy,
netRevenue: CopiableProp<Decimal> = .copy,
totalProducts: NullableCopiableProp<Int> = .copy
totalProducts: NullableCopiableProp<Int> = .copy,
averageOrderValue: CopiableProp<Decimal> = .copy
) -> Networking.OrderStatsV4Totals {
let totalOrders = totalOrders ?? self.totalOrders
let totalItemsSold = totalItemsSold ?? self.totalItemsSold
Expand All @@ -741,6 +742,7 @@ extension Networking.OrderStatsV4Totals {
let shipping = shipping ?? self.shipping
let netRevenue = netRevenue ?? self.netRevenue
let totalProducts = totalProducts ?? self.totalProducts
let averageOrderValue = averageOrderValue ?? self.averageOrderValue

return Networking.OrderStatsV4Totals(
totalOrders: totalOrders,
Expand All @@ -752,7 +754,8 @@ extension Networking.OrderStatsV4Totals {
taxes: taxes,
shipping: shipping,
netRevenue: netRevenue,
totalProducts: totalProducts
totalProducts: totalProducts,
averageOrderValue: averageOrderValue
)
}
}
Expand Down
10 changes: 8 additions & 2 deletions Networking/Networking/Model/Stats/OrderStatsV4Totals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public struct OrderStatsV4Totals: Decodable, Equatable, GeneratedCopiable, Gener
public let shipping: Decimal
public let netRevenue: Decimal
public let totalProducts: Int?
public let averageOrderValue: Decimal

public init(totalOrders: Int,
totalItemsSold: Int,
Expand All @@ -23,7 +24,8 @@ public struct OrderStatsV4Totals: Decodable, Equatable, GeneratedCopiable, Gener
taxes: Decimal,
shipping: Decimal,
netRevenue: Decimal,
totalProducts: Int?) {
totalProducts: Int?,
averageOrderValue: Decimal) {
self.totalOrders = totalOrders
self.totalItemsSold = totalItemsSold
self.grossRevenue = grossRevenue
Expand All @@ -34,6 +36,7 @@ public struct OrderStatsV4Totals: Decodable, Equatable, GeneratedCopiable, Gener
self.shipping = shipping
self.netRevenue = netRevenue
self.totalProducts = totalProducts
self.averageOrderValue = averageOrderValue
}

public init(from decoder: Decoder) throws {
Expand All @@ -48,6 +51,7 @@ public struct OrderStatsV4Totals: Decodable, Equatable, GeneratedCopiable, Gener
let shipping = try container.decode(Decimal.self, forKey: .shipping)
let netRevenue = try container.decode(Decimal.self, forKey: .netRevenue)
let totalProducts = try container.decodeIfPresent(Int.self, forKey: .products)
let averageOrderValue = try container.decode(Decimal.self, forKey: .averageOrderValue)

self.init(totalOrders: totalOrders,
totalItemsSold: totalItemsSold,
Expand All @@ -58,7 +62,8 @@ public struct OrderStatsV4Totals: Decodable, Equatable, GeneratedCopiable, Gener
taxes: taxes,
shipping: shipping,
netRevenue: netRevenue,
totalProducts: totalProducts)
totalProducts: totalProducts,
averageOrderValue: averageOrderValue)
}
}

Expand All @@ -77,5 +82,6 @@ private extension OrderStatsV4Totals {
case shipping
case netRevenue = "net_revenue"
case products
case averageOrderValue = "avg_order_value"
}
}
10 changes: 10 additions & 0 deletions Networking/NetworkingTests/Mapper/OrderStatsMapperV4Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ final class OrderStatsV4MapperTests: XCTestCase {
XCTAssertEqual(hourlyStats.totals.shipping, 0)
XCTAssertEqual(hourlyStats.totals.netRevenue, 800)
XCTAssertEqual(hourlyStats.totals.totalProducts, 2)
XCTAssertEqual(hourlyStats.totals.averageOrderValue, 266)

XCTAssertEqual(hourlyStats.intervals.count, 24)

Expand All @@ -47,6 +48,7 @@ final class OrderStatsV4MapperTests: XCTestCase {
XCTAssertEqual(nonZeroHourTotals.shipping, 0)
XCTAssertEqual(nonZeroHourTotals.netRevenue, 350)
XCTAssertNil(nonZeroHourTotals.totalProducts)
XCTAssertEqual(nonZeroHourTotals.averageOrderValue, 175)
}

/// Verifies that all of the daily unit OrderStatsV4 fields are parsed correctly.
Expand All @@ -70,6 +72,7 @@ final class OrderStatsV4MapperTests: XCTestCase {
XCTAssertEqual(dailyStats.totals.shipping, 0)
XCTAssertEqual(dailyStats.totals.netRevenue, 800)
XCTAssertEqual(dailyStats.totals.totalProducts, 2)
XCTAssertEqual(dailyStats.totals.averageOrderValue, 266)

XCTAssertEqual(dailyStats.intervals.count, 1)

Expand All @@ -87,6 +90,7 @@ final class OrderStatsV4MapperTests: XCTestCase {
XCTAssertEqual(nonZeroDayTotals.shipping, 0)
XCTAssertEqual(nonZeroDayTotals.netRevenue, 800)
XCTAssertNil(nonZeroDayTotals.totalProducts)
XCTAssertEqual(nonZeroDayTotals.averageOrderValue, 266)
}

/// Verifies that all of the weekly unit OrderStatsV4 fields are parsed correctly.
Expand All @@ -110,6 +114,7 @@ final class OrderStatsV4MapperTests: XCTestCase {
XCTAssertEqual(weeklyStats.totals.shipping, 0)
XCTAssertEqual(weeklyStats.totals.netRevenue, 800)
XCTAssertEqual(weeklyStats.totals.totalProducts, 2)
XCTAssertEqual(weeklyStats.totals.averageOrderValue, 266)

XCTAssertEqual(weeklyStats.intervals.count, 2)

Expand All @@ -127,6 +132,7 @@ final class OrderStatsV4MapperTests: XCTestCase {
XCTAssertEqual(nonZeroWeekTotals.shipping, 0)
XCTAssertEqual(nonZeroWeekTotals.netRevenue, 800)
XCTAssertNil(nonZeroWeekTotals.totalProducts)
XCTAssertEqual(nonZeroWeekTotals.averageOrderValue, 266)
}

/// Verifies that all of the monthly unit OrderStatsV4 fields are parsed correctly.
Expand All @@ -150,6 +156,7 @@ final class OrderStatsV4MapperTests: XCTestCase {
XCTAssertEqual(monthlyStats.totals.shipping, 0)
XCTAssertEqual(monthlyStats.totals.netRevenue, 800)
XCTAssertEqual(monthlyStats.totals.totalProducts, 2)
XCTAssertEqual(monthlyStats.totals.averageOrderValue, 266)

XCTAssertEqual(monthlyStats.intervals.count, 1)

Expand All @@ -167,6 +174,7 @@ final class OrderStatsV4MapperTests: XCTestCase {
XCTAssertEqual(nonZeroMonthTotals.shipping, 0)
XCTAssertEqual(nonZeroMonthTotals.netRevenue, 800)
XCTAssertNil(nonZeroMonthTotals.totalProducts)
XCTAssertEqual(nonZeroMonthTotals.averageOrderValue, 266)
}

/// Verifies that all of the yearly unit OrderStatsV4 fields are parsed correctly.
Expand All @@ -190,6 +198,7 @@ final class OrderStatsV4MapperTests: XCTestCase {
XCTAssertEqual(yearlyStats.totals.shipping, 0)
XCTAssertEqual(yearlyStats.totals.netRevenue, 800)
XCTAssertEqual(yearlyStats.totals.totalProducts, 2)
XCTAssertEqual(yearlyStats.totals.averageOrderValue, 266)

XCTAssertEqual(yearlyStats.intervals.count, 1)

Expand All @@ -207,6 +216,7 @@ final class OrderStatsV4MapperTests: XCTestCase {
XCTAssertEqual(nonZeroYearTotals.shipping, 0)
XCTAssertEqual(nonZeroYearTotals.netRevenue, 800)
XCTAssertNil(nonZeroYearTotals.totalProducts)
XCTAssertEqual(nonZeroYearTotals.averageOrderValue, 266)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"shipping": 0,
"net_revenue": 800,
"products": 2,
"avg_order_value": 266,
"segments": []
},
"intervals": [
Expand All @@ -30,6 +31,7 @@
"taxes": 0,
"shipping": 0,
"net_revenue": 800,
"avg_order_value": 266,
"segments": []
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"taxes": 0,
"shipping": 0,
"net_revenue": 800,
"avg_order_value": 266,
"products": 2,
"segments": []
},
Expand All @@ -30,6 +31,7 @@
"taxes": 0,
"shipping": 0,
"net_revenue": 800,
"avg_order_value": 266,
"segments": []
}
},
Expand All @@ -49,6 +51,7 @@
"taxes": 0,
"shipping": 0,
"net_revenue": 0,
"avg_order_value": 0,
"segments": []
}
}
Expand Down
Loading