@@ -40,57 +40,58 @@ final class ChatTests: XCTestCase {
40
40
let fileURL = try XCTUnwrap ( bundle. url (
41
41
forResource: " streaming-success-basic-reply-parts " ,
42
42
withExtension: " txt " ,
43
- subdirectory: " vertexai "
43
+ subdirectory: " mock-responses/ vertexai"
44
44
) )
45
45
46
46
// Skip tests using MockURLProtocol on watchOS; unsupported in watchOS 2 and later, see
47
47
// https://developer.apple.com/documentation/foundation/urlprotocol for details.
48
48
#if os(watchOS)
49
49
throw XCTSkip ( " Custom URL protocols are unsupported in watchOS 2 and later. " )
50
- #endif // os(watchOS)
51
- MockURLProtocol . requestHandler = { request in
52
- let response = HTTPURLResponse (
53
- url: request. url!,
54
- statusCode: 200 ,
55
- httpVersion: nil ,
56
- headerFields: nil
57
- ) !
58
- return ( response, fileURL. lines)
59
- }
50
+ #else // os(watchOS)
51
+ MockURLProtocol . requestHandler = { request in
52
+ let response = HTTPURLResponse (
53
+ url: request. url!,
54
+ statusCode: 200 ,
55
+ httpVersion: nil ,
56
+ headerFields: nil
57
+ ) !
58
+ return ( response, fileURL. lines)
59
+ }
60
60
61
- let app = FirebaseApp ( instanceWithName: " testApp " ,
62
- options: FirebaseOptions ( googleAppID: " ignore " ,
63
- gcmSenderID: " ignore " ) )
64
- let model = GenerativeModel (
65
- modelName: modelName,
66
- modelResourceName: modelResourceName,
67
- firebaseInfo: FirebaseInfo (
68
- projectID: " my-project-id " ,
69
- apiKey: " API_KEY " ,
70
- firebaseAppID: " My app ID " ,
71
- firebaseApp: app
72
- ) ,
73
- apiConfig: FirebaseAI . defaultVertexAIAPIConfig,
74
- tools: nil ,
75
- requestOptions: RequestOptions ( ) ,
76
- urlSession: urlSession
77
- )
78
- let chat = Chat ( model: model, history: [ ] )
79
- let input = " Test input "
80
- let stream = try chat. sendMessageStream ( input)
61
+ let app = FirebaseApp ( instanceWithName: " testApp " ,
62
+ options: FirebaseOptions ( googleAppID: " ignore " ,
63
+ gcmSenderID: " ignore " ) )
64
+ let model = GenerativeModel (
65
+ modelName: modelName,
66
+ modelResourceName: modelResourceName,
67
+ firebaseInfo: FirebaseInfo (
68
+ projectID: " my-project-id " ,
69
+ apiKey: " API_KEY " ,
70
+ firebaseAppID: " My app ID " ,
71
+ firebaseApp: app
72
+ ) ,
73
+ apiConfig: FirebaseAI . defaultVertexAIAPIConfig,
74
+ tools: nil ,
75
+ requestOptions: RequestOptions ( ) ,
76
+ urlSession: urlSession
77
+ )
78
+ let chat = Chat ( model: model, history: [ ] )
79
+ let input = " Test input "
80
+ let stream = try chat. sendMessageStream ( input)
81
81
82
- // Ensure the values are parsed correctly
83
- for try await value in stream {
84
- XCTAssertNotNil ( value. text)
85
- }
82
+ // Ensure the values are parsed correctly
83
+ for try await value in stream {
84
+ XCTAssertNotNil ( value. text)
85
+ }
86
86
87
- XCTAssertEqual ( chat. history. count, 2 )
88
- let part = try XCTUnwrap ( chat. history [ 0 ] . parts [ 0 ] )
89
- let textPart = try XCTUnwrap ( part as? TextPart )
90
- XCTAssertEqual ( textPart. text, input)
87
+ XCTAssertEqual ( chat. history. count, 2 )
88
+ let part = try XCTUnwrap ( chat. history [ 0 ] . parts [ 0 ] )
89
+ let textPart = try XCTUnwrap ( part as? TextPart )
90
+ XCTAssertEqual ( textPart. text, input)
91
91
92
- let finalText = " 1 2 3 4 5 6 7 8 "
93
- let assembledExpectation = ModelContent ( role: " model " , parts: finalText)
94
- XCTAssertEqual ( chat. history [ 1 ] , assembledExpectation)
92
+ let finalText = " 1 2 3 4 5 6 7 8 "
93
+ let assembledExpectation = ModelContent ( role: " model " , parts: finalText)
94
+ XCTAssertEqual ( chat. history [ 1 ] , assembledExpectation)
95
+ #endif // os(watchOS)
95
96
}
96
97
}
0 commit comments