11import  path  from  "path" 
2+ import  fs  from  "fs" 
23
34import  {  setActivePinia  }  from  "pinia" 
45import  {  createTestingPinia  }  from  "@pinia/testing" 
@@ -17,19 +18,25 @@ import {
1718import  { 
1819  executable_name , 
1920  executable_path , 
20-   kill_viewer , 
2121  run_viewer , 
22+   run_back , 
23+   kill_viewer , 
24+   kill_back , 
2225}  from  "@ogw_f/utils/local" 
2326
2427import  Status  from  "@ogw_f/utils/status" 
2528
29+ import  {  api_fetch  }  from  "@ogw_f/composables/api_fetch" 
2630import  *  as  composables  from  "@ogw_f/composables/viewer_call" 
2731import  {  useDataStyleStore  }  from  "@ogw_f/stores/data_style" 
2832import  {  useDataBaseStore  }  from  "@ogw_f/stores/data_base" 
2933import  {  useViewerStore  }  from  "@ogw_f/stores/viewer" 
3034import  {  useInfraStore  }  from  "@ogw_f/stores/infra" 
35+ import  {  useGeodeStore  }  from  "@ogw_f/stores/geode" 
3136
3237import  viewer_schemas  from  "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json" 
38+ import  back_schemas  from  "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json" 
39+ import  appMode  from  "@ogw_f/utils/app_mode" 
3340import  {  WebSocket  }  from  "ws" 
3441
3542const  mesh_edges_schemas  =  viewer_schemas . opengeodeweb_viewer . mesh . edges 
@@ -45,18 +52,50 @@ vi.stubGlobal("navigator", {
4552  } , 
4653} ) 
4754
55+ let  foldersBeforeTests  =  new  Set ( ) 
56+ const  data_folder_path  =  path . join ( __dirname ,  ".." ,  ".." ,  ".." ,  "data" ) 
57+ 
58+ function  getCurrentFolders ( dataFolderPath )  { 
59+   if  ( ! fs . existsSync ( dataFolderPath ) )  { 
60+     return  new  Set ( ) 
61+   } 
62+   const  entries  =  fs . readdirSync ( dataFolderPath ) 
63+   const  folders  =  new  Set ( ) 
64+   for  ( const  entry  of  entries )  { 
65+     const  entryPath  =  path . join ( dataFolderPath ,  entry ) 
66+     if  ( fs . statSync ( entryPath ) . isDirectory ( ) )  { 
67+       folders . add ( entry ) 
68+     } 
69+   } 
70+   return  folders 
71+ } 
72+ 
73+ function  cleanupCreatedFolders ( dataFolderPath ,  foldersBeforeTests )  { 
74+   if  ( ! fs . existsSync ( dataFolderPath ) )  { 
75+     return 
76+   } 
77+   const  currentFolders  =  getCurrentFolders ( dataFolderPath ) 
78+   for  ( const  folder  of  currentFolders )  { 
79+     if  ( ! foldersBeforeTests . has ( folder ) )  { 
80+       const  folderPath  =  path . join ( dataFolderPath ,  folder ) 
81+       fs . rmSync ( folderPath ,  {  recursive : true ,  force : true  } ) 
82+     } 
83+   } 
84+ } 
85+ 
4886beforeAll ( ( )  =>  { 
4987  global . WebSocket  =  WebSocket 
88+   foldersBeforeTests  =  getCurrentFolders ( data_folder_path ) 
5089} ) 
5190
5291afterAll ( ( )  =>  { 
5392  delete  global . WebSocket 
93+   cleanupCreatedFolders ( data_folder_path ,  foldersBeforeTests ) 
5494} ) 
5595
56- const  id  =  "fake_id" 
57- const  file_name  =  "edged_curve.vtp " 
96+ let  id  =  "fake_id" 
97+ const  file_name  =  "test.og_edc2d " 
5898const  geode_object  =  "EdgedCurve2D" 
59- const  object_type  =  "mesh" 
6099
61100beforeEach ( async  ( )  =>  { 
62101  const  pinia  =  createTestingPinia ( { 
@@ -66,32 +105,71 @@ beforeEach(async () => {
66105  setActivePinia ( pinia ) 
67106  const  dataStyleStore  =  useDataStyleStore ( ) 
68107  const  dataBaseStore  =  useDataBaseStore ( ) 
108+   const  geodeStore  =  useGeodeStore ( ) 
69109  const  viewerStore  =  useViewerStore ( ) 
70110  const  infraStore  =  useInfraStore ( ) 
71-   infraStore . app_mode  =  appMode . appMode . BROWSER 
111+   infraStore . app_mode  =  appMode . BROWSER 
112+ 
113+   if  ( ! fs . existsSync ( data_folder_path ) )  { 
114+     fs . mkdirSync ( data_folder_path ,  {  recursive : true  } ) 
115+   } 
116+ 
117+   const  back_path  =  path . join ( 
118+     executable_path ( path . join ( "tests" ,  "integration" ,  "microservices" ,  "back" ) ) , 
119+     executable_name ( "opengeodeweb-back" ) , 
120+   ) 
72121  const  viewer_path  =  path . join ( 
73122    executable_path ( 
74123      path . join ( "tests" ,  "integration" ,  "microservices" ,  "viewer" ) , 
75124    ) , 
76-     executable_name ( "opengeodeweb_viewer " ) , 
125+     executable_name ( "opengeodeweb-viewer " ) , 
77126  ) 
78-   const  viewer_port  =  await  run_viewer ( viewer_path ,  { 
127+ 
128+   const  back_promise  =  run_back ( back_path ,  { 
129+     port : 5000 , 
130+     data_folder_path, 
131+   } ) 
132+ 
133+   const  viewer_promise  =  run_viewer ( viewer_path ,  { 
79134    port : 1234 , 
80-     data_folder_path :  path . join ( __dirname ,   ".." ,   ".." ,   ".." ,   "data" ) , 
135+     data_folder_path, 
81136  } ) 
137+ 
138+   const  [ back_port ,  viewer_port ]  =  await  Promise . all ( [ 
139+     back_promise , 
140+     viewer_promise , 
141+   ] ) 
142+   console . log ( "Viewer path:" ,  viewer_path ) 
143+   geodeStore . default_local_port  =  back_port 
82144  viewerStore . default_local_port  =  viewer_port 
83145  await  viewerStore . ws_connect ( ) 
84-   await  dataBaseStore . registerObject ( id ,  file_name ,  object_type ) 
85-   await  dataStyleStore . addDataStyle ( id ,  geode_object ,  object_type ) 
146+   console . log ( "schema" ,  back_schemas . opengeodeweb_back . save_viewable_file ) 
147+ 
148+   const  response  =  await  api_fetch ( { 
149+     schema : back_schemas . opengeodeweb_back . save_viewable_file , 
150+     params : { 
151+       input_geode_object : geode_object , 
152+       filename : file_name , 
153+     } , 
154+   } ) 
155+   id  =  response . data . value . id 
156+ 
157+   await  dataBaseStore . registerObject ( id ,  "mesh" ) 
158+   await  dataStyleStore . addDataStyle ( id ,  geode_object ,  "mesh" ) 
159+ 
86160  expect ( viewerStore . status ) . toBe ( Status . CONNECTED ) 
87161} ,  15000 ) 
88162
89- describe ( "Mesh edges" ,  ( )  =>  { 
90-   afterEach ( async  ( )  =>  { 
91-     const  viewerStore  =  useViewerStore ( ) 
92-     await  kill_viewer ( viewerStore . default_local_port ) 
93-   } ) 
163+ afterEach ( async  ( )  =>  { 
164+   const  viewerStore  =  useViewerStore ( ) 
165+   const  geodeStore  =  useGeodeStore ( ) 
166+   await  Promise . all ( [ 
167+     kill_viewer ( viewerStore . default_local_port ) , 
168+     kill_back ( geodeStore . default_local_port ) , 
169+   ] ) 
170+ } ) 
94171
172+ describe ( "Mesh edges" ,  ( )  =>  { 
95173  describe ( "Edges visibility" ,  ( )  =>  { 
96174    test ( "test visibility true" ,  async  ( )  =>  { 
97175      const  dataStyleStore  =  useDataStyleStore ( ) 
0 commit comments