Skip to content

Commit ddf95f3

Browse files
committed
Update tests
1 parent 449a8d6 commit ddf95f3

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed

Modules/Tests/StorageTests/CoreData/MigrationTests.swift

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2333,6 +2333,36 @@ final class MigrationTests: XCTestCase {
23332333
// `note` should be present in `migratedBooking`
23342334
XCTAssertNotNil(migratedBooking.entity.attributesByName["note"])
23352335
}
2336+
2337+
func test_migrating_from_130_to_131_adds_note_attribute_to_bookingCustomerInfo() throws {
2338+
// Given
2339+
let sourceContainer = try startPersistentContainer("Model 130")
2340+
let sourceContext = sourceContainer.viewContext
2341+
2342+
let customerInfo = insertBookingCustomerInfo(to: sourceContext)
2343+
try sourceContext.save()
2344+
2345+
XCTAssertNil(customerInfo.entity.attributesByName["note"], "Precondition. Attribute does not exist.")
2346+
2347+
// When
2348+
let targetContainer = try migrate(sourceContainer, to: "Model 131")
2349+
2350+
// Then
2351+
let targetContext = targetContainer.viewContext
2352+
let migratedCustomerInfo = try XCTUnwrap(targetContext.first(entityName: "BookingCustomerInfo"))
2353+
2354+
// `note` should be present in `migratedCustomerInfo`
2355+
XCTAssertNotNil(migratedCustomerInfo.entity.attributesByName["note"])
2356+
2357+
let noteValue = migratedCustomerInfo.value(forKey: "note") as? String
2358+
XCTAssertNil(noteValue)
2359+
2360+
let updatedNote = "Customer note"
2361+
migratedCustomerInfo.setValue(updatedNote, forKey: "note")
2362+
try targetContext.save()
2363+
2364+
XCTAssertEqual(migratedCustomerInfo.value(forKey: "note") as? String, updatedNote)
2365+
}
23362366
}
23372367

23382368
// MARK: - Persistent Store Setup and Migrations
@@ -3275,7 +3305,7 @@ private extension MigrationTests {
32753305

32763306
@discardableResult
32773307
func insertBookingCustomerInfo(to context: NSManagedObjectContext) -> NSManagedObject {
3278-
context.insert(entityName: "BookingCustomerInfo", properties: [
3308+
var properties: [String: Any] = [
32793309
"billingFirstName": "John",
32803310
"billingLastName": "Doe",
32813311
"billingEmail": "[email protected]",
@@ -3284,7 +3314,12 @@ private extension MigrationTests {
32843314
"billingState": "CA",
32853315
"billingPostcode": "94102",
32863316
"billingCountry": "US"
3287-
])
3317+
]
3318+
if let entity = NSEntityDescription.entity(forEntityName: "BookingCustomerInfo", in: context),
3319+
entity.attributesByName.keys.contains("note") {
3320+
properties["note"] = "Sample note"
3321+
}
3322+
return context.insert(entityName: "BookingCustomerInfo", properties: properties)
32883323
}
32893324

32903325
@discardableResult

WooCommerce/WooCommerceTests/ViewRelated/Bookings/BookingDetailsViewModelTests.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,47 @@ final class BookingDetailsViewModelTests: XCTestCase {
211211
XCTAssertEqual(customerContent.billingAddressText, expectedAddress)
212212
}
213213

214+
func test_customer_content_includes_customer_note() {
215+
// Given
216+
let billingAddress = Address.fake().copy(
217+
firstName: "Alice",
218+
lastName: "Johnson",
219+
address1: "456 Main St",
220+
city: "Springfield",
221+
state: "IL",
222+
postcode: "62701",
223+
country: "US"
224+
)
225+
let note = "Please ring the bell twice"
226+
let customerInfo = BookingCustomerInfo(billingAddress: billingAddress, note: note)
227+
let orderInfo = BookingOrderInfo(
228+
statusKey: "confirmed",
229+
paymentInfo: nil,
230+
customerInfo: customerInfo,
231+
productInfo: nil
232+
)
233+
let booking = Booking.fake().copy(orderInfo: orderInfo)
234+
235+
// When
236+
let viewModel = BookingDetailsViewModel(booking: booking, stores: storesManager)
237+
238+
// Then
239+
let customerSection = viewModel.sections.first { section in
240+
if case .customer = section.content {
241+
return true
242+
}
243+
return false
244+
}
245+
246+
guard let customerSection = customerSection,
247+
case let .customer(customerContent) = customerSection.content else {
248+
XCTFail("Customer section not found")
249+
return
250+
}
251+
252+
XCTAssertEqual(customerContent.noteText, note)
253+
}
254+
214255
func test_navigation_title_includes_booking_id() {
215256
// Given
216257
let booking = Booking.fake().copy(bookingID: 12345)

0 commit comments

Comments
 (0)