Page tests merge into tables and drop duplicate cases
Browse files at this commit79f48c9d787b4bdedb03367c23aa8f64e650cf0cParent: f12f76a- test
- page tests merge into tables and drop duplicate cases
5 changed files +83 -141
- crates/forge-web/src/pages/profile.rs +13 -15
- crates/forge-web/src/pages/pulls_merge.rs +21 -44
- crates/forge-web/src/pages/releases_tests.rs +21 -38
- crates/forge-web/src/pages/settings_appearance.rs +2 -10
- crates/forge-web/src/pages/settings_profile.rs +26 -34
crates/forge-web/src/pages/profile.rsmodified+13 -15
| @@ -731,13 +731,15 @@ mod tests { | ||
| 731 | 731 | assert!(!as_member.contains(href), "member does not see Settings"); |
| 732 | 732 | } |
| 733 | 733 | |
| 734 | + /// Anonymous and other users see only public repos; the owner sees all, and a collaborator | |
| 735 | + /// sees the repo they were added to. | |
| 734 | 736 | #[tokio::test] |
| 735 | - async fn anonymous_and_other_users_see_only_public_repos() { | |
| 737 | + async fn repo_list_follows_the_viewers_access() { | |
| 736 | 738 | let site = seeded().await; |
| 737 | 739 | let (_, anon) = get(&site.router, "/tahinli", None).await; |
| 738 | - assert!(anon.contains("tahinli/open-repo")); | |
| 739 | - assert!(!anon.contains("tahinli/secret-repo")); | |
| 740 | - assert!(!anon.contains("tahinli/shared-repo")); | |
| 740 | + assert!(anon.contains("tahinli/open-repo"), "anonymous"); | |
| 741 | + assert!(!anon.contains("tahinli/secret-repo"), "anonymous"); | |
| 742 | + assert!(!anon.contains("tahinli/shared-repo"), "anonymous"); | |
| 741 | 743 | |
| 742 | 744 | let bob = site |
| 743 | 745 | .store |
| @@ -746,14 +748,10 @@ mod tests { | ||
| 746 | 748 | .unwrap(); |
| 747 | 749 | let cookie = sign_in(&site.store, &bob.id, "bob-token").await; |
| 748 | 750 | let (_, other) = get(&site.router, "/tahinli", Some(&cookie)).await; |
| 749 | - assert!(other.contains("tahinli/open-repo")); | |
| 750 | - assert!(!other.contains("tahinli/secret-repo")); | |
| 751 | - assert!(!other.contains("tahinli/shared-repo")); | |
| 752 | - } | |
| 751 | + assert!(other.contains("tahinli/open-repo"), "other user"); | |
| 752 | + assert!(!other.contains("tahinli/secret-repo"), "other user"); | |
| 753 | + assert!(!other.contains("tahinli/shared-repo"), "other user"); | |
| 753 | 754 | |
| 754 | - #[tokio::test] | |
| 755 | - async fn owner_sees_private_and_collaborator_sees_their_repo() { | |
| 756 | - let site = seeded().await; | |
| 757 | 755 | let tahinli = site |
| 758 | 756 | .store |
| 759 | 757 | .user_by_username("tahinli") |
| @@ -762,14 +760,14 @@ mod tests { | ||
| 762 | 760 | .unwrap(); |
| 763 | 761 | let cookie = sign_in(&site.store, &tahinli.id, "tahinli-token").await; |
| 764 | 762 | let (_, body) = get(&site.router, "/tahinli", Some(&cookie)).await; |
| 765 | - assert!(body.contains("tahinli/secret-repo")); | |
| 766 | - assert!(body.contains("tahinli/shared-repo")); | |
| 763 | + assert!(body.contains("tahinli/secret-repo"), "owner"); | |
| 764 | + assert!(body.contains("tahinli/shared-repo"), "owner"); | |
| 767 | 765 | |
| 768 | 766 | let carol = site.store.user_by_username("carol").await.unwrap().unwrap(); |
| 769 | 767 | let cookie = sign_in(&site.store, &carol.id, "carol-token").await; |
| 770 | 768 | let (_, body) = get(&site.router, "/tahinli", Some(&cookie)).await; |
| 771 | - assert!(body.contains("tahinli/shared-repo")); | |
| 772 | - assert!(!body.contains("tahinli/secret-repo")); | |
| 769 | + assert!(body.contains("tahinli/shared-repo"), "collaborator"); | |
| 770 | + assert!(!body.contains("tahinli/secret-repo"), "collaborator"); | |
| 773 | 771 | } |
| 774 | 772 | |
| 775 | 773 | #[tokio::test] |
crates/forge-web/src/pages/pulls_merge.rsmodified+21 -44
| @@ -1184,7 +1184,7 @@ mod tests { | ||
| 1184 | 1184 | } |
| 1185 | 1185 | |
| 1186 | 1186 | #[tokio::test] |
| 1187 | - async fn read_only_collaborator_gets_403() { | |
| 1187 | + async fn unauthorised_merge_requests_are_refused_and_base_unchanged() { | |
| 1188 | 1188 | let fx = fixture().await; |
| 1189 | 1189 | let number = fx |
| 1190 | 1190 | .open_feature("feature", "feature.txt", "f1", &fx.bob) |
| @@ -1196,52 +1196,29 @@ mod tests { | ||
| 1196 | 1196 | .expect("collaborator"); |
| 1197 | 1197 | let bob_cookie = fx.sign_in(&fx.bob, "bob-token").await; |
| 1198 | 1198 | let before = fx.main_tip(); |
| 1199 | + let path = format!("/tahinli/proj/pulls/{number}/merge"); | |
| 1199 | 1200 | |
| 1200 | - let reply = fx | |
| 1201 | - .post( | |
| 1202 | - &format!("/tahinli/proj/pulls/{number}/merge"), | |
| 1203 | - Some(&bob_cookie), | |
| 1204 | - merge_form("merge", None), | |
| 1205 | - ) | |
| 1206 | - .await; | |
| 1207 | - assert_eq!(reply.status, 403); | |
| 1208 | - assert_eq!(fx.main_tip(), before); | |
| 1209 | - } | |
| 1210 | - | |
| 1211 | - #[tokio::test] | |
| 1212 | - async fn anonymous_viewer_of_private_repo_gets_404() { | |
| 1213 | - let fx = fixture().await; | |
| 1214 | - let number = fx | |
| 1215 | - .open_feature("feature", "feature.txt", "f1", &fx.bob) | |
| 1216 | - .await; | |
| 1217 | - | |
| 1218 | - let reply = fx | |
| 1219 | - .post( | |
| 1220 | - &format!("/tahinli/proj/pulls/{number}/merge"), | |
| 1221 | - None, | |
| 1201 | + // A read-only collaborator gets 403, a stranger to the private repo gets 404. | |
| 1202 | + let cases = [ | |
| 1203 | + ( | |
| 1204 | + "read only", | |
| 1205 | + Some(bob_cookie.as_str()), | |
| 1222 | 1206 | merge_form("merge", None), |
| 1223 | - ) | |
| 1224 | - .await; | |
| 1225 | - assert_eq!(reply.status, 404); | |
| 1226 | - } | |
| 1227 | - | |
| 1228 | - #[tokio::test] | |
| 1229 | - async fn missing_csrf_is_rejected() { | |
| 1230 | - let fx = fixture().await; | |
| 1231 | - let number = fx | |
| 1232 | - .open_feature("feature", "feature.txt", "f1", &fx.bob) | |
| 1233 | - .await; | |
| 1234 | - let before = fx.main_tip(); | |
| 1235 | - | |
| 1236 | - let reply = fx | |
| 1237 | - .post( | |
| 1238 | - &format!("/tahinli/proj/pulls/{number}/merge"), | |
| 1239 | - Some(&fx.tahinli_cookie), | |
| 1207 | + 403, | |
| 1208 | + ), | |
| 1209 | + ("anonymous", None, merge_form("merge", None), 404), | |
| 1210 | + ( | |
| 1211 | + "missing csrf", | |
| 1212 | + Some(fx.tahinli_cookie.as_str()), | |
| 1240 | 1213 | "style=merge".to_owned(), |
| 1241 | - ) | |
| 1242 | - .await; | |
| 1243 | - assert_eq!(reply.status, 403); | |
| 1244 | - assert_eq!(fx.main_tip(), before); | |
| 1214 | + 403, | |
| 1215 | + ), | |
| 1216 | + ]; | |
| 1217 | + for (name, cookie, body, status) in cases { | |
| 1218 | + let reply = fx.post(&path, cookie, body).await; | |
| 1219 | + assert_eq!(reply.status, status, "case {name}"); | |
| 1220 | + assert_eq!(fx.main_tip(), before, "case {name}"); | |
| 1221 | + } | |
| 1245 | 1222 | } |
| 1246 | 1223 | |
| 1247 | 1224 | #[tokio::test] |
crates/forge-web/src/pages/releases_tests.rsmodified+21 -38
| @@ -830,66 +830,49 @@ async fn retagging_adopts_an_existing_tag_and_refuses_clashes() { | ||
| 830 | 830 | ); |
| 831 | 831 | } |
| 832 | 832 | |
| 833 | +/// Create refuses a bad tag or a missing target before touching git, and takes a commit id as a | |
| 834 | +/// target. | |
| 833 | 835 | #[tokio::test] |
| 834 | -async fn create_refuses_a_bad_tag_before_touching_git() { | |
| 836 | +async fn create_validates_its_tag_and_target() { | |
| 835 | 837 | let fx = fixture(None).await; |
| 836 | - let input = CreateRelease { | |
| 837 | - tag: "a/b".to_owned(), | |
| 838 | - target: Some("main".to_owned()), | |
| 838 | + let input = |tag: &str, target: &str| CreateRelease { | |
| 839 | + tag: tag.to_owned(), | |
| 840 | + target: Some(target.to_owned()), | |
| 839 | 841 | title: "x".to_owned(), |
| 840 | 842 | body: String::new(), |
| 841 | 843 | draft: false, |
| 842 | 844 | prerelease: false, |
| 843 | 845 | }; |
| 844 | - let refused = release_ops::create(&fx.state, &fx.repo, &fx.tahinli, input).await; | |
| 846 | + let refused = release_ops::create(&fx.state, &fx.repo, &fx.tahinli, input("a/b", "main")).await; | |
| 845 | 847 | assert!( |
| 846 | 848 | matches!(refused, Err(ReleaseError::Invalid(_))), |
| 847 | - "{refused:?}" | |
| 849 | + "bad tag: {refused:?}" | |
| 848 | 850 | ); |
| 849 | - assert!(fx.tag_target("a/b").is_none()); | |
| 850 | -} | |
| 851 | + assert!(fx.tag_target("a/b").is_none(), "bad tag"); | |
| 851 | 852 | |
| 852 | -#[tokio::test] | |
| 853 | -async fn create_takes_a_commit_id_as_its_target_and_refuses_a_missing_one() { | |
| 854 | - let fx = fixture(None).await; | |
| 855 | 853 | let tip = fx.main_tip(); |
| 856 | - let made = release_ops::create( | |
| 857 | - &fx.state, | |
| 858 | - &fx.repo, | |
| 859 | - &fx.tahinli, | |
| 860 | - CreateRelease { | |
| 861 | - tag: "v7".to_owned(), | |
| 862 | - target: Some(tip.clone()), | |
| 863 | - title: "by sha".to_owned(), | |
| 864 | - body: String::new(), | |
| 865 | - draft: false, | |
| 866 | - prerelease: false, | |
| 867 | - }, | |
| 868 | - ) | |
| 869 | - .await | |
| 870 | - .expect("a commit id works as a target"); | |
| 871 | - assert_eq!(made.target_oid, tip); | |
| 872 | - assert_eq!(fx.tag_target("v7").as_deref(), Some(tip.as_str())); | |
| 854 | + let made = release_ops::create(&fx.state, &fx.repo, &fx.tahinli, input("v7", &tip)) | |
| 855 | + .await | |
| 856 | + .expect("a commit id works as a target"); | |
| 857 | + assert_eq!(made.target_oid, tip, "commit id target"); | |
| 858 | + assert_eq!( | |
| 859 | + fx.tag_target("v7").as_deref(), | |
| 860 | + Some(tip.as_str()), | |
| 861 | + "commit id target" | |
| 862 | + ); | |
| 873 | 863 | |
| 874 | 864 | let missing = release_ops::create( |
| 875 | 865 | &fx.state, |
| 876 | 866 | &fx.repo, |
| 877 | 867 | &fx.tahinli, |
| 878 | - CreateRelease { | |
| 879 | - tag: "v8".to_owned(), | |
| 880 | - target: Some("1111111111111111111111111111111111111111".to_owned()), | |
| 881 | - title: "missing".to_owned(), | |
| 882 | - body: String::new(), | |
| 883 | - draft: false, | |
| 884 | - prerelease: false, | |
| 885 | - }, | |
| 868 | + input("v8", "1111111111111111111111111111111111111111"), | |
| 886 | 869 | ) |
| 887 | 870 | .await; |
| 888 | 871 | assert!( |
| 889 | 872 | matches!(missing, Err(ReleaseError::Invalid(_))), |
| 890 | - "{missing:?}" | |
| 873 | + "missing target: {missing:?}" | |
| 891 | 874 | ); |
| 892 | - assert!(fx.tag_target("v8").is_none()); | |
| 875 | + assert!(fx.tag_target("v8").is_none(), "missing target"); | |
| 893 | 876 | } |
| 894 | 877 | |
| 895 | 878 | #[tokio::test] |
crates/forge-web/src/pages/settings_appearance.rsmodified+2 -10
| @@ -543,7 +543,6 @@ mod tests { | ||
| 543 | 543 | "hue-07", |
| 544 | 544 | "hue-", |
| 545 | 545 | "hue-+5", |
| 546 | - "teal", | |
| 547 | 546 | ] { |
| 548 | 547 | assert!(accent_choice(Lang::En, Some(id), "sage").is_err(), "{id}"); |
| 549 | 548 | } |
| @@ -578,18 +577,15 @@ mod tests { | ||
| 578 | 577 | } |
| 579 | 578 | |
| 580 | 579 | #[test] |
| 581 | - fn the_stored_value_is_selected() { | |
| 580 | + fn the_stored_theme_accent_and_base_are_selected() { | |
| 582 | 581 | let options = choices(THEME_CODES, "dark", |code| theme_label(Lang::En, code)); |
| 583 | 582 | let selected: Vec<&str> = options |
| 584 | 583 | .iter() |
| 585 | 584 | .filter(|c| c.selected) |
| 586 | 585 | .map(|c| c.value) |
| 587 | 586 | .collect(); |
| 588 | - assert_eq!(selected, ["dark"]); | |
| 589 | - } | |
| 587 | + assert_eq!(selected, ["dark"], "theme"); | |
| 590 | 588 | |
| 591 | - #[test] | |
| 592 | - fn the_stored_accent_and_base_are_selected() { | |
| 593 | 589 | let codes: Vec<&'static str> = accent::ids().collect(); |
| 594 | 590 | let options = choices(&codes, "plum", |id| accent_name(Lang::En, id)); |
| 595 | 591 | let selected: Vec<&str> = options |
| @@ -644,10 +640,6 @@ mod tests { | ||
| 644 | 640 | assert_eq!(theme_label(Lang::En, "dark"), "Dark"); |
| 645 | 641 | assert_eq!(theme_label(Lang::Tr, "dark"), "Koyu"); |
| 646 | 642 | assert_eq!(base_name(Lang::Tr, "ink"), "M\u{fc}rekkep"); |
| 647 | - } | |
| 648 | - | |
| 649 | - #[test] | |
| 650 | - fn light_is_marked_as_the_default() { | |
| 651 | 643 | assert_eq!(theme_label(Lang::En, "light"), "Light (default)"); |
| 652 | 644 | assert_eq!( |
| 653 | 645 | theme_label(Lang::Tr, "light"), |
crates/forge-web/src/pages/settings_profile.rsmodified+26 -34
| @@ -652,16 +652,22 @@ pub(crate) mod tests { | ||
| 652 | 652 | #[tokio::test] |
| 653 | 653 | async fn post_without_a_valid_csrf_token_is_rejected() { |
| 654 | 654 | let fx = fixture().await; |
| 655 | - let forged = "csrf=wrong&username=Tahinli&about=&timezone=UTC"; | |
| 656 | - let (status, _, _) = | |
| 657 | - send(&fx.router, "POST", "/settings/profile", true, Some(forged)).await; | |
| 658 | - assert_eq!(status, 403); | |
| 659 | - let missing = "username=Tahinli&about=&timezone=UTC"; | |
| 660 | - let (status, _, _) = | |
| 661 | - send(&fx.router, "POST", "/settings/profile", true, Some(missing)).await; | |
| 662 | - assert_eq!(status, 403); | |
| 655 | + let cases = [ | |
| 656 | + ("forged", "csrf=wrong&username=Tahinli&about=&timezone=UTC"), | |
| 657 | + ("missing", "username=Tahinli&about=&timezone=UTC"), | |
| 658 | + ( | |
| 659 | + "missing with about", | |
| 660 | + "username=Tahinli&about=x&timezone=UTC", | |
| 661 | + ), | |
| 662 | + ]; | |
| 663 | + for (name, form) in cases { | |
| 664 | + let (status, _, _) = | |
| 665 | + send(&fx.router, "POST", "/settings/profile", true, Some(form)).await; | |
| 666 | + assert_eq!(status, 403, "case {name}"); | |
| 667 | + } | |
| 663 | 668 | let stored = fx.store.user_by_id(&fx.user.id).await.unwrap().unwrap(); |
| 664 | 669 | assert_eq!(stored.username, "tahinli"); |
| 670 | + assert_eq!(stored.about, ""); | |
| 665 | 671 | } |
| 666 | 672 | |
| 667 | 673 | #[tokio::test] |
| @@ -785,17 +791,7 @@ pub(crate) mod tests { | ||
| 785 | 791 | } |
| 786 | 792 | |
| 787 | 793 | #[tokio::test] |
| 788 | - async fn profile_post_without_csrf_is_rejected() { | |
| 789 | - let fx = fixture().await; | |
| 790 | - let form = "username=tahinli&about=x&timezone=UTC"; | |
| 791 | - let (status, _, _) = send(&fx.router, "POST", "/settings/profile", true, Some(form)).await; | |
| 792 | - assert_eq!(status, 403); | |
| 793 | - let stored = fx.store.user_by_id(&fx.user.id).await.unwrap().unwrap(); | |
| 794 | - assert_eq!(stored.about, ""); | |
| 795 | - } | |
| 796 | - | |
| 797 | - #[tokio::test] | |
| 798 | - async fn avatar_upload_without_csrf_is_rejected() { | |
| 794 | + async fn avatar_writes_without_csrf_are_rejected() { | |
| 799 | 795 | let fx = fixture().await; |
| 800 | 796 | let png = png_bytes(); |
| 801 | 797 | let (content_type, body) = multipart(&[("avatar", Some(("a.png", "image/png")), &png[..])]); |
| @@ -808,8 +804,18 @@ pub(crate) mod tests { | ||
| 808 | 804 | body, |
| 809 | 805 | ) |
| 810 | 806 | .await; |
| 811 | - assert_eq!(reply.status, 403); | |
| 807 | + assert_eq!(reply.status, 403, "upload"); | |
| 812 | 808 | assert!(fx.store.avatar_hash(&fx.user.id).await.unwrap().is_none()); |
| 809 | + | |
| 810 | + let (status, _, _) = send( | |
| 811 | + &fx.router, | |
| 812 | + "POST", | |
| 813 | + "/settings/profile/avatar/delete", | |
| 814 | + true, | |
| 815 | + Some("csrf=nope"), | |
| 816 | + ) | |
| 817 | + .await; | |
| 818 | + assert_eq!(status, 403, "remove"); | |
| 813 | 819 | } |
| 814 | 820 | |
| 815 | 821 | #[tokio::test] |
| @@ -934,18 +940,4 @@ pub(crate) mod tests { | ||
| 934 | 940 | ); |
| 935 | 941 | assert!(default.text().starts_with("<svg"), "{}", default.text()); |
| 936 | 942 | } |
| 937 | - | |
| 938 | - #[tokio::test] | |
| 939 | - async fn avatar_remove_without_csrf_is_rejected() { | |
| 940 | - let fx = fixture().await; | |
| 941 | - let (status, _, _) = send( | |
| 942 | - &fx.router, | |
| 943 | - "POST", | |
| 944 | - "/settings/profile/avatar/delete", | |
| 945 | - true, | |
| 946 | - Some("csrf=nope"), | |
| 947 | - ) | |
| 948 | - .await; | |
| 949 | - assert_eq!(status, 403); | |
| 950 | - } | |
| 951 | 943 | } |