Skip to content

Commit f547ee9

Browse files
committed
instructions attribute on Storage.PaymentGateway
1 parent 033242d commit f547ee9

File tree

7 files changed

+929
-3
lines changed

7 files changed

+929
-3
lines changed

Storage/Storage.xcodeproj/project.pbxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@
272272
0345DB4527A8122700B02D0C /* Model 63.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Model 63.xcdatamodel"; sourceTree = "<group>"; };
273273
0371C37D28781D1F00277E2C /* FeatureAnnouncementCampaign.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeatureAnnouncementCampaign.swift; sourceTree = "<group>"; };
274274
0371C37E28781D1F00277E2C /* FeatureAnnouncementCampaignSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeatureAnnouncementCampaignSettings.swift; sourceTree = "<group>"; };
275+
0372D8B828AFD9530041028A /* Model 72.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Model 72.xcdatamodel"; sourceTree = "<group>"; };
275276
077F39C3269F1F4600ABEADC /* SystemPlugin+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SystemPlugin+CoreDataClass.swift"; sourceTree = "<group>"; };
276277
077F39C5269F1F7C00ABEADC /* SystemPlugin+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SystemPlugin+CoreDataProperties.swift"; sourceTree = "<group>"; };
277278
2618707125409C65006522A1 /* ShippingLineTax+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ShippingLineTax+CoreDataClass.swift"; sourceTree = "<group>"; };
@@ -1788,6 +1789,7 @@
17881789
DEC51AA4275B41BE009F3DF4 /* WooCommerce.xcdatamodeld */ = {
17891790
isa = XCVersionGroup;
17901791
children = (
1792+
0372D8B828AFD9530041028A /* Model 72.xcdatamodel */,
17911793
CC6A05402877012B002C144E /* Model 71.xcdatamodel */,
17921794
B963A5CA2853859400EFADA0 /* Model 70.xcdatamodel */,
17931795
268FEC8528513A470005E4C2 /* Model 69.xcdatamodel */,
@@ -1860,7 +1862,7 @@
18601862
DEC51ADE275B41BE009F3DF4 /* Model 47.xcdatamodel */,
18611863
DEC51ADF275B41BE009F3DF4 /* Model 19.xcdatamodel */,
18621864
);
1863-
currentVersion = CC6A05402877012B002C144E /* Model 71.xcdatamodel */;
1865+
currentVersion = 0372D8B828AFD9530041028A /* Model 72.xcdatamodel */;
18641866
path = WooCommerce.xcdatamodeld;
18651867
sourceTree = "<group>";
18661868
versionGroupType = wrapper.xcdatamodel;

Storage/Storage/Model/MIGRATIONS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

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

5+
## Model 71 (Release 9.6.0.0)
6+
- @joshheald 2022-08-19
7+
- Added `instructions` attribute to `PaymentGateway` entity.
8+
59
## Model 71 (Release 9.6.0.0)
610
- @rachelmcr 2022-07-07
711
- Added `OrderMetaData` entity.

Storage/Storage/Model/PaymentGateway+CoreDataProperties.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,10 @@ extension PaymentGateway {
1313
@NSManaged public var gatewayDescription: String
1414
@NSManaged public var features: [String]
1515
@NSManaged public var enabled: Bool
16+
@NSManaged public var instructions: String?
17+
18+
}
19+
20+
extension PaymentGateway: Identifiable {
1621

1722
}

Storage/Storage/Model/WooCommerce.xcdatamodeld/.xccurrentversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<plist version="1.0">
44
<dict>
55
<key>_XCCurrentVersionName</key>
6-
<string>Model 71.xcdatamodel</string>
6+
<string>Model 72.xcdatamodel</string>
77
</dict>
88
</plist>

Storage/Storage/Model/WooCommerce.xcdatamodeld/Model 72.xcdatamodel/contents

Lines changed: 872 additions & 0 deletions
Large diffs are not rendered by default.

Storage/StorageTests/CoreData/MigrationTests.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,36 @@ final class MigrationTests: XCTestCase {
12421242
// The OrderMetaData.order inverse relationship should be updated.
12431243
XCTAssertEqual(customField.value(forKey: "order") as? NSManagedObject, migratedOrder)
12441244
}
1245+
1246+
func test_migrating_from_71_to_72_adds_instructions_attribute_to_PaymentGateway() throws {
1247+
// Given
1248+
let sourceContainer = try startPersistentContainer("Model 71")
1249+
let sourceContext = sourceContainer.viewContext
1250+
1251+
let paymentGateway = insertPaymentGateway(to: sourceContext)
1252+
try sourceContext.save()
1253+
1254+
// `instructions` should not be present before migration
1255+
XCTAssertNil(paymentGateway.entity.relationshipsByName["instructions"])
1256+
1257+
// When
1258+
let targetContainer = try migrate(sourceContainer, to: "Model 72")
1259+
let targetContext = targetContainer.viewContext
1260+
1261+
// Confidence check
1262+
XCTAssertEqual(try targetContext.count(entityName: "PaymentGateway"), 1)
1263+
1264+
let migratedPaymentGateway = try XCTUnwrap(targetContext.first(entityName: "PaymentGateway"))
1265+
1266+
// The instructions should be nil after migration: it's an optional field.
1267+
XCTAssertNil(migratedPaymentGateway.value(forKey: "instructions"))
1268+
1269+
// Set a test instructions
1270+
migratedPaymentGateway.setValue("payment gateway instructions", forKey: "instructions")
1271+
1272+
// Check instructions are correctly set.
1273+
assertEqual("payment gateway instructions", migratedPaymentGateway.value(forKey: "instructions") as? String)
1274+
}
12451275
}
12461276

12471277
// MARK: - Persistent Store Setup and Migrations
@@ -1635,6 +1665,18 @@ private extension MigrationTests {
16351665
])
16361666
}
16371667

1668+
@discardableResult
1669+
func insertPaymentGateway(to context: NSManagedObjectContext) -> NSManagedObject {
1670+
context.insert(entityName: "PaymentGateway", properties: [
1671+
"siteID": 1372,
1672+
"gatewayID": "woocommerce-payments",
1673+
"title": "WooCommerce Payments",
1674+
"gatewayDescription": "WooCommerce Payments - easy payments by Woo",
1675+
"enabled": true,
1676+
"features": []
1677+
])
1678+
}
1679+
16381680
@discardableResult
16391681
func insertPaymentGatewayAccount(to context: NSManagedObjectContext) -> NSManagedObject {
16401682
context.insert(entityName: "PaymentGatewayAccount", properties: [

Yosemite/Yosemite/Model/Storage/PaymentGateway+ReadOnlyConvertible.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extension Storage.PaymentGateway: ReadOnlyConvertible {
1414
gatewayDescription = paymentGateway.description
1515
enabled = paymentGateway.enabled
1616
features = paymentGateway.features.map { $0.rawValue }
17+
instructions = paymentGateway.instructions
1718
}
1819

1920
/// Returns a ReadOnly version of the receiver.
@@ -25,6 +26,6 @@ extension Storage.PaymentGateway: ReadOnlyConvertible {
2526
description: gatewayDescription,
2627
enabled: enabled,
2728
features: features.compactMap { PaymentGateway.Feature(rawValue: $0) },
28-
instructions: "")
29+
instructions: instructions)
2930
}
3031
}

0 commit comments

Comments
 (0)