2
This commit is contained in:
@@ -33,6 +33,12 @@ struct CreateFolder<'a> {
|
||||
parent_id: Option<Uuid>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct EnsureFolderPath<'a> {
|
||||
parent_id: Option<Uuid>,
|
||||
segments: &'a [&'a str],
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct MoveDocumentRequest {
|
||||
folder_id: Option<Uuid>,
|
||||
@@ -46,10 +52,7 @@ struct DocumentDetail {
|
||||
#[tokio::test]
|
||||
async fn folder_move_and_delete_flow() -> Result<()> {
|
||||
let _lock = acquire_db_lock().await;
|
||||
let Some(app) = TestApp::new().await? else {
|
||||
eprintln!("skipping test: TEST_DATABASE_URL not set");
|
||||
return Ok(());
|
||||
};
|
||||
let app = TestApp::new().await?;
|
||||
|
||||
let password = "folderpass";
|
||||
app.insert_user("folder-admin", password, "admin").await?;
|
||||
@@ -135,3 +138,80 @@ async fn folder_move_and_delete_flow() -> Result<()> {
|
||||
app.cleanup().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn ensure_path_creates_nested_folders() -> Result<()> {
|
||||
let _lock = acquire_db_lock().await;
|
||||
let app = TestApp::new().await?;
|
||||
|
||||
let password = "pathpass";
|
||||
app.insert_user("path-admin", password, "admin").await?;
|
||||
let token = app.login_token("path-admin", password).await?;
|
||||
|
||||
let base_path = EnsureFolderPath {
|
||||
parent_id: None,
|
||||
segments: &["Team", "Engineering", "Backend"],
|
||||
};
|
||||
let first_resp = app
|
||||
.post_json("/api/folders/path", &base_path, Some(&token))
|
||||
.await?;
|
||||
assert_eq!(first_resp.status(), StatusCode::OK);
|
||||
let first_body = body_to_vec(first_resp.into_body()).await?;
|
||||
let first_folder: FolderResponse = serde_json::from_slice(&first_body)?;
|
||||
|
||||
let second_resp = app
|
||||
.post_json("/api/folders/path", &base_path, Some(&token))
|
||||
.await?;
|
||||
assert_eq!(second_resp.status(), StatusCode::OK);
|
||||
let second_body = body_to_vec(second_resp.into_body()).await?;
|
||||
let second_folder: FolderResponse = serde_json::from_slice(&second_body)?;
|
||||
assert_eq!(second_folder.folder.id, first_folder.folder.id);
|
||||
|
||||
let engineering_resp = app
|
||||
.post_json(
|
||||
"/api/folders/path",
|
||||
&EnsureFolderPath {
|
||||
parent_id: None,
|
||||
segments: &["Team", "Engineering"],
|
||||
},
|
||||
Some(&token),
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(engineering_resp.status(), StatusCode::OK);
|
||||
let engineering_body = body_to_vec(engineering_resp.into_body()).await?;
|
||||
let engineering_folder: FolderResponse = serde_json::from_slice(&engineering_body)?;
|
||||
assert_ne!(engineering_folder.folder.id, first_folder.folder.id);
|
||||
|
||||
let infra_resp = app
|
||||
.post_json(
|
||||
"/api/folders/path",
|
||||
&EnsureFolderPath {
|
||||
parent_id: Some(engineering_folder.folder.id),
|
||||
segments: &["Infrastructure"],
|
||||
},
|
||||
Some(&token),
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(infra_resp.status(), StatusCode::OK);
|
||||
let infra_body = body_to_vec(infra_resp.into_body()).await?;
|
||||
let infra_folder: FolderResponse = serde_json::from_slice(&infra_body)?;
|
||||
assert_ne!(infra_folder.folder.id, engineering_folder.folder.id);
|
||||
|
||||
let infra_dupe_resp = app
|
||||
.post_json(
|
||||
"/api/folders/path",
|
||||
&EnsureFolderPath {
|
||||
parent_id: Some(engineering_folder.folder.id),
|
||||
segments: &["Infrastructure"],
|
||||
},
|
||||
Some(&token),
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(infra_dupe_resp.status(), StatusCode::OK);
|
||||
let infra_dupe_body = body_to_vec(infra_dupe_resp.into_body()).await?;
|
||||
let infra_dupe_folder: FolderResponse = serde_json::from_slice(&infra_dupe_body)?;
|
||||
assert_eq!(infra_dupe_folder.folder.id, infra_folder.folder.id);
|
||||
|
||||
app.cleanup().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user