@@ -22,7 +22,11 @@ import { FirebaseError } from '@firebase/util';
2222
2323describe ( 'chat-session-helpers' , ( ) => {
2424 describe ( 'validateChatHistory' , ( ) => {
25- const TCS : Array < { history : Content [ ] ; isValid : boolean } > = [
25+ const TCS : Array < {
26+ history : Content [ ] ;
27+ isValid : boolean ;
28+ errorShouldInclude ?: string ;
29+ } > = [
2630 {
2731 history : [ { role : 'user' , parts : [ { text : 'hi' } ] } ] ,
2832 isValid : true
@@ -99,19 +103,23 @@ describe('chat-session-helpers', () => {
99103 {
100104 //@ts -expect-error
101105 history : [ { role : 'user' , parts : '' } ] ,
106+ errorShouldInclude : `array of Parts` ,
102107 isValid : false
103108 } ,
104109 {
105110 //@ts -expect-error
106111 history : [ { role : 'user' } ] ,
112+ errorShouldInclude : `array of Parts` ,
107113 isValid : false
108114 } ,
109115 {
110116 history : [ { role : 'user' , parts : [ ] } ] ,
117+ errorShouldInclude : `at least one part` ,
111118 isValid : false
112119 } ,
113120 {
114121 history : [ { role : 'model' , parts : [ { text : 'hi' } ] } ] ,
122+ errorShouldInclude : `model` ,
115123 isValid : false
116124 } ,
117125 {
@@ -125,13 +133,15 @@ describe('chat-session-helpers', () => {
125133 ]
126134 }
127135 ] ,
136+ errorShouldInclude : `function` ,
128137 isValid : false
129138 } ,
130139 {
131140 history : [
132141 { role : 'user' , parts : [ { text : 'hi' } ] } ,
133142 { role : 'user' , parts : [ { text : 'hi' } ] }
134143 ] ,
144+ errorShouldInclude : `can't follow 'user'` ,
135145 isValid : false
136146 } ,
137147 {
@@ -140,6 +150,45 @@ describe('chat-session-helpers', () => {
140150 { role : 'model' , parts : [ { text : 'hi' } ] } ,
141151 { role : 'model' , parts : [ { text : 'hi' } ] }
142152 ] ,
153+ errorShouldInclude : `can't follow 'model'` ,
154+ isValid : false
155+ } ,
156+ {
157+ history : [
158+ { role : 'user' , parts : [ { text : 'hi' } ] } ,
159+ {
160+ role : 'model' ,
161+ parts : [
162+ { text : 'hi' } ,
163+ {
164+ text : 'thought about hi' ,
165+ thought : true ,
166+ thoughtSignature : 'thought signature'
167+ }
168+ ]
169+ }
170+ ] ,
171+ isValid : true
172+ } ,
173+ {
174+ history : [
175+ {
176+ role : 'user' ,
177+ parts : [ { text : 'hi' , thought : true , thoughtSignature : 'sig' } ]
178+ } ,
179+ {
180+ role : 'model' ,
181+ parts : [
182+ { text : 'hi' } ,
183+ {
184+ text : 'thought about hi' ,
185+ thought : true ,
186+ thoughtSignature : 'thought signature'
187+ }
188+ ]
189+ }
190+ ] ,
191+ errorShouldInclude : 'thought' ,
143192 isValid : false
144193 }
145194 ] ;
@@ -149,7 +198,14 @@ describe('chat-session-helpers', () => {
149198 if ( tc . isValid ) {
150199 expect ( fn ) . to . not . throw ( ) ;
151200 } else {
152- expect ( fn ) . to . throw ( FirebaseError ) ;
201+ try {
202+ fn ( ) ;
203+ } catch ( e ) {
204+ expect ( e ) . to . be . instanceOf ( FirebaseError ) ;
205+ if ( e instanceof FirebaseError && tc . errorShouldInclude ) {
206+ expect ( e . message ) . to . include ( tc . errorShouldInclude ) ;
207+ }
208+ }
153209 }
154210 } ) ;
155211 } ) ;
0 commit comments