forge
Explore
Log in

Don't you dare go Hollow

Board roster tests write board_participant

Browse files at this commit

2ba3280fc06bf9890a2f1a63cd5510f7eb8516e3Ahmet Kaan GümüşParent: 6fecf55
  • fix
    • board roster tests write board_participant
Show full message
🐛 fix: board roster tests write board_participant

The junction FKs to app_user, so fabricated UserId::generate() and
UPDATE board SET participants (dropped column) 23503/fail in CI.
src/db/board.rsmodified+3 -2
@@ -425,8 +425,9 @@ mod tests {
425 425
426 let locked = set_locked(&db, &board, true, &creator).await.unwrap();426 let locked = set_locked(&db, &board, true, &creator).await.unwrap();
427 assert!(locked.is_locked());427 assert!(locked.is_locked());
428-428+ let member =
429- let roster = vec![UserId::generate()];429+ crate::db::class_member::tests::fixture_user(&db, "board-member").await;
430+ let roster = vec![member];
430 let re_rostered = set_participants(&db, &board, roster).await.unwrap();431 let re_rostered = set_participants(&db, &board, roster).await.unwrap();
431 assert_eq!(re_rostered.get_participants().len(), 1);432 assert_eq!(re_rostered.get_participants().len(), 1);
432 433
tests/board_invite.rsmodified+21 -23
@@ -328,17 +328,24 @@ async fn an_over_cap_invite_is_refused_whole_and_changes_nothing() {
328 328
329 // Fill the roster to the brim directly: reaching the cap through the API329 // Fill the roster to the brim directly: reaching the cap through the API
330 // would mean registering two hundred accounts to prove an arithmetic guard.330 // would mean registering two hundred accounts to prove an arithmetic guard.
331- // The ids need not resolve — the roster is only repaired at boot, and the331+ // Participants FK to app_user, so the rows are minted here in one statement.
332- // guard under test counts entries.332+ let board_id = BoardId::from_key(&board);
333- let full: Vec<_> = (0..MAX_BOARD_PARTICIPANTS)333+ sqlx::query(
334- .map(|_| UserId::generate())334+ "WITH u AS (
335- .collect();335+ INSERT INTO app_user (id, username, created_at, role)
336- sqlx::query("UPDATE board SET participants = $1 WHERE id = $2")336+ SELECT gen_random_uuid(), 'bcap-' || $1::text || '-' || g::text, 0, 'student'
337- .bind(&full)337+ FROM generate_series(1, $2) AS g
338- .bind(BoardId::from_key(&board))338+ RETURNING id
339- .execute(&db)339+ )
340- .await340+ INSERT INTO board_participant (board, participant)
341- .unwrap();341+ SELECT $3, id FROM u",
342+ )
343+ .bind(board_id.uuid())
344+ .bind(MAX_BOARD_PARTICIPANTS as i32)
345+ .bind(board_id.uuid())
346+ .execute(&db)
347+ .await
348+ .unwrap();
342 let before = roster(&app, &teacher, &board).await;349 let before = roster(&app, &teacher, &board).await;
343 assert_eq!(before.len(), MAX_BOARD_PARTICIPANTS);350 assert_eq!(before.len(), MAX_BOARD_PARTICIPANTS);
344 351
@@ -493,18 +500,9 @@ async fn an_unknown_source_is_a_400_and_not_the_boards_404() {
493 let board = a_board(&app, &teacher).await;500 let board = a_board(&app, &teacher).await;
494 501
495 for (source, field) in [502 for (source, field) in [
496- (503+ (json!({"kind": "class", "class": ABSENT_ID}), "class"),
497- json!({"kind": "class", "class": ABSENT_ID}),504+ (json!({"kind": "course", "course": ABSENT_ID}), "course"),
498- "class",505+ (json!({"kind": "event", "event": ABSENT_ID}), "event"),
499- ),
500- (
501- json!({"kind": "course", "course": ABSENT_ID}),
502- "course",
503- ),
504- (
505- json!({"kind": "event", "event": ABSENT_ID}),
506- "event",
507- ),
508 ] {506 ] {
509 let res = invite(&app, &teacher, &board, source).await;507 let res = invite(&app, &teacher, &board, source).await;
510 assert_eq!(508 assert_eq!(
tests/e2e.rsmodified+16 -8
@@ -2591,15 +2591,24 @@ async fn a_parent_cannot_enter_the_room_or_draw() {
2591 .unwrap();2591 .unwrap();
2592 // Beside `veli`, who stays: the two differ only by role, so the refusal2592 // Beside `veli`, who stays: the two differ only by role, so the refusal
2593 // below cannot be blamed on the roster.2593 // below cannot be blamed on the roster.
2594- sqlx::query("UPDATE board SET participants = $1 WHERE id = $2")2594+ let board_uuid = Uuid::parse_str(board).unwrap();
2595- .bind(vec![2595+ sqlx::query("DELETE FROM board_participant WHERE board = $1")
2596- Uuid::parse_str(&room.veli_id).unwrap(),2596+ .bind(board_uuid)
2597- Uuid::parse_str(me["id"].as_str().unwrap()).unwrap(),
2598- ])
2599- .bind(Uuid::parse_str(board).unwrap())
2600 .execute(&room.db)2597 .execute(&room.db)
2601 .await2598 .await
2602 .unwrap();2599 .unwrap();
2600+ sqlx::query(
2601+ "INSERT INTO board_participant (board, participant)
2602+ SELECT $1, t.x FROM unnest($2::uuid[]) AS t(x)",
2603+ )
2604+ .bind(board_uuid)
2605+ .bind(vec![
2606+ Uuid::parse_str(&room.veli_id).unwrap(),
2607+ Uuid::parse_str(me["id"].as_str().unwrap()).unwrap(),
2608+ ])
2609+ .execute(&room.db)
2610+ .await
2611+ .unwrap();
2603 2612
2604 assert_eq!(2613 assert_eq!(
2605 board_open(base, board, Some(&cookie)).await.err(),2614 board_open(base, board, Some(&cookie)).await.err(),
@@ -2642,8 +2651,7 @@ async fn a_removed_participant_can_no_longer_draw() {
2642 2651
2643 // The silent removal first: write the roster straight into the database,2652 // The silent removal first: write the roster straight into the database,
2644 // so no frame is published and only the per-stroke gate can catch it.2653 // so no frame is published and only the per-stroke gate can catch it.
2645- sqlx::query("UPDATE board SET participants = $1 WHERE id = $2")2654+ sqlx::query("DELETE FROM board_participant WHERE board = $1")
2646- .bind(Vec::<Uuid>::new())
2647 .bind(Uuid::parse_str(board).unwrap())2655 .bind(Uuid::parse_str(board).unwrap())
2648 .execute(&room.db)2656 .execute(&room.db)
2649 .await2657 .await
tests/integration.rsmodified+12 -3
@@ -25220,12 +25220,21 @@ async fn a_parent_gets_no_whiteboard_at_all() {
25220 // 3. The stale row: a parent already on a roster, written before this rule.25220 // 3. The stale row: a parent already on a roster, written before this rule.
25221 // Every id-scoped route must still answer exactly like a board that was25221 // Every id-scoped route must still answer exactly like a board that was
25222 // never minted — a 403 anywhere here leaks the board's existence.25222 // never minted — a 403 anywhere here leaks the board's existence.
25223- sqlx::query("UPDATE board SET participants = $2 WHERE id = $1")25223+ let board_uuid = Uuid::parse_str(&board).expect("board id");
25224- .bind(Uuid::parse_str(&board).expect("board id"))25224+ sqlx::query("DELETE FROM board_participant WHERE board = $1")
25225- .bind(vec![Uuid::parse_str(&anne_id).expect("user id")])25225+ .bind(board_uuid)
25226 .execute(&db)25226 .execute(&db)
25227 .await25227 .await
25228 .unwrap();25228 .unwrap();
25229+ sqlx::query(
25230+ "INSERT INTO board_participant (board, participant)
25231+ SELECT $1, t.x FROM unnest($2::uuid[]) AS t(x)",
25232+ )
25233+ .bind(board_uuid)
25234+ .bind(vec![Uuid::parse_str(&anne_id).expect("user id")])
25235+ .execute(&db)
25236+ .await
25237+ .unwrap();
25229 let ghost = board_routes("nosuchboard");25238 let ghost = board_routes("nosuchboard");
25230 for (n, (method, uri, body)) in board_routes(&board).into_iter().enumerate() {25239 for (n, (method, uri, body)) in board_routes(&board).into_iter().enumerate() {
25231 let res = send(&app, method, &uri, Some(&anne), body).await;25240 let res = send(&app, method, &uri, Some(&anne), body).await;