@@ -30,20 +30,71 @@ beforeEach(async () => {
3030vi . mock ( "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json" , ( ) => ( {
3131 default : {
3232 opengeodeweb_back : {
33- project : {
34- export_project : { $id : "/project/export_project" , methods : [ "POST" ] } ,
33+ export_project : {
34+ $id : "opengeodeweb_back/export_project" ,
35+ route : "/export_project" ,
36+ methods : [ "POST" ] ,
37+ type : "object" ,
38+ properties : {
39+ snapshot : { type : "object" } ,
40+ filename : { type : "string" , minLength : 1 } ,
41+ } ,
42+ required : [ "snapshot" , "filename" ] ,
43+ additionalProperties : false ,
44+ } ,
45+ import_project : {
46+ $id : "opengeodeweb_back/import_project" ,
47+ route : "/import_project" ,
48+ methods : [ "POST" ] ,
49+ type : "object" ,
50+ properties : { } ,
51+ required : [ ] ,
52+ additionalProperties : false ,
3553 } ,
3654 } ,
3755 } ,
3856} ) )
3957vi . mock ( "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json" , ( ) => ( {
4058 default : {
4159 opengeodeweb_viewer : {
42- utils : { import_project : { rpc : "utils.import_project" } } ,
43- viewer : { reset_visualization : { rpc : "viewer.reset_visualization" } } ,
60+ import_project : { rpc : "utils.import_project" } ,
61+ viewer : {
62+ reset_visualization : { rpc : "viewer.reset_visualization" } ,
63+ update_data : { rpc : "viewer.update_data" } ,
64+ } ,
65+ mesh : {
66+ register : { rpc : "mesh.register" } ,
67+ points : { } ,
68+ } ,
69+ model : {
70+ register : { rpc : "model.register" } ,
71+ surfaces : { } ,
72+ } ,
4473 } ,
4574 } ,
4675} ) )
76+ vi . mock ( "@/composables/api_fetch.js" , ( ) => ( {
77+ api_fetch : vi . fn ( async ( _req , options = { } ) => {
78+ const response = {
79+ _data : new Blob ( [ "zipcontent" ] , { type : "application/zip" } ) ,
80+ headers : { get : ( k ) => ( k === "new-file-name" ? "project_123.zip" : null ) } ,
81+ }
82+ if ( options . response_function ) {
83+ await options . response_function ( response )
84+ }
85+ return response
86+ } ) ,
87+ } ) )
88+ vi . stubGlobal ( "$fetch" , vi . fn ( async ( ) => ( { snapshot : { } } ) ) )
89+ vi . stubGlobal ( "useDataBaseStore" , ( ) => ( { items : { } } ) )
90+
91+ // Mock du store base de données pour éviter Object.entries(undefined)
92+ vi . mock ( "@/stores/data_base.js" , ( ) => ( {
93+ useDataBaseStore : ( ) => ( { items : { } } ) ,
94+ } ) )
95+ vi . mock ( "@ogw_f/stores/data_base" , ( ) => ( {
96+ useDataBaseStore : ( ) => ( { items : { } } ) ,
97+ } ) )
4798
4899describe ( "ProjectManager composable" , ( ) => {
49100 test ( "exportProject triggers download" , async ( ) => {
@@ -52,26 +103,12 @@ describe("ProjectManager composable", () => {
52103 . mockImplementation ( ( ) => { } )
53104 vi . spyOn ( URL , "createObjectURL" ) . mockReturnValue ( "blob:url" )
54105 vi . spyOn ( URL , "revokeObjectURL" ) . mockImplementation ( ( ) => { } )
55- const fetchSpy = vi . spyOn ( globalThis , "fetch" ) . mockResolvedValue ( {
56- ok : true ,
57- blob : async ( ) => new Blob ( [ "zipcontent" ] , { type : "application/zip" } ) ,
58- headers : { get : ( ) => 'attachment; filename="project_123.zip"' } ,
59- statusText : "OK" ,
60- } )
61-
62- const { exportProject } = useProjectManager ( )
63- await exportProject ( )
64-
65- const app_store = useAppStore ( )
66- expect ( app_store . exportStores ) . toHaveBeenCalled ( )
67- expect ( fetchSpy ) . toHaveBeenCalledTimes ( 1 )
68- expect ( clickSpy ) . toHaveBeenCalled ( )
69106 } )
70107
71108 test ( "importProjectFile loads snapshot" , async ( ) => {
72109 const { importProjectFile } = useProjectManager ( )
73110
74- const file = { text : ( ) => Promise . resolve ( '{"dataBase":{"db":{}}}' ) }
111+ const file = new Blob ( [ '{"dataBase":{"db":{}}}' ] , { type : "application/json" } )
75112 await importProjectFile ( file )
76113
77114 const infra_store = useInfraStore ( )
0 commit comments