@@ -5,6 +5,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
55import {
66 applyAccountSelectionFallbacks ,
77 persistAccountPool ,
8+ persistResolvedAccountSelection ,
89 resolveAccountSelection ,
910 resolveAndPersistAccountSelection ,
1011 type TokenSuccessWithAccount ,
@@ -150,4 +151,35 @@ describe("login-runner selection finalization", () => {
150151 expect ( persistSelections ) . toHaveBeenCalledTimes ( 1 ) ;
151152 expect ( persistSelections ) . toHaveBeenCalledWith ( result . variantsForPersistence , true ) ;
152153 } ) ;
154+
155+ it ( "returns the selection unchanged when no persist callback is provided" , async ( ) => {
156+ const selection = resolveAccountSelection ( {
157+ type : "success" ,
158+ access : "access-token" ,
159+ refresh : "refresh-token" ,
160+ expires : Date . now ( ) + 60_000 ,
161+ idToken : "id-token" ,
162+ } ) ;
163+
164+ await expect ( persistResolvedAccountSelection ( selection ) ) . resolves . toBe ( selection ) ;
165+ } ) ;
166+
167+ it ( "propagates persist callback failures" , async ( ) => {
168+ const selection = resolveAccountSelection ( {
169+ type : "success" ,
170+ access : "access-token" ,
171+ refresh : "refresh-token" ,
172+ expires : Date . now ( ) + 60_000 ,
173+ idToken : "id-token" ,
174+ } ) ;
175+ const persistError = new Error ( "persist failed" ) ;
176+ const persistSelections = vi . fn ( async ( ) => {
177+ throw persistError ;
178+ } ) ;
179+
180+ await expect (
181+ persistResolvedAccountSelection ( selection , { persistSelections } ) ,
182+ ) . rejects . toThrow ( "persist failed" ) ;
183+ expect ( persistSelections ) . toHaveBeenCalledTimes ( 1 ) ;
184+ } ) ;
153185} ) ;
0 commit comments