forge
Explore
Log in

Don't you dare go Hollow

Page tests share their fixtures and merge into tables

Browse files at this commit

1a6f67b523cf4c3643969de78172fbbd18538160Ahmet Kaan GümüşParent: f6cbcec
  • test
    • page tests share their fixtures and merge into tables
Show full message
✅ test: page tests share their fixtures and merge into tables

Merge fixture-sharing scenarios into one table-like test each, keeping
every assertion and labelling each with its case.

- pulls_merge.rs: 22 -> 19 (four refused-merge tests become one)
- push.rs: 8 -> 5 (VAPID, refused subscriptions, public routes)
- pulls_list.rs: 6 -> 4 (list, issues exclusion and new-PR button)
- pull_branch.rs: 6 -> 5 (protected and default branch refusals)

Total in scope: 42 -> 33. Verified with nextest: 34 passed in the
pages module filter.
crates/forge-web/src/pages/pull_branch.rsmodified+36 -38
@@ -662,9 +662,13 @@ mod tests {
662 assert!(events.iter().any(|e| e.kind == "head_ref_restored"));662 assert!(events.iter().any(|e| e.kind == "head_ref_restored"));
663 }663 }
664 664
665+ /// Deleting a branch is refused for a protected branch and for the default branch. The
666+ /// scenarios share one fixture; each refusal leaves its branch in place.
665 #[tokio::test]667 #[tokio::test]
666- async fn protected_branch_is_refused() {668+ async fn protected_and_default_branches_are_refused() {
667 let fx = fixture().await;669 let fx = fixture().await;
670+
671+ // A merged feature branch that is protected.
668 let number = fx.open_feature("feature", "f.txt", "feature").await;672 let number = fx.open_feature("feature", "f.txt", "feature").await;
669 fx.merge(number).await;673 fx.merge(number).await;
670 fx.state674 fx.state
@@ -672,12 +676,41 @@ mod tests {
672 .upsert_branch_rule(&fx.repo.id, "feature", RuleFlags::basic(false, false))676 .upsert_branch_rule(&fx.repo.id, "feature", RuleFlags::basic(false, false))
673 .await677 .await
674 .expect("rule");678 .expect("rule");
675-
676 let reply = fx679 let reply = fx
677 .branch_post(number, "delete_branch", &fx.tahinli_cookie)680 .branch_post(number, "delete_branch", &fx.tahinli_cookie)
678 .await;681 .await;
679 assert_refused(&reply, number, "protected");682 assert_refused(&reply, number, "protected");
680- assert!(fx.branch_exists("feature"));683+ assert!(fx.branch_exists("feature"), "case protected");
684+
685+ // A finished pull request whose head is the default branch itself.
686+ let main = fx.branch_tip("main");
687+ let pr = fx
688+ .state
689+ .store
690+ .create_pull(
691+ &fx.repo.id,
692+ &fx.tahinli.id,
693+ "Main",
694+ "",
695+ "dev",
696+ &fx.repo.id,
697+ "main",
698+ &main,
699+ &main,
700+ )
701+ .await
702+ .expect("create pull");
703+ fx.state
704+ .store
705+ .mark_merged(&pr.issue.id, &fx.tahinli.id, &main)
706+ .await
707+ .expect("mark merged");
708+ let number = pr.issue.number;
709+ let reply = fx
710+ .branch_post(number, "delete_branch", &fx.tahinli_cookie)
711+ .await;
712+ assert_refused(&reply, number, "default_branch");
713+ assert!(fx.branch_exists("main"), "case default branch");
681 }714 }
682 715
683 #[tokio::test]716 #[tokio::test]
@@ -724,41 +757,6 @@ mod tests {
724 assert!(!page.body.contains("Delete branch"), "{}", page.body);757 assert!(!page.body.contains("Delete branch"), "{}", page.body);
725 }758 }
726 759
727- #[tokio::test]
728- async fn default_branch_is_refused() {
729- let fx = fixture().await;
730- // A finished pull request whose head is the default branch itself.
731- let main = fx.branch_tip("main");
732- let pr = fx
733- .state
734- .store
735- .create_pull(
736- &fx.repo.id,
737- &fx.tahinli.id,
738- "Main",
739- "",
740- "dev",
741- &fx.repo.id,
742- "main",
743- &main,
744- &main,
745- )
746- .await
747- .expect("create pull");
748- fx.state
749- .store
750- .mark_merged(&pr.issue.id, &fx.tahinli.id, &main)
751- .await
752- .expect("mark merged");
753-
754- let number = pr.issue.number;
755- let reply = fx
756- .branch_post(number, "delete_branch", &fx.tahinli_cookie)
757- .await;
758- assert_refused(&reply, number, "default_branch");
759- assert!(fx.branch_exists("main"));
760- }
761-
762 #[test]760 #[test]
763 fn unknown_branch_error_codes_have_no_message() {761 fn unknown_branch_error_codes_have_no_message() {
764 assert!(branch_error_text(Lang::En, "protected").is_some());762 assert!(branch_error_text(Lang::En, "protected").is_some());
crates/forge-web/src/pages/pulls_list.rsmodified+19 -52
@@ -427,6 +427,25 @@ mod tests {
427 );427 );
428 assert!(html.contains("issue-badge-open\">Open<"));428 assert!(html.contains("issue-badge-open\">Open<"));
429 assert!(html.contains(&format!("href=\"/{OWNER}/{REPO}/compare\"")));429 assert!(html.contains(&format!("href=\"/{OWNER}/{REPO}/compare\"")));
430+ assert!(html.contains("New pull request"), "case signed in");
431+ let anon = send(&fx.router, "GET", &base(), false, None, &[])
432+ .await
433+ .text();
434+ assert!(!anon.contains("New pull request"), "case anonymous");
435+
436+ // The issues list keeps excluding pull requests, using the same data.
437+ let issues = send(
438+ &fx.router,
439+ "GET",
440+ &format!("/{OWNER}/{REPO}/issues?state=all"),
441+ true,
442+ None,
443+ &[],
444+ )
445+ .await
446+ .text();
447+ assert!(issues.contains("plain issue title"));
448+ assert!(!issues.contains("pull request title"), "{issues}");
430 }449 }
431 450
432 #[tokio::test]451 #[tokio::test]
@@ -525,56 +544,4 @@ mod tests {
525 let owner = send(&fx.router, "GET", &base(), true, None, &[]).await;544 let owner = send(&fx.router, "GET", &base(), true, None, &[]).await;
526 assert_eq!(owner.status, 200);545 assert_eq!(owner.status, 200);
527 }546 }
528-
529- #[tokio::test]
530- async fn new_pull_request_button_only_for_signed_in_viewers() {
531- let fx = fixture(Visibility::Public).await;
532- let button = format!("href=\"/{OWNER}/{REPO}/compare\"");
533- let signed_in = send(&fx.router, "GET", &base(), true, None, &[])
534- .await
535- .text();
536- assert!(signed_in.contains("New pull request"));
537- assert!(signed_in.contains(&button));
538- let anon = send(&fx.router, "GET", &base(), false, None, &[])
539- .await
540- .text();
541- assert!(!anon.contains("New pull request"));
542- }
543-
544- #[tokio::test]
545- async fn issues_list_still_excludes_pulls() {
546- let fx = fixture(Visibility::Public).await;
547- let repo_id = fx.repo.id.clone();
548- fx.store
549- .create_issue(&repo_id, &fx.owner.id, "plain issue title", "")
550- .await
551- .unwrap();
552- fx.store
553- .create_pull(
554- &repo_id,
555- &fx.owner.id,
556- "pull request title",
557- "",
558- "main",
559- &repo_id,
560- "feature",
561- HEAD_OID,
562- BASE_OID,
563- )
564- .await
565- .unwrap();
566-
567- let html = send(
568- &fx.router,
569- "GET",
570- &format!("/{OWNER}/{REPO}/issues?state=all"),
571- true,
572- None,
573- &[],
574- )
575- .await
576- .text();
577- assert!(html.contains("plain issue title"));
578- assert!(!html.contains("pull request title"), "{html}");
579- }
580 }547 }
crates/forge-web/src/pages/pulls_merge.rsmodified+27 -23
@@ -931,49 +931,53 @@ mod tests {
931 assert!(fx.pull(number).await.merged_at.is_some());931 assert!(fx.pull(number).await.merged_at.is_some());
932 }932 }
933 933
934+ /// Refusals that must leave the base alone. The scenarios share one fixture: each uses its own
935+ /// branch and file, and the base only moves forward between them. The scenario that moves
936+ /// main onto its head runs last.
934 #[tokio::test]937 #[tokio::test]
935- async fn fast_forward_is_refused_when_base_has_diverged() {938+ async fn refused_merges_leave_the_base_unchanged() {
936 let fx = fixture().await;939 let fx = fixture().await;
937- let number = fx940+
938- .open_feature("feature", "feature.txt", "f1", &fx.bob)941+ // Fast-forward is impossible once the base has diverged.
939- .await;942+ let number = fx.open_feature("ff", "ff.txt", "f1", &fx.bob).await;
940 fx.advance_main("other.txt", "other");943 fx.advance_main("other.txt", "other");
941 let before = fx.main_tip();944 let before = fx.main_tip();
942-
943 let reply = fx.merge(number, "ff").await;945 let reply = fx.merge(number, "ff").await;
944 assert_refused(&reply, number, ERR_FF_IMPOSSIBLE);946 assert_refused(&reply, number, ERR_FF_IMPOSSIBLE);
945- assert_eq!(fx.main_tip(), before);947+ assert_eq!(fx.main_tip(), before, "case ff: base moved");
946- assert!(fx.pull(number).await.merged_at.is_none());948+ assert!(fx.pull(number).await.merged_at.is_none(), "case ff");
947- }
948 949
949- #[tokio::test]950+ // The same file changed on both sides conflicts.
950- async fn conflicting_pull_request_is_refused_and_base_unchanged() {
951- let fx = fixture().await;
952 let number = fx951 let number = fx
953- .open_feature("feature", "file.txt", "feature", &fx.bob)952+ .open_feature("conflict", "file.txt", "feature", &fx.bob)
954 .await;953 .await;
955 fx.advance_main("file.txt", "main");954 fx.advance_main("file.txt", "main");
956 let before = fx.main_tip();955 let before = fx.main_tip();
957-
958 let reply = fx.merge(number, "merge").await;956 let reply = fx.merge(number, "merge").await;
959 assert_refused(&reply, number, ERR_CONFLICT);957 assert_refused(&reply, number, ERR_CONFLICT);
960- assert_eq!(fx.main_tip(), before);958+ assert_eq!(fx.main_tip(), before, "case conflict: base moved");
961- assert!(fx.pull(number).await.merged_at.is_none());959+ assert!(fx.pull(number).await.merged_at.is_none(), "case conflict");
962- }
963 960
964- #[tokio::test]961+ // A rebase that replays onto a conflicting base is refused too.
965- async fn head_already_in_base_is_refused_as_up_to_date() {
966- let fx = fixture().await;
967 let number = fx962 let number = fx
968- .open_feature("feature", "feature.txt", "f1", &fx.bob)963+ .open_feature("rebase", "same.txt", "feature side", &fx.bob)
969 .await;964 .await;
970- // Move main onto the feature head, so the head is already contained in the base.965+ fx.advance_main("same.txt", "main side");
971- fx.push("feature:main");
972 let before = fx.main_tip();966 let before = fx.main_tip();
967+ let reply = fx.merge(number, "rebase").await;
968+ assert_refused(&reply, number, ERR_CONFLICT);
969+ assert_eq!(fx.main_tip(), before, "case rebase: base moved");
970+ assert!(fx.pull(number).await.merged_at.is_none(), "case rebase");
973 971
972+ // Move main onto the head, so the head is already contained in the base.
973+ let number = fx
974+ .open_feature("contained", "contained.txt", "f1", &fx.bob)
975+ .await;
976+ fx.push("contained:main");
977+ let before = fx.main_tip();
974 let reply = fx.merge(number, "merge").await;978 let reply = fx.merge(number, "merge").await;
975 assert_refused(&reply, number, ERR_UP_TO_DATE);979 assert_refused(&reply, number, ERR_UP_TO_DATE);
976- assert_eq!(fx.main_tip(), before);980+ assert_eq!(fx.main_tip(), before, "case up to date: base moved");
977 }981 }
978 982
979 #[tokio::test]983 #[tokio::test]
crates/forge-web/src/pages/push.rsmodified+14 -28
@@ -392,13 +392,10 @@ mod tests {
392 let key: serde_json::Value = serde_json::from_str(&first).expect("json");392 let key: serde_json::Value = serde_json::from_str(&first).expect("json");
393 let public = key["public_key"].as_str().expect("public key");393 let public = key["public_key"].as_str().expect("public key");
394 assert_eq!(crypto::decode_b64(public).expect("b64").len(), 65);394 assert_eq!(crypto::decode_b64(public).expect("b64").len(), 65);
395- }
396 395
397- #[tokio::test]396+ // Without a session the key is not served.
398- async fn the_vapid_key_needs_a_session() {
399- let fx = fixture().await;
400 let (status, _) = send(&fx.router, "GET", "/push/vapid-key", None, None).await;397 let (status, _) = send(&fx.router, "GET", "/push/vapid-key", None, None).await;
401- assert_ne!(status, 200);398+ assert_ne!(status, 200, "case anonymous");
402 }399 }
403 400
404 #[tokio::test]401 #[tokio::test]
@@ -445,10 +442,14 @@ mod tests {
445 );442 );
446 }443 }
447 444
445+ /// Every refused subscription (bad token or bad fields) stores nothing. The scenarios share one
446+ /// fixture and each one is refused, so the store stays empty throughout.
448 #[tokio::test]447 #[tokio::test]
449- async fn a_subscription_needs_the_csrf_token() {448+ async fn refused_subscriptions_store_nothing() {
450 let fx = fixture().await;449 let fx = fixture().await;
451 let (p256dh, auth) = browser_keys();450 let (p256dh, auth) = browser_keys();
451+
452+ // A wrong CSRF token is forbidden.
452 let form = subscribe_form("wrong", "https://push.example.test/x", &p256dh, &auth);453 let form = subscribe_form("wrong", "https://push.example.test/x", &p256dh, &auth);
453 let (status, _) = send(454 let (status, _) = send(
454 &fx.router,455 &fx.router,
@@ -458,20 +459,8 @@ mod tests {
458 Some(form),459 Some(form),
459 )460 )
460 .await;461 .await;
461- assert_eq!(status, 403);462+ assert_eq!(status, 403, "case csrf");
462- assert!(
463- fx.store
464- .push_subscriptions(&fx.user_id)
465- .await
466- .expect("list")
467- .is_empty()
468- );
469- }
470 463
471- #[tokio::test]
472- async fn a_subscription_with_bad_fields_is_refused() {
473- let fx = fixture().await;
474- let (p256dh, auth) = browser_keys();
475 let http_endpoint = subscribe_form(CSRF, "http://push.example.test/x", &p256dh, &auth);464 let http_endpoint = subscribe_form(CSRF, "http://push.example.test/x", &p256dh, &auth);
476 let (status, _) = send(465 let (status, _) = send(
477 &fx.router,466 &fx.router,
@@ -481,7 +470,7 @@ mod tests {
481 Some(http_endpoint),470 Some(http_endpoint),
482 )471 )
483 .await;472 .await;
484- assert_eq!(status, 400, "an endpoint must be https");473+ assert_eq!(status, 400, "case http endpoint: an endpoint must be https");
485 let short_auth = subscribe_form(474 let short_auth = subscribe_form(
486 CSRF,475 CSRF,
487 "https://push.example.test/x",476 "https://push.example.test/x",
@@ -496,7 +485,7 @@ mod tests {
496 Some(short_auth),485 Some(short_auth),
497 )486 )
498 .await;487 .await;
499- assert_eq!(status, 400, "the auth secret is 16 bytes");488+ assert_eq!(status, 400, "case short auth: the auth secret is 16 bytes");
500 let not_a_point = subscribe_form(489 let not_a_point = subscribe_form(
501 CSRF,490 CSRF,
502 "https://push.example.test/x",491 "https://push.example.test/x",
@@ -511,7 +500,7 @@ mod tests {
511 Some(not_a_point),500 Some(not_a_point),
512 )501 )
513 .await;502 .await;
514- assert_eq!(status, 400, "the browser key is a point");503+ assert_eq!(status, 400, "case not a point: the browser key is a point");
515 assert!(504 assert!(
516 fx.store505 fx.store
517 .push_subscriptions(&fx.user_id)506 .push_subscriptions(&fx.user_id)
@@ -560,8 +549,9 @@ mod tests {
560 );549 );
561 }550 }
562 551
552+ /// The push worker and manifest are public, while the events stream needs a session.
563 #[tokio::test]553 #[tokio::test]
564- async fn the_events_stream_needs_a_session() {554+ async fn worker_and_manifest_are_public_and_events_need_a_session() {
565 let fx = fixture().await;555 let fx = fixture().await;
566 let (status, _) = send(556 let (status, _) = send(
567 &fx.router,557 &fx.router,
@@ -571,12 +561,8 @@ mod tests {
571 None,561 None,
572 )562 )
573 .await;563 .await;
574- assert_eq!(status, 401);564+ assert_eq!(status, 401, "case events without a session");
575- }
576 565
577- #[tokio::test]
578- async fn the_service_worker_and_manifest_are_served() {
579- let fx = fixture().await;
580 let (status, sw) = send(&fx.router, "GET", "/sw.js", None, None).await;566 let (status, sw) = send(&fx.router, "GET", "/sw.js", None, None).await;
581 assert_eq!(status, 200);567 assert_eq!(status, 200);
582 assert!(sw.contains("notificationclick"), "{sw}");568 assert!(sw.contains("notificationclick"), "{sw}");