@@ -136,7 +136,6 @@ defmodule TransportWeb.API.DatasetControllerTest do
136136 custom_title: "title" ,
137137 type: "public-transit" ,
138138 licence: "lov2" ,
139- datagouv_id: datagouv_id = "datagouv" ,
140139 slug: "slug-1" ,
141140 is_active: true ,
142141 created_at: ~U[ 2021-12-23 13:30:40.000000Z] ,
@@ -157,9 +156,9 @@ defmodule TransportWeb.API.DatasetControllerTest do
157156 dataset_subtypes: [ ds1 ]
158157 )
159158
160- resource_1 =
159+ gtfs_resource_1 =
161160 insert ( :resource ,
162- dataset_id : dataset . id ,
161+ dataset : dataset ,
163162 url: "https://link.to/file.zip" ,
164163 latest_url: "https://static.data.gouv.fr/foo" ,
165164 datagouv_id: "1" ,
@@ -168,9 +167,9 @@ defmodule TransportWeb.API.DatasetControllerTest do
168167 filesize: 42
169168 )
170169
171- resource_2 =
170+ gtfs_resource_2 =
172171 insert ( :resource ,
173- dataset_id : dataset . id ,
172+ dataset : dataset ,
174173 url: "https://link.to/file2.zip" ,
175174 latest_url: "https://static.data.gouv.fr/foo2" ,
176175 datagouv_id: "2" ,
@@ -181,7 +180,7 @@ defmodule TransportWeb.API.DatasetControllerTest do
181180
182181 gbfs_resource =
183182 insert ( :resource ,
184- dataset_id : dataset . id ,
183+ dataset : dataset ,
185184 url: "https://link.to/gbfs.json" ,
186185 latest_url: "https://link.to/latest" ,
187186 datagouv_id: "3" ,
@@ -191,10 +190,22 @@ defmodule TransportWeb.API.DatasetControllerTest do
191190 is_available: false
192191 )
193192
193+ netex_resource =
194+ insert ( :resource ,
195+ dataset: dataset ,
196+ url: "https://link.to/file3.zip" ,
197+ latest_url: "https://static.data.gouv.fr/foo3" ,
198+ datagouv_id: "4" ,
199+ title: "NeTEx" ,
200+ type: "main" ,
201+ format: "NeTEx" ,
202+ filesize: 43
203+ )
204+
194205 insert ( :resource_metadata ,
195206 multi_validation:
196207 insert ( :multi_validation ,
197- resource_history: insert ( :resource_history , resource_id: resource_1 . id ) ,
208+ resource_history: insert ( :resource_history , resource: gtfs_resource_1 ) ,
198209 validator: Transport.Validators.GTFSTransport . validator_name ( )
199210 ) ,
200211 modes: [ "bus" ] ,
@@ -205,31 +216,42 @@ defmodule TransportWeb.API.DatasetControllerTest do
205216 insert ( :resource_metadata ,
206217 multi_validation:
207218 insert ( :multi_validation ,
208- resource_history: insert ( :resource_history , resource_id: resource_2 . id ) ,
219+ resource_history: insert ( :resource_history , resource: gtfs_resource_2 ) ,
209220 validator: Transport.Validators.GTFSTransport . validator_name ( )
210221 ) ,
211222 modes: [ "skate" ] ,
212223 features: [ "clim" ] ,
213224 metadata: % { "foo" => "bar2" }
214225 )
215226
227+ insert ( :resource_metadata ,
228+ multi_validation:
229+ insert ( :multi_validation ,
230+ resource_history: insert ( :resource_history , resource: netex_resource ) ,
231+ validator: Transport.Validators.NeTEx.Validator . validator_name ( )
232+ ) ,
233+ modes: [ "bus" ] ,
234+ features: [ "networks" ] ,
235+ metadata: % { "foo" => "bar3" }
236+ )
237+
216238 path = Helpers . dataset_path ( conn , :datasets )
217239
218240 dataset_res = % {
219241 "community_resources" => [ ] ,
220242 "covered_area" => [ % { "insee" => "123456" , "nom" => "Angers Métropole" , "type" => "epci" } ] ,
221243 "legal_owners" => [ ] ,
222244 "created_at" => "2021-12-23" ,
223- "datagouv_id" => "datagouv" ,
224- "id" => "datagouv" ,
245+ "datagouv_id" => dataset . datagouv_id ,
246+ "id" => dataset . datagouv_id ,
225247 "licence" => "lov2" ,
226248 "page_url" => "http://127.0.0.1:5100/datasets/slug-1" ,
227249 "publisher" => % { "name" => "org" , "type" => "organization" , "id" => "org_id" } ,
228250 "resources" => [
229251 % {
230- "updated" => resource_1 . last_update |> DateTime . to_iso8601 ( ) ,
231- "page_url" => resource_page_url ( resource_1 ) ,
232- "id" => resource_1 . id ,
252+ "updated" => gtfs_resource_1 . last_update |> DateTime . to_iso8601 ( ) ,
253+ "page_url" => resource_page_url ( gtfs_resource_1 ) ,
254+ "id" => gtfs_resource_1 . id ,
233255 "datagouv_id" => "1" ,
234256 "features" => [ "couleurs des lignes" ] ,
235257 "filesize" => 42 ,
@@ -243,9 +265,9 @@ defmodule TransportWeb.API.DatasetControllerTest do
243265 "is_available" => true
244266 } ,
245267 % {
246- "updated" => resource_2 . last_update |> DateTime . to_iso8601 ( ) ,
247- "page_url" => resource_page_url ( resource_2 ) ,
248- "id" => resource_2 . id ,
268+ "updated" => gtfs_resource_2 . last_update |> DateTime . to_iso8601 ( ) ,
269+ "page_url" => resource_page_url ( gtfs_resource_2 ) ,
270+ "id" => gtfs_resource_2 . id ,
249271 "datagouv_id" => "2" ,
250272 "features" => [ "clim" ] ,
251273 "filesize" => 43 ,
@@ -269,14 +291,30 @@ defmodule TransportWeb.API.DatasetControllerTest do
269291 "type" => "main" ,
270292 "url" => gbfs_resource . latest_url ,
271293 "is_available" => gbfs_resource . is_available
294+ } ,
295+ % {
296+ "updated" => netex_resource . last_update |> DateTime . to_iso8601 ( ) ,
297+ "page_url" => resource_page_url ( netex_resource ) ,
298+ "id" => netex_resource . id ,
299+ "datagouv_id" => "4" ,
300+ "features" => [ "networks" ] ,
301+ "filesize" => 43 ,
302+ "format" => "NeTEx" ,
303+ "metadata" => % { "foo" => "bar3" } ,
304+ "modes" => [ "bus" ] ,
305+ "original_url" => "https://link.to/file3.zip" ,
306+ "title" => "NeTEx" ,
307+ "type" => "main" ,
308+ "url" => "https://static.data.gouv.fr/foo3" ,
309+ "is_available" => true
272310 }
273311 ] ,
274312 "slug" => "slug-1" ,
275313 "title" => "title" ,
276314 "type" => "public-transit" ,
277315 "sub_types" => [ "urban" ] ,
278316 "updated" =>
279- [ resource_1 , gbfs_resource , resource_2 ]
317+ [ gtfs_resource_1 , gbfs_resource , gtfs_resource_2 , netex_resource ]
280318 |> Enum . map ( & & 1 . last_update )
281319 |> Enum . max ( DateTime )
282320 |> DateTime . to_iso8601 ( ) ,
@@ -304,7 +342,7 @@ defmodule TransportWeb.API.DatasetControllerTest do
304342 |> Map . merge ( % { "history" => [ ] } )
305343 |> Map . put ( "resources" , Enum . map ( dataset_res [ "resources" ] , & Map . put ( & 1 , "conversions" , % { } ) ) )
306344
307- json = conn |> get ( Helpers . dataset_path ( conn , :by_id , datagouv_id ) ) |> json_response ( 200 )
345+ json = conn |> get ( Helpers . dataset_path ( conn , :by_id , dataset . datagouv_id ) ) |> json_response ( 200 )
308346 assert dataset_res == json
309347 assert_schema ( json , "DatasetDetails" , TransportWeb.API.Spec . spec ( ) )
310348 end
0 commit comments