pinakes-server: expand test coverage for server features
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ia09d2d3ad7f6613e21d20321e0877bc16a6a6964
This commit is contained in:
parent
4a2136439f
commit
7d8ec5ffc1
8 changed files with 853 additions and 10 deletions
125
crates/pinakes-server/tests/notes.rs
Normal file
125
crates/pinakes-server/tests/notes.rs
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
mod common;
|
||||
|
||||
use axum::http::StatusCode;
|
||||
use common::{
|
||||
delete_authed,
|
||||
get,
|
||||
get_authed,
|
||||
patch_json_authed,
|
||||
post_json_authed,
|
||||
put_json_authed,
|
||||
response_body,
|
||||
setup_app,
|
||||
setup_app_with_auth,
|
||||
};
|
||||
use tower::ServiceExt;
|
||||
|
||||
#[tokio::test]
|
||||
async fn backlinks_for_nonexistent_media() {
|
||||
let app = setup_app().await;
|
||||
let fake_id = uuid::Uuid::now_v7();
|
||||
let resp = app
|
||||
.oneshot(get(&format!("/api/v1/media/{fake_id}/backlinks")))
|
||||
.await
|
||||
.unwrap();
|
||||
// Should return OK with empty list, or NOT_FOUND
|
||||
assert!(
|
||||
resp.status() == StatusCode::OK || resp.status() == StatusCode::NOT_FOUND
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn outgoing_links_for_nonexistent_media() {
|
||||
let app = setup_app().await;
|
||||
let fake_id = uuid::Uuid::now_v7();
|
||||
let resp = app
|
||||
.oneshot(get(&format!("/api/v1/media/{fake_id}/outgoing-links")))
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(
|
||||
resp.status() == StatusCode::OK || resp.status() == StatusCode::NOT_FOUND
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn notes_graph_empty() {
|
||||
let (app, _, _, viewer) = setup_app_with_auth().await;
|
||||
let resp = app
|
||||
.clone()
|
||||
.oneshot(get_authed("/api/v1/notes/graph", &viewer))
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
let body = response_body(resp).await;
|
||||
assert!(body.is_object() || body.is_array());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn unresolved_count_zero() {
|
||||
let app = setup_app().await;
|
||||
let resp = app
|
||||
.oneshot(get("/api/v1/notes/unresolved-count"))
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn reindex_links_requires_editor() {
|
||||
let (app, _, _, viewer) = setup_app_with_auth().await;
|
||||
let fake_id = uuid::Uuid::now_v7();
|
||||
let resp = app
|
||||
.clone()
|
||||
.oneshot(post_json_authed(
|
||||
&format!("/api/v1/media/{fake_id}/reindex-links"),
|
||||
"{}",
|
||||
&viewer,
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::FORBIDDEN);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn update_media_requires_editor() {
|
||||
let (app, _, _, viewer) = setup_app_with_auth().await;
|
||||
let fake_id = uuid::Uuid::now_v7();
|
||||
let resp = app
|
||||
.clone()
|
||||
.oneshot(patch_json_authed(
|
||||
&format!("/api/v1/media/{fake_id}"),
|
||||
r#"{"title":"new title"}"#,
|
||||
&viewer,
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::FORBIDDEN);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn delete_media_requires_editor() {
|
||||
let (app, _, _, viewer) = setup_app_with_auth().await;
|
||||
let fake_id = uuid::Uuid::now_v7();
|
||||
let resp = app
|
||||
.clone()
|
||||
.oneshot(delete_authed(&format!("/api/v1/media/{fake_id}"), &viewer))
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::FORBIDDEN);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn update_sync_device_requires_editor() {
|
||||
let (app, _, _, viewer) = setup_app_with_auth().await;
|
||||
let fake_id = uuid::Uuid::now_v7();
|
||||
let resp = app
|
||||
.clone()
|
||||
.oneshot(put_json_authed(
|
||||
&format!("/api/v1/sync/devices/{fake_id}"),
|
||||
r#"{"name":"renamed"}"#,
|
||||
&viewer,
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::FORBIDDEN);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue