|
| 1 | +use crate::models::NewDeletedCrate; |
| 2 | +use crate::tests::builders::PublishBuilder; |
| 3 | +use crate::tests::util::{RequestHelper, TestApp}; |
| 4 | +use chrono::{Duration, Utc}; |
| 5 | +use crates_io_database::schema::deleted_crates; |
| 6 | +use diesel_async::RunQueryDsl; |
| 7 | +use googletest::prelude::*; |
| 8 | +use http::StatusCode; |
| 9 | +use insta::assert_snapshot; |
| 10 | + |
| 11 | +#[tokio::test(flavor = "multi_thread")] |
| 12 | +async fn test_recently_deleted_crate_with_same_name() -> anyhow::Result<()> { |
| 13 | + let (app, _, _, token) = TestApp::full().with_token(); |
| 14 | + let mut conn = app.async_db_conn().await; |
| 15 | + |
| 16 | + let now = Utc::now(); |
| 17 | + let created_at = now - Duration::hours(24); |
| 18 | + let deleted_at = now - Duration::hours(1); |
| 19 | + let available_at = "2099-12-25T12:34:56Z".parse()?; |
| 20 | + |
| 21 | + let deleted_crate = NewDeletedCrate::builder("actix_web") |
| 22 | + .created_at(&created_at) |
| 23 | + .deleted_at(&deleted_at) |
| 24 | + .available_at(&available_at) |
| 25 | + .build(); |
| 26 | + |
| 27 | + diesel::insert_into(deleted_crates::table) |
| 28 | + .values(deleted_crate) |
| 29 | + .execute(&mut conn) |
| 30 | + .await?; |
| 31 | + |
| 32 | + let crate_to_publish = PublishBuilder::new("actix-web", "1.0.0"); |
| 33 | + let response = token.publish_crate(crate_to_publish).await; |
| 34 | + assert_eq!(response.status(), StatusCode::BAD_REQUEST); |
| 35 | + assert_snapshot!(response.text(), @r#"{"errors":[{"detail":"A crate with the name `actix_web` was recently deleted. Reuse of this name will be available after 2099-12-25T12:34:56Z."}]}"#); |
| 36 | + assert_that!(app.stored_files().await, empty()); |
| 37 | + |
| 38 | + Ok(()) |
| 39 | +} |
0 commit comments