use openstreetmap_api::types; use openstreetmap_api::Openstreetmap; use pretty_assertions::assert_eq; use rstest::*; use wiremock::matchers::{method, path, query_param}; use wiremock::{Mock, MockServer, ResponseTemplate}; use super::utils::no_credentials; #[rstest(response_str, expected, case( r##" "##, types::Map { bounds: types::BoundingBox { left: 1.0, bottom: 2.0, right: 3.0, top: 4.0, }, nodes: vec![ types::Node { id: 1150316, visible: true, version: 1, changeset: 2297, timestamp: "2009-12-09T08:19:00Z".into(), user: Some("guggis".into()), uid: Some(1), lat: Some(1.0), lon: Some(1.0), tags: vec![], }, types::Node { id: 2935283, visible: true, version: 1, changeset: 3180, timestamp: "2010-02-19T16:29:45Z".into(), user: Some("EtienneChove".into()), uid: Some(34), lat: Some(1.0), lon:Some( 1.0), tags: vec![ types::Tag { k: "#".into(), v: "#".into(), }, types::Tag { k: "place".into(), v: "locality".into(), }, ], }, ], ways: vec![types::Way { id: 49780, visible: true, version: 1, changeset: 2308, timestamp: "2009-12-09T08:51:50Z".into(), user: "guggis".into(), uid: 1, node_refs: vec![ types::NodeRef { node_id: 1150401 }, types::NodeRef { node_id: 1150400 }, ], tags: vec![types::Tag { k: "random-key.1".into(), v: "random-value.1".into(), }], }], relations: vec![types::Relation { id: 4507, visible: true, version: 1, changeset: 3198, timestamp: "2010-02-25T19:52:18Z".into(), user: "rus".into(), uid: 96, members: vec![ types::Member { member_type: "way".into(), node_id: 80976, role: "outer".into(), }, types::Member { member_type: "way".into(), node_id: 80977, role: "outer".into(), }, ], tags: vec![types::Tag { k: "type".into(), v: "multipolygon".into(), }], }], } ) )] #[actix_rt::test] async fn test_get(no_credentials: types::Credentials, response_str: &str, expected: types::Map) { /* GIVEN an OSM client WHEN calling the map() function THEN returns the list of nodes, ways and relations inside the bbox */ // GIVEN let mock_server = MockServer::start().await; Mock::given(method("GET")) .and(path("/api/0.6/map")) .and(query_param("bbox", "1,2,3,4")) .respond_with(ResponseTemplate::new(200).set_body_raw(response_str, "application/xml")) .mount(&mock_server) .await; let client = Openstreetmap::new(mock_server.uri(), no_credentials); let bbox = types::BoundingBox { left: 1.0, bottom: 2.0, right: 3.0, top: 4.0, }; // WHEN let actual = client.map(&bbox).await.unwrap(); // THEN assert_eq!(actual, expected); }