Warn before watch history is left behind, and re-apply it later (#2)
CI / test (push) Successful in 1m16s

This commit is contained in:
IxianPixel committed 2026-11-06 17:34:22 +00:00
1 parent 2bd4489b1a
commit 8cfa0f05eb
15 files changed
+611 -73

No files matched your search

+89
View File
@@ -726,6 +726,95 @@ async fn refuses_a_season_folder_holding_other_seasons() {
);
}
#[tokio::test]
async fn warns_about_missing_users_and_reapplies_their_watch_state_later() {
let (cloud, home) = pair(seed_movie).await;
// Cloud has a second user, Bob, whom home doesn't know yet.
cloud.fake.add_user("u2", "Bob");
let movie = cloud.fake.find("Movie", "Alien").unwrap();
cloud.fake.set_user_data(&movie, json!({"Played": true}));
cloud
.fake
.set_user_data_for("u2", &movie, json!({"PlaybackPositionTicks": 777}));
// Before moving, the UI can see whose watch history won't carry over,
// whichever side it asks from.
let check = get(
&cloud.url,
&format!("/api/moves/check?from=local&item_id={movie}"),
)
.await;
assert_eq!(check["watchers"], json!(["Alice", "Bob"]));
assert_eq!(check["missing_users"], json!(["Bob"]));
let check = get(
&home.url,
&format!("/api/moves/check?from=peer&item_id={movie}"),
)
.await;
assert_eq!(check["missing_users"], json!(["Bob"]));
// A dry run says so too.
let dry: Value = post(
&cloud.url,
"/api/moves",
json!({"from": "local", "item_id": movie, "name": "Alien", "dry_run": true}),
)
.await
.json()
.await
.unwrap();
let dry = wait_job(&cloud.url, dry["id"].as_str().unwrap()).await;
assert_eq!(dry["status"]["kind"], "Planned");
assert_eq!(dry["missing_users"], json!(["Bob"]));
assert!(
dry["log"]
.as_array()
.unwrap()
.iter()
.any(|l| l.as_str().unwrap().contains("won't carry over for Bob")),
"{dry:#}"
);
// The move goes ahead; Alice's watch state follows, Bob's is kept.
let job = move_item(&cloud.url, "local", &movie, "Alien").await;
assert_eq!(job["missing_users"], json!(["Bob"]));
let new_id = home.fake.find("Movie", "Alien").unwrap();
assert_eq!(home.fake.get_user_data(&new_id).unwrap()["Played"], true);
let id = job["id"].as_str().unwrap();
// Re-applying before Bob has an account explains what to do.
let r = post(&cloud.url, &format!("/api/jobs/{id}/reapply"), json!({})).await;
assert!(!r.status().is_success());
let text = r.text().await.unwrap();
assert!(
text.contains("no user called Bob on home yet; create them in Jellyfin on home first"),
"{text}"
);
assert!(!text.contains("HTTP 502"), "{text}");
// Alice carries on watching on home in the meantime.
home.fake
.set_user_data(&new_id, json!({"Played": true, "PlayCount": 5}));
// Once home has a "bob" (names match ignoring case), re-apply from the
// cloud UI: the job runs on home, so the request is passed on.
home.fake.add_user("u9", "bob");
let r = post(&cloud.url, &format!("/api/jobs/{id}/reapply"), json!({})).await;
assert!(r.status().is_success(), "{}", r.text().await.unwrap());
let job: Value = r.json().await.unwrap();
assert_eq!(job["missing_users"], json!([]));
assert_eq!(
home.fake.get_user_data_for("u9", &new_id).unwrap()["PlaybackPositionTicks"],
777
);
// Alice's newer watch state wasn't overwritten by the old snapshot.
assert_eq!(home.fake.get_user_data(&new_id).unwrap()["PlayCount"], 5);
// Nothing left to re-apply.
let r = post(&home.url, &format!("/api/jobs/{id}/reapply"), json!({})).await;
assert!(r.text().await.unwrap().contains("no skipped watch history"));
}
#[tokio::test]
async fn peer_api_rejects_bad_token_and_ui_requires_csrf_header() {
let (cloud, _home) = pair(|_| {}).await;