@@ -159,4 +159,57 @@ describe("getUserDataForFid", () => {
159159 'Failed to parse response body as JSON because server hub returned response with status "504" and body "Gateway Timeout"'
160160 ) ;
161161 } ) ;
162+
163+ it ( "warns if message could not be parsed" , async ( ) => {
164+ nock ( DEFAULT_HUB_API_URL )
165+ . get ( "/v1/userDataByFid?fid=1214" )
166+ . reply ( 200 , {
167+ messages : [
168+ {
169+ data : {
170+ type : "MESSAGE_TYPE_USER_DATA_ADD" ,
171+ fid : 1214 ,
172+ timestamp : 69403426 ,
173+ network : "FARCASTER_NETWORK_MAINNET" ,
174+ userDataBody : {
175+ type : "USER_DATA_TYPE_SOMETHING_UNKNOWN" ,
176+ value :
177+ "https://lh3.googleusercontent.com/-S5cdhOpZtJ_Qzg9iPWELEsRTkIsZ7qGYmVlwEORgFB00WWAtZGefRnS4Bjcz5ah40WVOOWeYfU5pP9Eekikb3cLMW2mZQOMQHlWhg" ,
178+ } ,
179+ } ,
180+ hash : "0x465e44c9d8b4f6189d40b79029168a1dc0b50ea5" ,
181+ hashScheme : "HASH_SCHEME_BLAKE3" ,
182+ signature :
183+ "x4J7Lo4FM7wutYYomV7ItFSOlo3Rca4s+BQ5rQK0dvRpIrsCCX7BU5fnkX3UfseXTyh4kJOVYmeEhLeeA27oAw==" ,
184+ signatureScheme : "SIGNATURE_SCHEME_ED25519" ,
185+ signer :
186+ "0xf23a5c7b9f067c621a989a585b78daf7b2a9debe9d54325ef95b0878f44204c6" ,
187+ } ,
188+ ] ,
189+ } ) ;
190+
191+ const consoleWarnSpy = jest
192+ . spyOn ( console , "warn" )
193+ . mockImplementation ( ( ) => { } ) ;
194+
195+ const result = await getUserDataForFid ( { fid : 1214 } ) ;
196+
197+ expect ( consoleWarnSpy ) . toHaveBeenCalled ( ) ;
198+ expect ( consoleWarnSpy ) . toHaveBeenCalledWith (
199+ "Failed to parse user data message for fid 1214" ,
200+ expect . any ( Object ) ,
201+ expect . any ( Error )
202+ ) ;
203+
204+ expect ( result ) . toBeDefined ( ) ;
205+ if ( ! result ) {
206+ throw new Error ( "Result is null" ) ;
207+ }
208+
209+ const allValuesUndefined = Object . values ( result ) . every (
210+ ( value ) => value === undefined
211+ ) ;
212+
213+ expect ( allValuesUndefined ) . toBe ( true ) ;
214+ } ) ;
162215} ) ;
0 commit comments