|
1 | 1 | //! Tests for [`crate::controller::map`]. |
2 | 2 |
|
3 | 3 | use crate::model::dto::UpdateMapGeometryDto; |
| 4 | +use crate::test::util::data; |
4 | 5 | use crate::test::util::dummy_map_polygons::small_rectangle; |
5 | 6 | use crate::{ |
6 | 7 | model::{ |
@@ -165,6 +166,52 @@ async fn test_can_create_map() { |
165 | 166 | assert_eq!(resp.status(), StatusCode::OK); |
166 | 167 | } |
167 | 168 |
|
| 169 | +#[actix_rt::test] |
| 170 | +async fn test_conflict_on_create_map_with_taken_name() { |
| 171 | + let taken_name = "taken name"; |
| 172 | + let pool = init_test_database(|conn| { |
| 173 | + async { |
| 174 | + diesel::insert_into(crate::schema::maps::table) |
| 175 | + .values(data::TestInsertableMap { |
| 176 | + name: taken_name.to_owned(), |
| 177 | + ..Default::default() |
| 178 | + }) |
| 179 | + .execute(conn) |
| 180 | + .await?; |
| 181 | + Ok(()) |
| 182 | + } |
| 183 | + .scope_boxed() |
| 184 | + }) |
| 185 | + .await; |
| 186 | + let (token, app) = init_test_app(pool.clone()).await; |
| 187 | + |
| 188 | + let map_update = NewMapDto { |
| 189 | + name: taken_name.to_owned(), |
| 190 | + creation_date: NaiveDate::from_ymd_opt(2023, 5, 8).expect("Could not parse date!"), |
| 191 | + deletion_date: None, |
| 192 | + last_visit: None, |
| 193 | + is_inactive: false, |
| 194 | + zoom_factor: 100, |
| 195 | + honors: 0, |
| 196 | + visits: 0, |
| 197 | + harvested: 0, |
| 198 | + privacy: PrivacyOption::Public, |
| 199 | + description: None, |
| 200 | + location: None, |
| 201 | + geometry: tall_rectangle(), |
| 202 | + }; |
| 203 | + |
| 204 | + let resp = test::TestRequest::post() |
| 205 | + .uri("/api/maps") |
| 206 | + .insert_header((header::AUTHORIZATION, token)) |
| 207 | + .set_json(map_update) |
| 208 | + .send_request(&app) |
| 209 | + .await; |
| 210 | + |
| 211 | + // Expect conflict since the map name is already present in the database |
| 212 | + assert_eq!(resp.status(), StatusCode::CONFLICT); |
| 213 | +} |
| 214 | + |
168 | 215 | #[actix_rt::test] |
169 | 216 | async fn test_update_fails_for_not_owner() { |
170 | 217 | let pool = init_test_database(|conn| { |
|
0 commit comments