Files
kvitt/server/crates/kvitt-server/tests/sync_api/e2e.rs
T
jacobh2 8cb42f85a9 Server overhaul: one test harness in tests/common for every test binary
core_api/common.rs becomes tests/common/mod.rs and sync_api/m4.rs tests/common/sync_fixtures.rs; each binary
includes them through #[path] (the binaries of SPEC §14.7 stay as they are). TempDir's Default moves into the
harness instead of three copies; the skeleton helpers take ids, tokens and TempDir from it. Milestone wording in
test docs and the server README replaced by what the code does; README seams and test layout updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TQd3pEP9UeN2uifbHknQ7B
2026-10-18 22:43:54 +02:00

50 lines
1.8 KiB
Rust

//! End to end: device A creates through E-32, device B pulls through E-31 and sees the row and its audit entry
//! (AC-12.3); exactly one push is queued on the real queue, for the other user's devices.
use std::sync::Arc;
use kvitt_server::push::{PushHub, PushType};
use crate::common::*;
use crate::sync_fixtures::*;
#[tokio::test]
async fn create_on_device_a_pull_on_device_b_row_audit_and_one_push() {
let mut app = app().await;
let hub = Arc::new(PushHub::new());
with_push(&mut app, hub.clone());
let id = new_id();
let cursor_b = pull(&app, &member_token(), 0, Some(1000)).await.json["next_since"]
.as_i64()
.unwrap();
let result = push_one(
&app,
&admin_token(),
exp(expense(&id, "2026-10-17T11:59:00.000Z")),
)
.await;
let created = accepted(&result);
let page = pull(&app, &member_token(), cursor_b, None).await.json;
assert_eq!(page["expenses"].as_array().unwrap().len(), 1);
assert_eq!(page["expenses"][0], created);
let audit = page["audit_entries"].as_array().unwrap();
assert_eq!(audit.len(), 1);
assert_eq!(audit[0]["entity_id"], id);
assert_eq!(audit[0]["action"], "create");
assert_eq!(audit[0]["source"], "app");
assert_eq!(audit[0]["actor_user_id"], ADMIN_ID);
assert_eq!(audit[0]["client_at"], "2026-10-17T11:59:00.000Z");
assert_eq!(audit[0]["changes"].as_array().unwrap().len(), 9);
assert!(audit[0]["server_version"].as_i64() > created["server_version"].as_i64());
assert_eq!(page["next_since"], audit[0]["server_version"]);
assert_eq!(hub.len(), 1);
let message = hub.pop().unwrap();
assert_eq!(message.push_type, PushType::ExpenseCreated);
assert_eq!(message.entity_id.unwrap().to_string(), id);
assert_eq!(message.actor_user_id.to_string(), ADMIN_ID);
assert_eq!(message.count, 1);
}