pinakes-server: add more integration tests
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I7c6c8eaad569404c7a13cfa8114d84516a6a6964
This commit is contained in:
parent
fd11b2b7c4
commit
30041c40c0
6 changed files with 517 additions and 1 deletions
143
crates/pinakes-server/tests/enrichment.rs
Normal file
143
crates/pinakes-server/tests/enrichment.rs
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
mod common;
|
||||
|
||||
use axum::http::StatusCode;
|
||||
use common::{
|
||||
get,
|
||||
get_authed,
|
||||
post_json_authed,
|
||||
setup_app,
|
||||
setup_app_with_auth,
|
||||
};
|
||||
use tower::ServiceExt;
|
||||
|
||||
// GET /api/v1/media/{id}/metadata/external (viewer)
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_external_metadata_requires_auth() {
|
||||
let (app, ..) = setup_app_with_auth().await;
|
||||
let response = app
|
||||
.oneshot(get(
|
||||
"/api/v1/media/00000000-0000-0000-0000-000000000000/external-metadata",
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::UNAUTHORIZED);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_external_metadata_viewer_ok() {
|
||||
let (app, _, _, viewer_token) = setup_app_with_auth().await;
|
||||
let response = app
|
||||
.oneshot(get_authed(
|
||||
"/api/v1/media/00000000-0000-0000-0000-000000000000/external-metadata",
|
||||
&viewer_token,
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
// Media does not exist; 200 with empty array or 404 are both valid
|
||||
assert!(
|
||||
response.status() == StatusCode::OK
|
||||
|| response.status() == StatusCode::NOT_FOUND
|
||||
);
|
||||
}
|
||||
|
||||
// POST /api/v1/media/{id}/enrich (editor)
|
||||
|
||||
#[tokio::test]
|
||||
async fn trigger_enrichment_requires_editor() {
|
||||
let (app, _, _, viewer_token) = setup_app_with_auth().await;
|
||||
let response = app
|
||||
.oneshot(post_json_authed(
|
||||
"/api/v1/media/00000000-0000-0000-0000-000000000000/enrich",
|
||||
"{}",
|
||||
&viewer_token,
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::FORBIDDEN);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn trigger_enrichment_editor_accepted() {
|
||||
let (app, _, editor_token, _) = setup_app_with_auth().await;
|
||||
let response = app
|
||||
.oneshot(post_json_authed(
|
||||
"/api/v1/media/00000000-0000-0000-0000-000000000000/enrich",
|
||||
"{}",
|
||||
&editor_token,
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
// Route is accessible to editors; media not found returns 404, job queued
|
||||
// returns 200
|
||||
assert!(
|
||||
response.status() == StatusCode::OK
|
||||
|| response.status() == StatusCode::NOT_FOUND
|
||||
);
|
||||
}
|
||||
|
||||
// POST /api/v1/jobs/enrich (editor, batch)
|
||||
|
||||
#[tokio::test]
|
||||
async fn batch_enrich_requires_editor() {
|
||||
let (app, _, _, viewer_token) = setup_app_with_auth().await;
|
||||
let response = app
|
||||
.oneshot(post_json_authed(
|
||||
"/api/v1/jobs/enrich",
|
||||
r#"{"media_ids":["00000000-0000-0000-0000-000000000000"]}"#,
|
||||
&viewer_token,
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::FORBIDDEN);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn batch_enrich_empty_ids_rejected() {
|
||||
let (app, _, editor_token, _) = setup_app_with_auth().await;
|
||||
let response = app
|
||||
.oneshot(post_json_authed(
|
||||
"/api/v1/jobs/enrich",
|
||||
r#"{"media_ids":[]}"#,
|
||||
&editor_token,
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
// Validation requires 1-1000 ids
|
||||
assert!(
|
||||
response.status() == StatusCode::BAD_REQUEST
|
||||
|| response.status() == StatusCode::UNPROCESSABLE_ENTITY
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn batch_enrich_editor_accepted() {
|
||||
let (app, _, editor_token, _) = setup_app_with_auth().await;
|
||||
let response = app
|
||||
.oneshot(post_json_authed(
|
||||
"/api/v1/jobs/enrich",
|
||||
r#"{"media_ids":["00000000-0000-0000-0000-000000000000"]}"#,
|
||||
&editor_token,
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
// Job is queued and a job_id is returned
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
}
|
||||
|
||||
// No-auth coverage (exercises setup_app and get)
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_external_metadata_auth_disabled() {
|
||||
let app = setup_app().await;
|
||||
let response = app
|
||||
.oneshot(get(
|
||||
"/api/v1/media/00000000-0000-0000-0000-000000000000/external-metadata",
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(
|
||||
response.status() == StatusCode::OK
|
||||
|| response.status() == StatusCode::NOT_FOUND
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue