@@ -3493,6 +3493,31 @@ final class MigrationTests: XCTestCase {
34933493
34943494 XCTAssertEqual ( migratedOrder. value ( forKey: " shipments " ) as? Set < NSManagedObject > , [ shipment] )
34953495 }
3496+
3497+ func test_migrating_from_123_to_124_enables_creating_new_WooShippingOriginAddress_entity( ) throws {
3498+ // Given
3499+ let sourceContainer = try startPersistentContainer ( " Model 123 " )
3500+ let sourceContext = sourceContainer. viewContext
3501+
3502+ try sourceContext. save ( )
3503+
3504+ // Confidence Check. WooShippingOriginAddress should not exist in Model 123
3505+ XCTAssertNil ( NSEntityDescription . entity ( forEntityName: " WooShippingOriginAddress " , in: sourceContext) )
3506+
3507+ // When
3508+ let targetContainer = try migrate ( sourceContainer, to: " Model 124 " )
3509+ let targetContext = targetContainer. viewContext
3510+
3511+ // Then
3512+ XCTAssertEqual ( try targetContext. count ( entityName: " WooShippingOriginAddress " ) , 0 )
3513+
3514+ let address = insertWooShippingOriginAddress ( to: targetContext)
3515+ XCTAssertNoThrow ( try targetContext. save ( ) )
3516+
3517+ XCTAssertEqual ( try targetContext. count ( entityName: " WooShippingOriginAddress " ) , 1 )
3518+ let insertedAddress = try XCTUnwrap ( targetContext. firstObject ( ofType: WooShippingOriginAddress . self) )
3519+ XCTAssertEqual ( insertedAddress, address)
3520+ }
34963521}
34973522
34983523// MARK: - Persistent Store Setup and Migrations
@@ -4409,4 +4434,12 @@ private extension MigrationTests {
44094434 " subItems " : [ " sub_1 " , " sub_2 " ]
44104435 ] )
44114436 }
4437+
4438+ @discardableResult
4439+ func insertWooShippingOriginAddress( to context: NSManagedObjectContext ) -> NSManagedObject {
4440+ context. insert ( entityName: " WooShippingOriginAddress " , properties: [
4441+ " siteID " : 1 ,
4442+ " id " : " test-address "
4443+ ] )
4444+ }
44124445}
0 commit comments