migration

This commit is contained in:
Daniel Arantes Loverde
2026-08-11 13:22:02 -03:00
parent c4d6998595
commit 7702836fe7
231 changed files with 4329 additions and 1958 deletions

View File

@@ -0,0 +1,37 @@
import Foundation
import Testing
@testable import PediFoods
private func decode<T: Decodable>(_ type: T.Type, _ json: String) throws -> T {
try JSONDecoder().decode(T.self, from: Data(json.utf8))
}
@Test("StorePizzaConfig defaults every list to empty when fields are missing")
func storePizzaConfigDefaultsToEmptyLists() throws {
let config = try decode(StorePizzaConfig.self, "{}")
#expect(config.sizes.isEmpty)
#expect(config.doughs.isEmpty)
#expect(config.crusts.isEmpty)
}
@Test("StorePizzaCrust falls back to a placeholder id when missing")
func storePizzaCrustPlaceholderId() throws {
let crust = try decode(StorePizzaCrust.self, "{}")
#expect(crust.id.isEmpty == false)
#expect(crust.priceModifier == nil)
}
@Test("StorePizzaCrust coerces priceModifier from Double, Int, or comma-decimal String")
func storePizzaCrustPriceModifierCoercion() throws {
let asDouble = try decode(StorePizzaCrust.self, #"{"id":"1","priceModifier":3.5}"#)
#expect(asDouble.priceModifier == 3.5)
let asInt = try decode(StorePizzaCrust.self, #"{"id":"1","priceModifier":4}"#)
#expect(asInt.priceModifier == 4.0)
let asString = try decode(StorePizzaCrust.self, #"{"id":"1","priceModifier":"3,50"}"#)
#expect(asString.priceModifier == 3.5)
let malformed = try decode(StorePizzaCrust.self, #"{"id":"1","priceModifier":"not-a-number"}"#)
#expect(malformed.priceModifier == nil)
}