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 Networking/Networking/Model/Stats/SiteVisitStatsItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public struct SiteVisitStatsItem: Equatable, GeneratedCopiable, GeneratedFakeabl
extension SiteVisitStatsItem: Comparable {
public static func < (lhs: SiteVisitStatsItem, rhs: SiteVisitStatsItem) -> Bool {
return lhs.period < rhs.period ||
(lhs.period == rhs.period && lhs.visitors < rhs.visitors && lhs.views < rhs.views)
(lhs.period == rhs.period && lhs.visitors < rhs.visitors) ||
(lhs.period == rhs.period && lhs.visitors == rhs.visitors && lhs.views < rhs.views)
}
}
4 changes: 2 additions & 2 deletions Networking/NetworkingTests/Responses/site-visits-alt.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"data": [
[
"2014-01-01",
12821,
12831,
1140,
1094,
0,
Expand All @@ -22,7 +22,7 @@
],
[
"2015-01-01",
14808,
14818,
1634,
1492,
0,
Expand Down
4 changes: 3 additions & 1 deletion Storage/Storage.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@
CC6A05402877012B002C144E /* Model 71.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Model 71.xcdatamodel"; sourceTree = "<group>"; };
CC6A054128770933002C144E /* OrderMetaData+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OrderMetaData+CoreDataClass.swift"; sourceTree = "<group>"; };
CC6A054228770933002C144E /* OrderMetaData+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OrderMetaData+CoreDataProperties.swift"; sourceTree = "<group>"; };
CCA1D60B29477F5E00B40560 /* Model 79.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Model 79.xcdatamodel"; 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>"; };
Expand Down Expand Up @@ -1816,6 +1817,7 @@
DEC51AA4275B41BE009F3DF4 /* WooCommerce.xcdatamodeld */ = {
isa = XCVersionGroup;
children = (
CCA1D60B29477F5E00B40560 /* Model 79.xcdatamodel */,
CCF3209E2927EBEE002114B1 /* Model 78.xcdatamodel */,
AE7DF9FA2919023100C4D1ED /* Model 77.xcdatamodel */,
AEC4481B290853C300BAA299 /* Model 76.xcdatamodel */,
Expand Down Expand Up @@ -1895,7 +1897,7 @@
DEC51ADE275B41BE009F3DF4 /* Model 47.xcdatamodel */,
DEC51ADF275B41BE009F3DF4 /* Model 19.xcdatamodel */,
);
currentVersion = CCF3209E2927EBEE002114B1 /* Model 78.xcdatamodel */;
currentVersion = CCA1D60B29477F5E00B40560 /* Model 79.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 79 (Release 11.7.0.0)
- @rachelmcr 2022-12-12
- Added `views` attribute to `SiteVisitStatsItem` entity.

## Model 78 (Release 11.4.0.0)
- @rachelmcr 2022-11-18
- Added `averageOrderValue` attribute to `OrderStatsV4Totals` entity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ extension SiteVisitStatsItem {

@NSManaged public var period: String?
@NSManaged public var visitors: Int64
@NSManaged public var views: Int64
@NSManaged public var stats: SiteVisitStats?
}
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 78.xcdatamodel</string>
<string>Model 79.xcdatamodel</string>
</dict>
</plist>

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions Storage/StorageTests/CoreData/MigrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,34 @@ final class MigrationTests: XCTestCase {
let newAverageOrderValue = try XCTUnwrap(migratedOrderStatsV4Totals.value(forKey: "averageOrderValue") as? Double)
XCTAssertEqual(newAverageOrderValue, averageOrderValue)
}

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

let siteVisitStatsItem = insertSiteVisitStatsItem(to: sourceContainer.viewContext)
try sourceContext.save()

XCTAssertNil(siteVisitStatsItem.entity.attributesByName["views"])

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

let migratedSiteVisitStatsItem = try XCTUnwrap(targetContext.first(entityName: "SiteVisitStatsItem"))
let defaultViewsCount = try XCTUnwrap(migratedSiteVisitStatsItem.value(forKey: "views") as? Int)

let viewsCount = 12
migratedSiteVisitStatsItem.setValue(viewsCount, forKey: "views")

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

let newViewsCount = try XCTUnwrap(migratedSiteVisitStatsItem.value(forKey: "views") as? Int)
XCTAssertEqual(newViewsCount, viewsCount)
}
}

// MARK: - Persistent Store Setup and Migrations
Expand Down Expand Up @@ -1943,6 +1971,14 @@ private extension MigrationTests {
])
}

@discardableResult
func insertSiteVisitStatsItem(to context: NSManagedObjectContext) -> NSManagedObject {
context.insert(entityName: "SiteVisitStatsItem", properties: [
"period": "day",
"visitors": 3
])
}

@discardableResult
func insertTopEarnerStats(to context: NSManagedObjectContext) -> NSManagedObject {
context.insert(entityName: "TopEarnerStats", properties: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ extension Storage.SiteVisitStatsItem: ReadOnlyConvertible {
public func update(with statsItem: Yosemite.SiteVisitStatsItem) {
period = statsItem.period
visitors = Int64(statsItem.visitors)
views = Int64(statsItem.views)
}

/// Returns a ReadOnly version of the receiver.
///
public func toReadOnly() -> Yosemite.SiteVisitStatsItem {
return SiteVisitStatsItem(period: period ?? "",
visitors: Int(visitors),
views: 0) // TODO-8363: Update Storage with views count
views: Int(views))
}
}
8 changes: 4 additions & 4 deletions Yosemite/YosemiteTests/Stores/StatsStoreV4Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,11 @@ private extension StatsStoreV4Tests {


func sampleSiteVisitStatsItem1() -> Networking.SiteVisitStatsItem {
return SiteVisitStatsItem(period: "2014-01-01", visitors: 1135, views: 0)
return SiteVisitStatsItem(period: "2014-01-01", visitors: 1135, views: 12821)
}

func sampleSiteVisitStatsItem2() -> Networking.SiteVisitStatsItem {
return SiteVisitStatsItem(period: "2015-01-01", visitors: 1629, views: 0)
return SiteVisitStatsItem(period: "2015-01-01", visitors: 1629, views: 14808)
}

func sampleSiteVisitStatsMutated() -> Networking.SiteVisitStats {
Expand All @@ -619,11 +619,11 @@ private extension StatsStoreV4Tests {


func sampleSiteVisitStatsItem1Mutated() -> Networking.SiteVisitStatsItem {
return SiteVisitStatsItem(period: "2014-01-01", visitors: 1140, views: 0)
return SiteVisitStatsItem(period: "2014-01-01", visitors: 1140, views: 12831)
}

func sampleSiteVisitStatsItem2Mutated() -> Networking.SiteVisitStatsItem {
return SiteVisitStatsItem(period: "2015-01-01", visitors: 1634, views: 0)
return SiteVisitStatsItem(period: "2015-01-01", visitors: 1634, views: 14818)
}

// MARK: - Top Earner Stats Sample
Expand Down