Skip to content

Commit 2c4e503

Browse files
committed
Add migration test
1 parent 2d2baed commit 2c4e503

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

Modules/Sources/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 127 (Release 23.4.0.0)
6+
- @itsmeichigo 2025-09-23
7+
- Added new `Booking` entity.
8+
59
## Model 126 (Release 23.3.0.0)
610
- @rafaelkayumov 2025-09-15
711
- Added `isGarden` attribute to `Site` entity.

Modules/Tests/StorageTests/CoreData/MigrationTests.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,6 +2755,32 @@ final class MigrationTests: XCTestCase {
27552755
let updatedCategory = migratedLabel.value(forKey: "hazmatCategory") as? String
27562756
XCTAssertEqual(updatedCategory, category)
27572757
}
2758+
2759+
func test_migrating_126_to_127_adds_new_booking_entity() throws {
2760+
// Given
2761+
let sourceContainer = try startPersistentContainer("Model 126")
2762+
let sourceContext = sourceContainer.viewContext
2763+
2764+
try sourceContext.save()
2765+
2766+
// Confidence Check. Booking should not exist in Model 126
2767+
XCTAssertNil(NSEntityDescription.entity(forEntityName: "Booking", in: sourceContext))
2768+
2769+
// When
2770+
let targetContainer = try migrate(sourceContainer, to: "Model 127")
2771+
let targetContext = targetContainer.viewContext
2772+
2773+
// Then
2774+
XCTAssertEqual(try targetContext.count(entityName: "Booking"), 0)
2775+
2776+
let booking = insertBooking(to: targetContext)
2777+
XCTAssertNoThrow(try targetContext.save())
2778+
2779+
XCTAssertEqual(try targetContext.count(entityName: "Booking"), 1)
2780+
let insertedBooking = try XCTUnwrap(targetContext.firstObject(ofType: Booking.self))
2781+
XCTAssertEqual(insertedBooking, booking)
2782+
XCTAssertEqual(insertedBooking.parentID, 0) // default value
2783+
}
27582784
}
27592785

27602786
// MARK: - Persistent Store Setup and Migrations
@@ -3679,4 +3705,12 @@ private extension MigrationTests {
36793705
"id": "test-address"
36803706
])
36813707
}
3708+
3709+
@discardableResult
3710+
func insertBooking(to context: NSManagedObjectContext) -> NSManagedObject {
3711+
context.insert(entityName: "Booking", properties: [
3712+
"siteID": 1,
3713+
"bookingID": 23
3714+
])
3715+
}
36823716
}

0 commit comments

Comments
 (0)