This commit is contained in:
Daniel Arantes Loverde
2026-04-16 14:50:07 -03:00
parent 7f7d414e6c
commit 0ebb854213
20 changed files with 871 additions and 216 deletions

View File

@@ -0,0 +1,49 @@
import Foundation
import Testing
@testable import PediFoods
@Test("Customer profile decodes persisted favorite store ids")
func customerProfileDecodesFavoriteStoreIds() throws {
let json = """
{
"error": false,
"result": {
"id": "cust_1",
"name": "Daniel",
"email": "daniel@example.com",
"phoneNumber": "+5511999999999",
"favorites": ["store_a", "store_b"],
"address_book": []
}
}
"""
let envelope = try JSONDecoder().decode(ApiEnvelope<CustomerProfile>.self, from: Data(json.utf8))
#expect(envelope.result?.favorites == ["store_a", "store_b"])
}
@Test("Favorite mutation decodes updated favorites array")
func favoriteMutationDecodesUpdatedFavoritesArray() throws {
let json = """
{
"error": false,
"result": {
"favorites": ["store_a"],
"store": {
"id": "store_a",
"name": "CPS Drinks",
"category": "Doces & Bolos",
"rating": 4.8,
"totalReviews": 12,
"isOpen": true,
"statusLabel": "Aberto"
}
}
}
"""
let envelope = try JSONDecoder().decode(ApiEnvelope<CustomerFavoritesMutationResult>.self, from: Data(json.utf8))
#expect(envelope.result?.favorites == ["store_a"])
#expect(envelope.result?.store?.id == "store_a")
#expect(envelope.result?.store?.name == "CPS Drinks")
}