@@ -193,5 +193,44 @@ describe('connected-services/factories', () => {
193193 Sinon . assert . calledOnce ( bStubbed . oauthClients ) ;
194194 Sinon . assert . calledOnce ( bStubbed . sessions ) ;
195195 } ) ;
196+
197+ it ( 'coerces undefined device name to null' , async ( ) => {
198+ deviceList = [
199+ {
200+ id : 'test-device' ,
201+ sessionTokenId : 'test' ,
202+ name : undefined as any , // Simulate undefined from database
203+ pushEndpointExpired : false ,
204+ availableCommands : { } ,
205+ location : { } ,
206+ } as AttachedDevice ,
207+ ] ;
208+ oauthClients = [ ] ;
209+ sessions = [ ] ;
210+
211+ const results = await factory . build ( '1234' , 'en' ) ;
212+
213+ assert . strictEqual ( results [ 0 ] . name , null ) ;
214+ } ) ;
215+
216+ it ( 'coerces undefined client_name to null' , async ( ) => {
217+ oauthClients = [
218+ {
219+ refresh_token_id : 'test-oauth' ,
220+ created_time : Date . now ( ) ,
221+ last_access_time : Date . now ( ) ,
222+ client_name : undefined as any , // Simulate undefined from database
223+ client_id : null as any ,
224+ scope : null as any ,
225+ } as AttachedOAuthClient ,
226+ ] ;
227+ deviceList = [ ] ;
228+ sessions = [ ] ;
229+
230+ const results = await factory . build ( '1234' , 'en' ) ;
231+
232+ // Verify name is null, not undefined (required for validation)
233+ assert . strictEqual ( results [ 0 ] . name , null ) ;
234+ } ) ;
196235 } ) ;
197236} ) ;
0 commit comments