Return response instead of data

This commit is contained in:
cdricms
2025-12-06 17:53:51 +01:00
parent bc1abfdebc
commit fd493ce546
3 changed files with 31 additions and 14 deletions

View File

@@ -18,11 +18,13 @@ final class OpenFoodFactsTests: XCTestCase {
func testProductFetch() async throws {
// Fetch specific fields only
let product = try await client.product(
let response = try await client.product(
barcode: "3017620422003", // Nutella
fields: [.code, .productName, .nutriscoreGrade, .nutriments]
)
let product = response.product
XCTAssertEqual(product?.code, "3017620422003")
XCTAssertNotNil(product?.productName)
XCTAssertNotNil(product?.nutriscoreGrade)
@@ -31,13 +33,15 @@ final class OpenFoodFactsTests: XCTestCase {
}
func testSearch() async throws {
let results = try await client.search(
let response = try await client.search(
.query("chocolate"),
.tag(tag: .brands, value: "milka"),
.pageSize(5),
.sort(.popularity),
)
let results = response.products ?? []
let jsonResults = try JSONEncoder().encode(results)
try jsonResults.write(to: .init(filePath: "./jsonResults.json"))