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
4 changes: 3 additions & 1 deletion Storage/Storage.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@
CC6A054228770933002C144E /* OrderMetaData+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OrderMetaData+CoreDataProperties.swift"; sourceTree = "<group>"; };
CCBEBD3F27C68E660010C96F /* FeatureIcon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeatureIcon.swift; sourceTree = "<group>"; };
CCD2E70625DE9AAA00BD975D /* WooCommerceModelV45toV46.xcmappingmodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcmappingmodel; path = WooCommerceModelV45toV46.xcmappingmodel; sourceTree = "<group>"; };
CCF3209E2927EBEE002114B1 /* Model 78.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Model 78.xcdatamodel"; sourceTree = "<group>"; };
CE12FBE22220515600C59248 /* WooCommerceModelV9toV10.xcmappingmodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcmappingmodel; path = WooCommerceModelV9toV10.xcmappingmodel; sourceTree = "<group>"; };
CE3B7AD02225E62C0050FE4B /* OrderStatus+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OrderStatus+CoreDataClass.swift"; sourceTree = "<group>"; };
CE3B7AD12225E62C0050FE4B /* OrderStatus+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OrderStatus+CoreDataProperties.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1815,6 +1816,7 @@
DEC51AA4275B41BE009F3DF4 /* WooCommerce.xcdatamodeld */ = {
isa = XCVersionGroup;
children = (
CCF3209E2927EBEE002114B1 /* Model 78.xcdatamodel */,
AE7DF9FA2919023100C4D1ED /* Model 77.xcdatamodel */,
AEC4481B290853C300BAA299 /* Model 76.xcdatamodel */,
688908A328F8EB360081A07E /* Model 75.xcdatamodel */,
Expand Down Expand Up @@ -1893,7 +1895,7 @@
DEC51ADE275B41BE009F3DF4 /* Model 47.xcdatamodel */,
DEC51ADF275B41BE009F3DF4 /* Model 19.xcdatamodel */,
);
currentVersion = AE7DF9FA2919023100C4D1ED /* Model 77.xcdatamodel */;
currentVersion = CCF3209E2927EBEE002114B1 /* Model 78.xcdatamodel */;
path = WooCommerce.xcdatamodeld;
sourceTree = "<group>";
versionGroupType = wrapper.xcdatamodel;
Expand Down
4 changes: 4 additions & 0 deletions Storage/Storage/Model/MIGRATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

This file documents changes in the WCiOS Storage data model. Please explain any changes to the data model as well as any custom migrations.

## Model 78 (Release 11.4.0.0)
- @rachelmcr 2022-11-18
- Added `averageOrderValue` attribute to `OrderStatsV4Totals` entity.

## Model 77 (Release 11.2.0.0)
- @ealeksandrov 2022-11-07
- Added `frameNonce` attribute to `Site` entity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extension OrderStatsV4Totals {
@NSManaged public var shipping: NSDecimalNumber
@NSManaged public var netRevenue: NSDecimalNumber
@NSManaged public var totalProducts: Int64
@NSManaged public var averageOrderValue: NSDecimalNumber
@NSManaged public var interval: OrderStatsV4Interval?
@NSManaged public var stats: OrderStatsV4?
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>Model 77.xcdatamodel</string>
<string>Model 78.xcdatamodel</string>
</dict>
</plist>

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions Storage/StorageTests/CoreData/MigrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,34 @@ final class MigrationTests: XCTestCase {
let newFrameNonce = try XCTUnwrap(migratedSite.value(forKey: "frameNonce") as? String)
XCTAssertEqual(newFrameNonce, frameNonce)
}

func test_migrating_from_77_to_78_adds_averageOrderValue_attribute() throws {
// Given
let sourceContainer = try startPersistentContainer("Model 77")
let sourceContext = sourceContainer.viewContext

let orderStatsV4Totals = insertOrderStatsTotals(to: sourceContainer.viewContext)
try sourceContext.save()

XCTAssertNil(orderStatsV4Totals.entity.attributesByName["averageOrderValue"])

// When
let targetContainer = try migrate(sourceContainer, to: "Model 78")
let targetContext = targetContainer.viewContext

let migratedOrderStatsV4Totals = try XCTUnwrap(targetContext.first(entityName: "OrderStatsV4Totals"))
let defaultAverageOrderValue = try XCTUnwrap(migratedOrderStatsV4Totals.value(forKey: "averageOrderValue") as? Double)

let averageOrderValue = 123.45
migratedOrderStatsV4Totals.setValue(averageOrderValue, forKey: "averageOrderValue")

// Then
// Default value is 0.
XCTAssertEqual(defaultAverageOrderValue, 0)

let newAverageOrderValue = try XCTUnwrap(migratedOrderStatsV4Totals.value(forKey: "averageOrderValue") as? Double)
XCTAssertEqual(newAverageOrderValue, averageOrderValue)
}
}

// MARK: - Persistent Store Setup and Migrations
Expand Down Expand Up @@ -1891,6 +1919,22 @@ private extension MigrationTests {
])
}

@discardableResult
func insertOrderStatsTotals(to context: NSManagedObjectContext) -> NSManagedObject {
context.insert(entityName: "OrderStatsV4Totals", properties: [
"totalOrders": 3,
"totalItemsSold": 5,
"grossRevenue": 800,
"couponDiscount": 0,
"totalCoupons": 0,
"refunds": 0,
"taxes": 0,
"shipping": 0,
"netRevenue": 800,
"totalProducts": 2,
])
}

@discardableResult
func insertSiteVisitStats(to context: NSManagedObjectContext) -> NSManagedObject {
context.insert(entityName: "SiteVisitStats", properties: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extension Storage.OrderStatsV4Totals: ReadOnlyConvertible {
shipping = NSDecimalNumber(decimal: statsTotals.shipping)
netRevenue = NSDecimalNumber(decimal: statsTotals.netRevenue)
totalProducts = Int64(statsTotals.totalProducts ?? 0)
averageOrderValue = NSDecimalNumber(decimal: statsTotals.averageOrderValue)
}

/// Returns a ReadOnly version of the receiver.
Expand All @@ -34,6 +35,6 @@ extension Storage.OrderStatsV4Totals: ReadOnlyConvertible {
shipping: shipping.decimalValue,
netRevenue: netRevenue.decimalValue,
totalProducts: Int(totalProducts),
averageOrderValue: 0) // TODO-8156: Update after Storage.OrderStatsV4Totals is updated
averageOrderValue: averageOrderValue.decimalValue)
}
}
4 changes: 2 additions & 2 deletions Yosemite/YosemiteTests/Stores/StatsStoreV4Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ private extension StatsStoreV4Tests {
shipping: 0,
netRevenue: 800,
totalProducts: 2,
averageOrderValue: 0)
averageOrderValue: 266)
}

/// Matches the first interval's `subtotals` field in `order-stats-v4-year` response.
Expand All @@ -539,7 +539,7 @@ private extension StatsStoreV4Tests {
shipping: 0,
netRevenue: 800,
totalProducts: 0,
averageOrderValue: 0)
averageOrderValue: 266)
}

func sampleIntervals() -> [Networking.OrderStatsV4Interval] {
Expand Down