import Foundation import Testing @testable import PediFoods private func decode(_ 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) }