diff --git a/src/db/board.rs b/src/db/board.rs index 964faca..1102ef3 100644 --- a/src/db/board.rs +++ b/src/db/board.rs @@ -425,8 +425,9 @@ mod tests { let locked = set_locked(&db, &board, true, &creator).await.unwrap(); assert!(locked.is_locked()); - - let roster = vec![UserId::generate()]; + let member = + crate::db::class_member::tests::fixture_user(&db, "board-member").await; + let roster = vec![member]; let re_rostered = set_participants(&db, &board, roster).await.unwrap(); assert_eq!(re_rostered.get_participants().len(), 1); diff --git a/tests/board_invite.rs b/tests/board_invite.rs index ecc41a7..cf3b2d3 100644 --- a/tests/board_invite.rs +++ b/tests/board_invite.rs @@ -328,17 +328,24 @@ async fn an_over_cap_invite_is_refused_whole_and_changes_nothing() { // Fill the roster to the brim directly: reaching the cap through the API // would mean registering two hundred accounts to prove an arithmetic guard. - // The ids need not resolve — the roster is only repaired at boot, and the - // guard under test counts entries. - let full: Vec<_> = (0..MAX_BOARD_PARTICIPANTS) - .map(|_| UserId::generate()) - .collect(); - sqlx::query("UPDATE board SET participants = $1 WHERE id = $2") - .bind(&full) - .bind(BoardId::from_key(&board)) - .execute(&db) - .await - .unwrap(); + // Participants FK to app_user, so the rows are minted here in one statement. + let board_id = BoardId::from_key(&board); + sqlx::query( + "WITH u AS ( + INSERT INTO app_user (id, username, created_at, role) + SELECT gen_random_uuid(), 'bcap-' || $1::text || '-' || g::text, 0, 'student' + FROM generate_series(1, $2) AS g + RETURNING id + ) + INSERT INTO board_participant (board, participant) + SELECT $3, id FROM u", + ) + .bind(board_id.uuid()) + .bind(MAX_BOARD_PARTICIPANTS as i32) + .bind(board_id.uuid()) + .execute(&db) + .await + .unwrap(); let before = roster(&app, &teacher, &board).await; assert_eq!(before.len(), MAX_BOARD_PARTICIPANTS); @@ -493,18 +500,9 @@ async fn an_unknown_source_is_a_400_and_not_the_boards_404() { let board = a_board(&app, &teacher).await; for (source, field) in [ - ( - json!({"kind": "class", "class": ABSENT_ID}), - "class", - ), - ( - json!({"kind": "course", "course": ABSENT_ID}), - "course", - ), - ( - json!({"kind": "event", "event": ABSENT_ID}), - "event", - ), + (json!({"kind": "class", "class": ABSENT_ID}), "class"), + (json!({"kind": "course", "course": ABSENT_ID}), "course"), + (json!({"kind": "event", "event": ABSENT_ID}), "event"), ] { let res = invite(&app, &teacher, &board, source).await; assert_eq!( diff --git a/tests/e2e.rs b/tests/e2e.rs index 24c890c..4c6d88f 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -2591,15 +2591,24 @@ async fn a_parent_cannot_enter_the_room_or_draw() { .unwrap(); // Beside `veli`, who stays: the two differ only by role, so the refusal // below cannot be blamed on the roster. - sqlx::query("UPDATE board SET participants = $1 WHERE id = $2") - .bind(vec![ - Uuid::parse_str(&room.veli_id).unwrap(), - Uuid::parse_str(me["id"].as_str().unwrap()).unwrap(), - ]) - .bind(Uuid::parse_str(board).unwrap()) + let board_uuid = Uuid::parse_str(board).unwrap(); + sqlx::query("DELETE FROM board_participant WHERE board = $1") + .bind(board_uuid) .execute(&room.db) .await .unwrap(); + sqlx::query( + "INSERT INTO board_participant (board, participant) + SELECT $1, t.x FROM unnest($2::uuid[]) AS t(x)", + ) + .bind(board_uuid) + .bind(vec![ + Uuid::parse_str(&room.veli_id).unwrap(), + Uuid::parse_str(me["id"].as_str().unwrap()).unwrap(), + ]) + .execute(&room.db) + .await + .unwrap(); assert_eq!( board_open(base, board, Some(&cookie)).await.err(), @@ -2642,8 +2651,7 @@ async fn a_removed_participant_can_no_longer_draw() { // The silent removal first: write the roster straight into the database, // so no frame is published and only the per-stroke gate can catch it. - sqlx::query("UPDATE board SET participants = $1 WHERE id = $2") - .bind(Vec::::new()) + sqlx::query("DELETE FROM board_participant WHERE board = $1") .bind(Uuid::parse_str(board).unwrap()) .execute(&room.db) .await diff --git a/tests/integration.rs b/tests/integration.rs index 51eadf5..20e02aa 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -25220,12 +25220,21 @@ async fn a_parent_gets_no_whiteboard_at_all() { // 3. The stale row: a parent already on a roster, written before this rule. // Every id-scoped route must still answer exactly like a board that was // never minted — a 403 anywhere here leaks the board's existence. - sqlx::query("UPDATE board SET participants = $2 WHERE id = $1") - .bind(Uuid::parse_str(&board).expect("board id")) - .bind(vec![Uuid::parse_str(&anne_id).expect("user id")]) + let board_uuid = Uuid::parse_str(&board).expect("board id"); + sqlx::query("DELETE FROM board_participant WHERE board = $1") + .bind(board_uuid) .execute(&db) .await .unwrap(); + sqlx::query( + "INSERT INTO board_participant (board, participant) + SELECT $1, t.x FROM unnest($2::uuid[]) AS t(x)", + ) + .bind(board_uuid) + .bind(vec![Uuid::parse_str(&anne_id).expect("user id")]) + .execute(&db) + .await + .unwrap(); let ghost = board_routes("nosuchboard"); for (n, (method, uri, body)) in board_routes(&board).into_iter().enumerate() { let res = send(&app, method, &uri, Some(&anne), body).await;