Skip to content

Commit 46a7ef0

Browse files
committed
5976 loadWCPayCharge function for CoreData access
1 parent bdb1713 commit 46a7ef0

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Storage/Storage/Tools/StorageType+Extensions.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,13 @@ public extension StorageType {
584584
return firstObject(ofType: PaymentGatewayAccount.self, matching: predicate)
585585
}
586586

587+
/// Returns a charge with a specified `siteID` and `chargeID`
588+
///
589+
func loadWCPayCharge(siteID: Int64, chargeID: String) -> WCPayCharge? {
590+
let predicate = \WCPayCharge.siteID == siteID && \WCPayCharge.id == chargeID
591+
return firstObject(ofType: WCPayCharge.self, matching: predicate)
592+
}
593+
587594
// MARK: - System plugins
588595

589596
/// Returns all stored system plugins for a provided `siteID`.

Storage/StorageTests/Tools/StorageTypeExtensionsTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,4 +1170,21 @@ final class StorageTypeExtensionsTests: XCTestCase {
11701170
// Then
11711171
XCTAssertEqual(foundSystemPlugin, systemPlugin2)
11721172
}
1173+
1174+
func test_load_WCPayCharge_by_siteID_and_chargeID() throws {
1175+
// Given
1176+
let charge1 = storage.insertNewObject(ofType: WCPayCharge.self)
1177+
charge1.id = "ch_1"
1178+
charge1.siteID = sampleSiteID
1179+
1180+
let charge2 = storage.insertNewObject(ofType: WCPayCharge.self)
1181+
charge2.id = "ch_2"
1182+
charge2.siteID = sampleSiteID
1183+
1184+
// When
1185+
let foundCharge = try XCTUnwrap(storage.loadWCPayCharge(siteID: sampleSiteID, chargeID: "ch_2"))
1186+
1187+
// Then
1188+
XCTAssertEqual(foundCharge, charge2)
1189+
}
11731190
}

0 commit comments

Comments
 (0)