Return response instead of data
This commit is contained in:
@@ -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"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user