Skip to content

Commit

Permalink
Merge pull request #955 from hove-io/fix/odt_reservation
Browse files Browse the repository at this point in the history
ODT Reservation : odt_reservation_name is now optional
  • Loading branch information
datanel authored Jul 30, 2024
2 parents b00bdbb + 919126b commit 2f36d54
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Hove <[email protected]>", "Guillaume Pinot <[email protected]>"]
name = "transit_model"
version = "0.63.0"
version = "0.64.0"
license = "AGPL-3.0-only"
description = "Transit data management"
repository = "https://github.com/hove-io/transit_model"
Expand Down
6 changes: 3 additions & 3 deletions src/ntfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,23 +1102,23 @@ mod tests {
let odt_reservations = CollectionWithId::new(vec![
ODTReservation {
id: "odt:1".to_string(),
name: "name:1".to_string(),
name: Some("name:1".to_string()),
url: Some("https://reservation1".to_string()),
phone: Some("01 02 03 04 01".to_string()),
conditions: Some("lundi au vendredi de 9h à 18h".to_string()),
deeplink: Some("https://deeplink1".to_string()),
},
ODTReservation {
id: "odt:2".to_string(),
name: "name:2".to_string(),
name: None,
url: Some("https://reservation2".to_string()),
phone: Some("01 02 03 04 02".to_string()),
conditions: Some("lundi au samedi de 8h à 15h".to_string()),
deeplink: Some("https://deeplink2".to_string()),
},
ODTReservation {
id: "odt:3".to_string(),
name: "name:3".to_string(),
name: Some("name:3".to_string()),
url: Some("https://reservation3".to_string()),
phone: Some("01 02 03 04 03".to_string()),
conditions: Some("lundi au mardi de 9h à 10h".to_string()),
Expand Down
2 changes: 1 addition & 1 deletion src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ pub struct ODTReservation {
#[serde(rename = "odt_reservation_id")]
pub id: String,
#[serde(rename = "odt_reservation_name")]
pub name: String,
pub name: Option<String>,
#[serde(rename = "odt_reservation_url")]
pub url: Option<String>,
#[serde(rename = "odt_reservation_phone")]
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/ntfs/odt_reservation_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object_id,object_type,odt_reservation_id
M1F1,trip,odtres1
RERAB1,trip,odtres2
RERA,line,odtres3
4 changes: 4 additions & 0 deletions tests/fixtures/ntfs/odt_reservations.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
odt_reservation_id,odt_reservation_name,odt_reservation_url,odt_reservation_phone,odt_reservation_conditions,odt_reservation_deeplink
odtres1,odtres1,,01 02 03 04 99,lundi au samedi de 12h à 18h,https://deeplink1/search?departure-address={from_name}
odtres2,,https://odtreservation2.com,,,
odtres3,odtres3,https://odtreservation3.com,01 02 03 04 03,,
74 changes: 73 additions & 1 deletion tests/read_ntfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use pretty_assertions::assert_eq;
use relational_types::IdxSet;
use std::collections::HashMap;
use std::collections::{BTreeSet, HashMap};
use transit_model::model::{Collections, GetCorresponding, Model};
use transit_model::objects::*;
use transit_model::test_utils::*;
Expand Down Expand Up @@ -242,6 +242,78 @@ fn ntfs() {
stop_time_comments.insert(("RERAB1".to_string(), 5), "RERACOM1".to_string());

assert_eq!(stop_time_comments, pt_objects.stop_time_comments);

// ODT reservations
fn odt_reservations<'a>(
odt_res_ids: &'a BTreeSet<String>,
odt_reservations: &'a CollectionWithId<ODTReservation>,
) -> impl Iterator<Item = &'a ODTReservation> {
odt_res_ids
.iter()
.filter_map(move |id| odt_reservations.get(id))
}
assert_eq!(3, pt_objects.odt_reservations.len());

// Line RERA
let ids = &pt_objects.lines.get("RERA").unwrap().odt_reservation_links;
assert_eq!(1, ids.len());

let mut iter = odt_reservations(ids, &pt_objects.odt_reservations);
assert_eq!(
iter.next().unwrap(),
&ODTReservation {
id: String::from("odtres3"),
name: Some(String::from("odtres3")),
url: Some(String::from("https://odtreservation3.com")),
phone: Some(String::from("01 02 03 04 03")),
conditions: None,
deeplink: None,
}
);

// Trip M1F1
let ids = &pt_objects
.vehicle_journeys
.get("M1F1")
.unwrap()
.odt_reservation_links;
assert_eq!(1, ids.len());

let mut iter = odt_reservations(ids, &pt_objects.odt_reservations);
assert_eq!(
iter.next().unwrap(),
&ODTReservation {
id: String::from("odtres1"),
name: Some(String::from("odtres1")),
url: None,
phone: Some(String::from("01 02 03 04 99")),
conditions: Some(String::from("lundi au samedi de 12h à 18h")),
deeplink: Some(String::from(
"https://deeplink1/search?departure-address={from_name}"
)),
}
);

// Trip RERAB1
let ids = &pt_objects
.vehicle_journeys
.get("RERAB1")
.unwrap()
.odt_reservation_links;
assert_eq!(1, ids.len());

let mut iter = odt_reservations(ids, &pt_objects.odt_reservations);
assert_eq!(
iter.next().unwrap(),
&ODTReservation {
id: String::from("odtres2"),
name: None,
url: Some(String::from("https://odtreservation2.com")),
phone: None,
conditions: None,
deeplink: None,
}
);
}

#[test]
Expand Down

0 comments on commit 2f36d54

Please sign in to comment.