@@ -90,6 +90,45 @@ final class IntegrationTests: XCTestCase {
90
90
XCTAssertEqual ( candidatesTokensDetails. tokenCount, usageMetadata. candidatesTokenCount)
91
91
}
92
92
93
+ func testGenerateContentStream( ) async throws {
94
+ let expectedText = """
95
+ 1. Mercury
96
+ 2. Venus
97
+ 3. Earth
98
+ 4. Mars
99
+ 5. Jupiter
100
+ 6. Saturn
101
+ 7. Uranus
102
+ 8. Neptune
103
+ """
104
+ let prompt = """
105
+ What are the names of the planets in the solar system, ordered from closest to furthest from
106
+ the sun? Answer with a Markdown numbered list of the names and no other text.
107
+ """
108
+ let chat = model. startChat ( )
109
+
110
+ let stream = try chat. sendMessageStream ( prompt)
111
+ var textValues = [ String] ( )
112
+ for try await value in stream {
113
+ try textValues. append ( XCTUnwrap ( value. text) )
114
+ }
115
+
116
+ let userHistory = try XCTUnwrap ( chat. history. first)
117
+ XCTAssertEqual ( userHistory. role, " user " )
118
+ XCTAssertEqual ( userHistory. parts. count, 1 )
119
+ let promptTextPart = try XCTUnwrap ( userHistory. parts. first as? TextPart )
120
+ XCTAssertEqual ( promptTextPart. text, prompt)
121
+ let modelHistory = try XCTUnwrap ( chat. history. last)
122
+ XCTAssertEqual ( modelHistory. role, " model " )
123
+ XCTAssertEqual ( modelHistory. parts. count, 1 )
124
+ let modelTextPart = try XCTUnwrap ( modelHistory. parts. first as? TextPart )
125
+ let modelText = modelTextPart. text. trimmingCharacters ( in: . whitespacesAndNewlines)
126
+ XCTAssertEqual ( modelText, expectedText)
127
+ XCTAssertGreaterThan ( textValues. count, 1 )
128
+ let text = textValues. joined ( ) . trimmingCharacters ( in: . whitespacesAndNewlines)
129
+ XCTAssertEqual ( text, expectedText)
130
+ }
131
+
93
132
func testGenerateContent_appCheckNotConfigured_shouldFail( ) async throws {
94
133
let app = try FirebaseApp . defaultNamedCopy ( name: TestAppCheckProviderFactory . notConfiguredName)
95
134
addTeardownBlock { await app. delete ( ) }
0 commit comments