@@ -16,8 +16,8 @@ describe("App Store", () => {
1616 test ( "initial state" , ( ) => {
1717 const app_store = useAppStore ( )
1818 expectTypeOf ( app_store . stores ) . toBeArray ( )
19- expectTypeOf ( app_store . save ) . toBeFunction ( )
20- expectTypeOf ( app_store . load ) . toBeFunction ( )
19+ expectTypeOf ( app_store . exportStore ) . toBeFunction ( )
20+ expectTypeOf ( app_store . importStore ) . toBeFunction ( )
2121 expectTypeOf ( app_store . registerStore ) . toBeFunction ( )
2222 } )
2323 } )
@@ -60,54 +60,54 @@ describe("App Store", () => {
6060 } )
6161 } )
6262
63- describe ( "save " , ( ) => {
64- test ( "save stores with save method" , ( ) => {
63+ describe ( "Export " , ( ) => {
64+ test ( "export stores with exportStore method" , ( ) => {
6565 const app_store = useAppStore ( )
6666 const mock_store_1 = {
6767 $id : "userStore" ,
68- save : vi . fn ( ) . mockImplementation ( ( ) => ( {
68+ exportStore : vi . fn ( ) . mockImplementation ( ( ) => ( {
6969 name : "toto" ,
70707171 } ) ) ,
72- load : vi . fn ( ) . mockImplementation ( ( ) => { } ) ,
72+ importStore : vi . fn ( ) . mockImplementation ( ( ) => { } ) ,
7373 }
7474 const mock_store_2 = {
7575 $id : "geodeStore" ,
76- save : vi . fn ( ) . mockImplementation ( ( ) => ( { items : [ ] , total : 0 } ) ) ,
77- load : vi . fn ( ) . mockImplementation ( ( ) => { } ) ,
76+ exportStore : vi . fn ( ) . mockImplementation ( ( ) => ( { items : [ ] , total : 0 } ) ) ,
77+ importStore : vi . fn ( ) . mockImplementation ( ( ) => { } ) ,
7878 }
7979
8080 app_store . registerStore ( mock_store_1 )
8181 app_store . registerStore ( mock_store_2 )
8282
83- const snapshot = app_store . save ( )
83+ const snapshot = app_store . exportStore ( )
8484
85- expect ( mock_store_1 . save ) . toHaveBeenCalledTimes ( 1 )
86- expect ( mock_store_2 . save ) . toHaveBeenCalledTimes ( 1 )
85+ expect ( mock_store_1 . exportStore ) . toHaveBeenCalledTimes ( 1 )
86+ expect ( mock_store_2 . exportStore ) . toHaveBeenCalledTimes ( 1 )
8787 expect ( snapshot ) . toEqual ( {
8888 userStore :
{ name :
"toto" , email :
"[email protected] " } , 8989 geodeStore : { items : [ ] , total : 0 } ,
9090 } )
9191 } )
9292
93- test ( "skip stores without save method" , ( ) => {
93+ test ( "skip stores without exportSave method" , ( ) => {
9494 const app_store = useAppStore ( )
9595 const mock_store_1 = {
9696 $id : "withSave" ,
97- save : vi . fn ( ) . mockImplementation ( ( ) => ( { data : "test" } ) ) ,
98- load : vi . fn ( ) . mockImplementation ( ( ) => { } ) ,
97+ exportStore : vi . fn ( ) . mockImplementation ( ( ) => ( { data : "test" } ) ) ,
98+ importStore : vi . fn ( ) . mockImplementation ( ( ) => { } ) ,
9999 }
100100 const mock_store_2 = {
101101 $id : "withoutSave" ,
102- load : vi . fn ( ) . mockImplementation ( ( ) => { } ) ,
102+ importStore : vi . fn ( ) . mockImplementation ( ( ) => { } ) ,
103103 }
104104
105105 app_store . registerStore ( mock_store_1 )
106106 app_store . registerStore ( mock_store_2 )
107107
108- const snapshot = app_store . save ( )
108+ const snapshot = app_store . exportStore ( )
109109
110- expect ( mock_store_1 . save ) . toHaveBeenCalledTimes ( 1 )
110+ expect ( mock_store_1 . exportStore ) . toHaveBeenCalledTimes ( 1 )
111111 expect ( snapshot ) . toEqual ( {
112112 withSave : { data : "test" } ,
113113 } )
@@ -116,76 +116,64 @@ describe("App Store", () => {
116116
117117 test ( "return empty snapshot when no stores registered" , ( ) => {
118118 const app_store = useAppStore ( )
119- const snapshot = app_store . save ( )
119+ const snapshot = app_store . exportStore ( )
120120 expect ( snapshot ) . toEqual ( { } )
121121 } )
122122 } )
123123
124124 describe ( "load" , ( ) => {
125- test ( "App Store > actions > load > load stores with load method" , async ( ) => {
125+ test ( "App Store > actions > importStore > import stores with importStore method" , async ( ) => {
126126 const appStore = useAppStore ( )
127-
128127 const userStore = {
129128 $id : "userStore" ,
130- load : vi . fn ( ) . mockResolvedValue ( ) ,
129+ importStore : vi . fn ( ) . mockResolvedValue ( ) ,
131130 }
132131 const geodeStore = {
133132 $id : "geodeStore" ,
134- load : vi . fn ( ) . mockResolvedValue ( ) ,
133+ importStore : vi . fn ( ) . mockResolvedValue ( ) ,
135134 }
136-
137135 appStore . registerStore ( userStore )
138136 appStore . registerStore ( geodeStore )
139-
140137 const snapshot = {
141138 userStore : { some : "data" } ,
142139 geodeStore : { other : "data" } ,
143140 }
144-
145- await appStore . load ( snapshot )
146- expect ( userStore . load ) . toHaveBeenCalledTimes ( 1 )
147- expect ( geodeStore . load ) . toHaveBeenCalledTimes ( 1 )
141+ await appStore . importStore ( snapshot )
142+ expect ( userStore . importStore ) . toHaveBeenCalledTimes ( 1 )
143+ expect ( geodeStore . importStore ) . toHaveBeenCalledTimes ( 1 )
148144 } )
149-
150- test ( "skip stores without load method" , ( ) => {
145+
146+ test ( "skip stores without importStore method" , ( ) => {
151147 const app_store = useAppStore ( )
152148 const mock_store_1 = {
153- $id : "withLoad " ,
149+ $id : "withImport " ,
154150 save : vi . fn ( ) . mockImplementation ( ( ) => { } ) ,
155- load : vi . fn ( ) . mockImplementation ( ( ) => { } ) ,
151+ importStore : vi . fn ( ) . mockImplementation ( ( ) => { } ) ,
156152 }
157153 const mock_store_2 = {
158- $id : "withoutLoad " ,
154+ $id : "withoutImport " ,
159155 save : vi . fn ( ) . mockImplementation ( ( ) => { } ) ,
160156 }
161-
162157 app_store . registerStore ( mock_store_1 )
163158 app_store . registerStore ( mock_store_2 )
164-
165159 const snapshot = {
166- withLoad : { data : "test" } ,
167- withoutLoad : { data : "ignored" } ,
160+ withImport : { data : "test" } ,
161+ withoutImport : { data : "ignored" } ,
168162 }
169-
170- app_store . load ( snapshot )
171-
172- expect ( mock_store_1 . load ) . toHaveBeenCalledTimes ( 1 )
173- expect ( mock_store_2 . load ) . toBeUndefined ( )
163+ app_store . importStore ( snapshot )
164+ expect ( mock_store_1 . importStore ) . toHaveBeenCalledTimes ( 1 )
165+ expect ( mock_store_2 . importStore ) . toBeUndefined ( )
174166 } )
175-
167+
176168 test ( "warn when store not found in snapshot" , ( ) => {
177169 const app_store = useAppStore ( )
178- const console_warn_spy = vi
179- . spyOn ( console , "warn" )
180- . mockImplementation ( ( ) => { } )
170+ const console_warn_spy = vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } )
181171 const mock_store = {
182172 $id : "testStore" ,
183- load : vi . fn ( ) . mockImplementation ( ( ) => { } ) ,
173+ importStore : vi . fn ( ) . mockImplementation ( ( ) => { } ) ,
184174 }
185-
186175 app_store . registerStore ( mock_store )
187- app_store . load ( { } )
188-
176+ app_store . importStore ( { } )
189177 expect ( console_warn_spy ) . toHaveBeenCalledWith (
190178 expect . stringContaining ( "Stores not found in snapshot: testStore" ) ,
191179 )
0 commit comments