@@ -5,28 +5,79 @@ import {
55} from "../lib/storage/account-port.js" ;
66
77describe ( "account port helpers" , ( ) => {
8- it ( "exports transaction snapshot when active" , async ( ) => {
8+ it ( "exports transaction snapshot when active for the current storage path " , async ( ) => {
99 const exportAccountsToFile = vi . fn ( async ( ) => undefined ) ;
10+ const snapshot = {
11+ version : 3 as const ,
12+ accounts : [ { refreshToken : "snapshot-token" } ] ,
13+ activeIndex : 0 ,
14+ activeIndexByFamily : { } ,
15+ } ;
16+ const readCurrentStorageUnlocked = vi . fn ( ) ;
17+ const readCurrentStorage = vi . fn ( ) ;
18+
1019 await exportAccountsSnapshot ( {
1120 resolvedPath : "/tmp/out.json" ,
1221 force : true ,
1322 currentStoragePath : "/tmp/accounts.json" ,
1423 transactionState : {
1524 active : true ,
1625 storagePath : "/tmp/accounts.json" ,
26+ snapshot,
27+ } ,
28+ readCurrentStorageUnlocked,
29+ readCurrentStorage,
30+ exportAccountsToFile,
31+ logInfo : vi . fn ( ) ,
32+ } ) ;
33+ expect ( readCurrentStorageUnlocked ) . not . toHaveBeenCalled ( ) ;
34+ expect ( readCurrentStorage ) . not . toHaveBeenCalled ( ) ;
35+ expect ( exportAccountsToFile ) . toHaveBeenCalledWith (
36+ expect . objectContaining ( {
37+ storage : snapshot ,
38+ } ) ,
39+ ) ;
40+ } ) ;
41+
42+ it ( "reads current storage without reusing a stale transaction snapshot from another path" , async ( ) => {
43+ const exportAccountsToFile = vi . fn ( async ( ) => undefined ) ;
44+ const readCurrentStorageUnlocked = vi . fn ( async ( ) => ( {
45+ version : 3 as const ,
46+ accounts : [ { refreshToken : "live-token" } ] ,
47+ activeIndex : 0 ,
48+ activeIndexByFamily : { } ,
49+ } ) ) ;
50+ const readCurrentStorage = vi . fn ( ) ;
51+
52+ await exportAccountsSnapshot ( {
53+ resolvedPath : "/tmp/out.json" ,
54+ force : true ,
55+ currentStoragePath : "/tmp/accounts.json" ,
56+ transactionState : {
57+ active : true ,
58+ storagePath : "/tmp/other.json" ,
1759 snapshot : {
1860 version : 3 ,
19- accounts : [ ] ,
61+ accounts : [ { refreshToken : "stale-token" } ] ,
2062 activeIndex : 0 ,
2163 activeIndexByFamily : { } ,
2264 } ,
2365 } ,
24- loadAccountsInternal : vi . fn ( ) ,
25- readCurrentStorage : vi . fn ( ) ,
66+ readCurrentStorageUnlocked ,
67+ readCurrentStorage,
2668 exportAccountsToFile,
2769 logInfo : vi . fn ( ) ,
2870 } ) ;
29- expect ( exportAccountsToFile ) . toHaveBeenCalled ( ) ;
71+
72+ expect ( readCurrentStorageUnlocked ) . toHaveBeenCalledTimes ( 1 ) ;
73+ expect ( readCurrentStorage ) . not . toHaveBeenCalled ( ) ;
74+ expect ( exportAccountsToFile ) . toHaveBeenCalledWith (
75+ expect . objectContaining ( {
76+ storage : expect . objectContaining ( {
77+ accounts : [ { refreshToken : "live-token" } ] ,
78+ } ) ,
79+ } ) ,
80+ ) ;
3081 } ) ;
3182
3283 it ( "imports through transaction helper and logs result" , async ( ) => {
0 commit comments