@@ -40,57 +40,58 @@ final class ChatTests: XCTestCase {
4040 let fileURL = try XCTUnwrap ( bundle. url (
4141 forResource: " streaming-success-basic-reply-parts " ,
4242 withExtension: " txt " ,
43- subdirectory: " vertexai "
43+ subdirectory: " mock-responses/ vertexai"
4444 ) )
4545
4646 // Skip tests using MockURLProtocol on watchOS; unsupported in watchOS 2 and later, see
4747 // https://developer.apple.com/documentation/foundation/urlprotocol for details.
4848 #if os(watchOS)
4949 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+ }
6060
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)
8181
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+ }
8686
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)
9191
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)
9596 }
9697}
0 commit comments