Fixed some type issues + made request methods
This commit is contained in:
@@ -1,12 +1,62 @@
|
||||
import XCTest
|
||||
@testable import USDA
|
||||
@testable import USDA_FDC
|
||||
|
||||
func loadEnvironment() -> [String: String] {
|
||||
var dic: [String: String] = [:]
|
||||
if FileManager.default.fileExists(atPath: ".env") {
|
||||
do {
|
||||
let contents = try String(contentsOfFile: ".env", encoding: .utf8)
|
||||
let lines = contents.components(separatedBy: .newlines)
|
||||
|
||||
for line in lines {
|
||||
let components = line.components(separatedBy: "=")
|
||||
if components.count == 2 {
|
||||
let key = components[0].trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let value = components[1].trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
dic[key] = value
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
print("Error reading .env file: \(error)")
|
||||
}
|
||||
}
|
||||
return dic
|
||||
}
|
||||
|
||||
final class USDATests: XCTestCase {
|
||||
func testExample() throws {
|
||||
// XCTest Documentation
|
||||
// https://developer.apple.com/documentation/xctest
|
||||
|
||||
// Defining Test Cases and Test Methods
|
||||
// https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods
|
||||
var env: [String: String] {
|
||||
loadEnvironment()
|
||||
}
|
||||
|
||||
func testFoodList() async throws {
|
||||
let fdc = USDA_FDC_Client()
|
||||
fdc.apiKey = env["API_KEY"] ?? ""
|
||||
do {
|
||||
let _ = try await fdc.getFoodList()
|
||||
} catch {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
func testFoodItem() async throws {
|
||||
let fdc = USDA_FDC_Client()
|
||||
fdc.apiKey = env["API_KEY"] ?? ""
|
||||
do {
|
||||
let _ = try await fdc.getFood(.init(fdcId: 167782))
|
||||
} catch {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
func testFoodSearch() async throws {
|
||||
let fdc = USDA_FDC_Client()
|
||||
fdc.apiKey = env["API_KEY"] ?? ""
|
||||
do {
|
||||
let _ = try await fdc.getFoodsSearch(.init(query: "cheddar cheese"))
|
||||
} catch {
|
||||
throw error
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user