Skip to content

Commit 2ac5d28

Browse files
committed
fix tests
1 parent 1c0f537 commit 2ac5d28

File tree

2 files changed

+18
-31
lines changed

2 files changed

+18
-31
lines changed

Tests/FunctionCalling-FirebaseVertexAITests/Extensions.swift

Lines changed: 0 additions & 24 deletions
This file was deleted.

Tests/FunctionCalling-FirebaseVertexAITests/FunctionCalling_FirebaseVertexAITests.swift

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,31 @@ final class FunctionCalling_FirebaseVertexAITests: XCTestCase {
2121
}
2222

2323
func testConvertedResults() throws {
24-
guard let functions = FunctionContainer().firebaseVertexAITools.first?.functions else {
24+
guard let tool = FunctionContainer().firebaseVertexAITools.first else {
2525
XCTFail("Conainer should contain some functions")
2626
return
2727
}
2828

29+
let encodedToolData = try JSONEncoder().encode(tool)
30+
let jsonObject = try JSONSerialization.jsonObject(with: encodedToolData)
31+
32+
guard let toolDictionary = jsonObject as? [String: Any] else {
33+
XCTFail("Failed to convert to JSON object")
34+
return
35+
}
36+
37+
guard let functions = toolDictionary["functionDeclarations"] as? [[String: Any]] else {
38+
XCTFail("Failed to convert to JSON object")
39+
return
40+
}
41+
2942
XCTAssertEqual(functions.count, 2)
3043

31-
let getWeather = try XCTUnwrap(functions.first)
32-
XCTAssertEqual(getWeather.getName(), "getWeather")
44+
let getWeather = try XCTUnwrap(functions.first(where: { $0["name"] as? String == "getWeather" }))
3345
// swiftlint:disable:next line_length
34-
XCTAssertEqual(getWeather.getDescription(), "Return current weather of location that passed by the argument- Parameter location: location that I want to know how the weather- Returns: string of weather")
46+
XCTAssertEqual(getWeather["description"] as? String, "Return current weather of location that passed by the argument- Parameter location: location that I want to know how the weather- Returns: string of weather")
3547

36-
let getStock = try XCTUnwrap(functions.last)
37-
XCTAssertEqual(getStock.getName(), "getStock")
38-
XCTAssertEqual(getStock.getDescription(), "")
48+
let getStock = try XCTUnwrap(functions.first(where: { $0["name"] as? String == "getStock" }))
49+
XCTAssertEqual(getStock["description"] as? String, "")
3950
}
4051
}

0 commit comments

Comments
 (0)