forge
Explore
Log in

Don't you dare go Hollow

Page tests share their fixtures and merge into tables

Browse files at this commit

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

Counts per file, before to after:
- profile.rs: 13 to 4
- profile_pins.rs: 6 to 2
- settings_profile.rs: 11 to 2
- settings_appearance.rs: 8 to 5
- settings_live.rs: 5 to 3
- settings_notifications.rs: 4 to 2

Scenarios that share one fixture now run in order in one test, with
unique names per scenario and a label on every assertion. Pure
checks that cannot fail were folded into their neighbours. No
assertion was removed.
crates/forge-web/src/pages/profile.rsmodified+287 -248
@@ -686,103 +686,91 @@ mod tests {
686686 site
687687 }
688688
689+ /// One seeded site covers the repo list for each kind of viewer, the about text, the
690+ /// edit button, the unknown-user 404 and the fixed routes. Each signed-in viewer gets its
691+ /// own session token.
689692 #[tokio::test]
690- async fn about_is_rendered_and_sanitized() {
693+ async fn profile_visibility_routing_and_edit_button() {
691694 let site = seeded().await;
692- let (status, body) = get(&site.router, "/tahinli", None).await;
693- assert_eq!(status, 200);
694- assert!(body.contains("<h1"), "heading rendered: {body}");
695- assert!(body.contains("Hello heading"));
696- assert!(body.contains("<strong>bold</strong>"));
697- assert!(!body.contains("<script>"), "script stripped: {body}");
698- assert!(!body.contains("alert(1)"));
699- }
700-
701- #[tokio::test]
702- async fn org_sidebar_shows_settings_to_owners_only() {
703- let site = site().await;
704- let owner = site
705- .store
706- .create_user("tahinli", None, "not-a-real-hash", false)
707- .await
708- .unwrap();
709- let member = site
710- .store
711- .create_user("kaan", None, "not-a-real-hash", false)
712- .await
713- .unwrap();
714- let org = site.store.create_org("forge-org", &owner.id).await.unwrap();
715- site.store
716- .add_org_member(
717- &org.id,
718- &member.id,
719- forge_core::store::orgs::OrgMemberRole::Member,
720- )
721- .await
722- .unwrap();
723- let owner_cookie = sign_in(&site.store, &owner.id, "owner-token").await;
724- let member_cookie = sign_in(&site.store, &member.id, "member-token").await;
725- let href = "href=\"/org/forge-org/settings\"";
726- let (_, as_owner) = get(&site.router, "/org/forge-org/members", Some(&owner_cookie)).await;
727- assert!(as_owner.contains(href), "owner sees Settings");
728- let (_, as_member) =
729- get(&site.router, "/org/forge-org/members", Some(&member_cookie)).await;
730- assert!(as_member.contains("href=\"/org/forge-org/teams\""));
731- assert!(!as_member.contains(href), "member does not see Settings");
732- }
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.
736- #[tokio::test]
737- async fn repo_list_follows_the_viewers_access() {
738- let site = seeded().await;
739- let (_, anon) = get(&site.router, "/tahinli", None).await;
740- assert!(anon.contains("tahinli/open-repo"), "anonymous");
741- assert!(!anon.contains("tahinli/secret-repo"), "anonymous");
742- assert!(!anon.contains("tahinli/shared-repo"), "anonymous");
743695
696+ // About is rendered and sanitized.
697+ let (status, anon) = get(&site.router, "/tahinli", None).await;
698+ assert_eq!(status, 200, "about");
699+ assert!(anon.contains("<h1"), "about: heading rendered: {anon}");
700+ assert!(anon.contains("Hello heading"), "about: heading text");
701+ assert!(
702+ anon.contains("<strong>bold</strong>"),
703+ "about: bold rendered"
704+ );
705+ assert!(!anon.contains("<script>"), "about: script stripped: {anon}");
706+ assert!(!anon.contains("alert(1)"), "about: script body stripped");
707+
708+ // Anonymous visitors see only public repos and no edit button.
709+ assert!(anon.contains("tahinli/open-repo"), "anonymous: public repo");
710+ assert!(
711+ !anon.contains("tahinli/secret-repo"),
712+ "anonymous: private repo"
713+ );
714+ assert!(
715+ !anon.contains("tahinli/shared-repo"),
716+ "anonymous: shared repo"
717+ );
718+ assert!(!anon.contains("profile-edit"), "anonymous: edit button");
719+
720+ // Another user sees the same public-only list and no edit button.
744721 let bob = site
745722 .store
746723 .create_user("bob", None, "not-a-real-hash", false)
747724 .await
748725 .unwrap();
749- let cookie = sign_in(&site.store, &bob.id, "bob-token").await;
726+ let cookie = sign_in(&site.store, &bob.id, "visibility-bob-token").await;
750727 let (_, other) = get(&site.router, "/tahinli", Some(&cookie)).await;
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");
754-
755- let tahinli = site
756- .store
757- .user_by_username("tahinli")
758- .await
759- .unwrap()
760- .unwrap();
761- let cookie = sign_in(&site.store, &tahinli.id, "tahinli-token").await;
762- let (_, body) = get(&site.router, "/tahinli", Some(&cookie)).await;
763- assert!(body.contains("tahinli/secret-repo"), "owner");
764- assert!(body.contains("tahinli/shared-repo"), "owner");
765-
766- let carol = site.store.user_by_username("carol").await.unwrap().unwrap();
767- let cookie = sign_in(&site.store, &carol.id, "carol-token").await;
768- let (_, body) = get(&site.router, "/tahinli", Some(&cookie)).await;
769- assert!(body.contains("tahinli/shared-repo"), "collaborator");
770- assert!(!body.contains("tahinli/secret-repo"), "collaborator");
771- }
772-
773- #[tokio::test]
774- async fn unknown_user_is_404_and_lookup_is_case_insensitive() {
775- let site = seeded().await;
728+ assert!(
729+ other.contains("tahinli/open-repo"),
730+ "other user: public repo"
731+ );
732+ assert!(
733+ !other.contains("tahinli/secret-repo"),
734+ "other user: private repo"
735+ );
736+ assert!(
737+ !other.contains("tahinli/shared-repo"),
738+ "other user: shared repo"
739+ );
740+ assert!(!other.contains("profile-edit"), "other user: edit button");
741+
742+ // The owner sees every repo and the edit button.
743+ let tahinli = user_id(&site.store, "tahinli").await;
744+ let cookie = sign_in(&site.store, &tahinli, "visibility-owner-token").await;
745+ let (_, owner) = get(&site.router, "/tahinli", Some(&cookie)).await;
746+ assert!(owner.contains("tahinli/secret-repo"), "owner: private repo");
747+ assert!(owner.contains("tahinli/shared-repo"), "owner: shared repo");
748+ assert!(
749+ owner.contains("class=\"button profile-edit\" href=\"/settings/profile\""),
750+ "owner: edit button"
751+ );
752+
753+ // A collaborator sees the repo they were added to, not the private one.
754+ let carol = user_id(&site.store, "carol").await;
755+ let cookie = sign_in(&site.store, &carol, "visibility-carol-token").await;
756+ let (_, collab) = get(&site.router, "/tahinli", Some(&cookie)).await;
757+ assert!(
758+ collab.contains("tahinli/shared-repo"),
759+ "collaborator: shared repo"
760+ );
761+ assert!(
762+ !collab.contains("tahinli/secret-repo"),
763+ "collaborator: private repo"
764+ );
765+
766+ // Unknown users 404, and the lookup ignores case.
776767 let (status, _) = get(&site.router, "/nobody-here", None).await;
777- assert_eq!(status, 404);
768+ assert_eq!(status, 404, "unknown user");
778769 let (status, body) = get(&site.router, "/TAHINLI", None).await;
779- assert_eq!(status, 200);
780- assert!(body.contains("tahinli"));
781- }
770+ assert_eq!(status, 200, "case-insensitive lookup");
771+ assert!(body.contains("tahinli"), "case-insensitive lookup");
782772
783- #[tokio::test]
784- async fn fixed_routes_are_not_shadowed_by_the_profile() {
785- let site = seeded().await;
773+ // Fixed routes are not shadowed by the profile.
786774 for uri in [
787775 "/new",
788776 "/login",
@@ -803,219 +791,270 @@ mod tests {
803791 }
804792 // The fixed login page still renders its form, not a profile.
805793 let (status, body) = get(&site.router, "/login", None).await;
806- assert_eq!(status, 200);
807- assert!(body.contains("<form"));
794+ assert_eq!(status, 200, "fixed login page");
795+ assert!(body.contains("<form"), "fixed login page renders its form");
808796 // Two-segment repo routes keep working and still 404 for a missing repo.
809797 let (status, body) = get(&site.router, "/tahinli/missing", None).await;
810- assert_eq!(status, 404);
811- assert!(!body.contains("<article class=\"profile-page\""));
812- }
813-
814- fn count(body: &str, needle: &str) -> usize {
815- body.matches(needle).count()
816- }
817-
818- /// A user with 35 public repos, `bulk-00` to `bulk-34`.
819- async fn bulk_site() -> Site {
820- let site = site().await;
821- let tahinli = site
822- .store
823- .create_user("tahinli", None, "not-a-real-hash", false)
824- .await
825- .unwrap();
826- for i in 0..35 {
827- site.store
828- .create_repo(
829- &tahinli.id,
830- &format!("bulk-{i:02}"),
831- "",
832- Visibility::Public,
833- "main",
834- )
835- .await
836- .unwrap();
837- }
838- site
839- }
840-
841- async fn user_id(store: &Store, name: &str) -> String {
842- store.user_by_username(name).await.unwrap().unwrap().id
798+ assert_eq!(status, 404, "missing repo");
799+ assert!(
800+ !body.contains("<article class=\"profile-page\""),
801+ "missing repo"
802+ );
843803 }
844804
805+ /// Stars, the org sidebar and org pins, on one seeded site. The org scenarios use their
806+ /// own org names and session tokens.
845807 #[tokio::test]
846- async fn repositories_tab_pages_thirty_at_a_time() {
847- let site = bulk_site().await;
848- let (status, first) = get(&site.router, "/tahinli?tab=repositories&sort=name", None).await;
849- assert_eq!(status, 200);
850- assert_eq!(count(&first, "class=\"repo-name\""), 30);
851- assert!(first.contains("page=2"), "next link: {first}");
852-
853- let (_, second) = get(
854- &site.router,
855- "/tahinli?tab=repositories&sort=name&page=2",
856- None,
857- )
858- .await;
859- assert_eq!(count(&second, "class=\"repo-name\""), 5);
860- assert!(second.contains("tahinli/bulk-34"));
861- assert!(!second.contains("tahinli/bulk-00"));
862- }
863-
864- #[tokio::test]
865- async fn name_filter_is_a_case_insensitive_substring() {
866- let site = bulk_site().await;
867- let (_, body) = get(&site.router, "/tahinli?tab=repositories&q=BULK-1", None).await;
868- assert_eq!(count(&body, "class=\"repo-name\""), 10);
869- assert!(body.contains("tahinli/bulk-12"));
870- assert!(!body.contains("tahinli/bulk-22"));
871- }
872-
873- #[tokio::test]
874- async fn stars_tab_lists_only_starred_repos_the_viewer_may_read() {
808+ async fn stars_org_sidebar_and_org_pins() {
875809 let site = seeded().await;
810+ let tahinli = user_id(&site.store, "tahinli").await;
811+
812+ // The stars tab lists only starred repos the viewer may read.
876813 let mira = site
877814 .store
878815 .create_user("mira", None, "not-a-real-hash", false)
879816 .await
880817 .unwrap();
881- let open = site
882- .store
883- .list_repos_by_owner(&user_id(&site.store, "tahinli").await)
884- .await
885- .unwrap();
886- for repo in &open {
818+ let repos = site.store.list_repos_by_owner(&tahinli).await.unwrap();
819+ for repo in &repos {
887820 if repo.name == "open-repo" || repo.name == "secret-repo" {
888821 site.store.star(&mira.id, &repo.id).await.unwrap();
889822 }
890823 }
891824 let (_, anon) = get(&site.router, "/mira?tab=stars", None).await;
892- assert!(anon.contains("tahinli/open-repo"));
893- assert!(!anon.contains("tahinli/secret-repo"));
825+ assert!(
826+ anon.contains("tahinli/open-repo"),
827+ "stars: public starred repo"
828+ );
829+ assert!(
830+ !anon.contains("tahinli/secret-repo"),
831+ "stars: private starred repo"
832+ );
833+
834+ // The org sidebar shows Settings to owners only.
835+ let kaan = site
836+ .store
837+ .create_user("kaan", None, "not-a-real-hash", false)
838+ .await
839+ .unwrap();
840+ let org = site.store.create_org("forge-org", &tahinli).await.unwrap();
841+ site.store
842+ .add_org_member(
843+ &org.id,
844+ &kaan.id,
845+ forge_core::store::orgs::OrgMemberRole::Member,
846+ )
847+ .await
848+ .unwrap();
849+ let owner_cookie = sign_in(&site.store, &tahinli, "org-owner-token").await;
850+ let member_cookie = sign_in(&site.store, &kaan.id, "org-member-token").await;
851+ let href = "href=\"/org/forge-org/settings\"";
852+ let (_, as_owner) = get(&site.router, "/org/forge-org/members", Some(&owner_cookie)).await;
853+ assert!(as_owner.contains(href), "org sidebar: owner sees Settings");
854+ let (_, as_member) =
855+ get(&site.router, "/org/forge-org/members", Some(&member_cookie)).await;
856+ assert!(
857+ as_member.contains("href=\"/org/forge-org/teams\""),
858+ "org sidebar: member sees Teams"
859+ );
860+ assert!(
861+ !as_member.contains(href),
862+ "org sidebar: member does not see Settings"
863+ );
864+
865+ // Org pins show on the org profile, with an edit link for owners only.
866+ let acme = site.store.create_org("acme", &tahinli).await.unwrap();
867+ let lib = site
868+ .store
869+ .create_repo(&acme.id, "lib", "", Visibility::Public, "main")
870+ .await
871+ .unwrap();
872+ site.store
873+ .set_profile_pins(&acme.id, &[lib.id])
874+ .await
875+ .unwrap();
876+ let (_, owner) = get(&site.router, "/acme", Some(&owner_cookie)).await;
877+ assert!(owner.contains("acme/lib"), "org pins: owner sees pin");
878+ assert!(
879+ owner.contains("href=\"/org/acme/settings/pins\""),
880+ "org pins: owner edit link"
881+ );
882+ let (_, anon) = get(&site.router, "/acme", None).await;
883+ assert!(anon.contains("acme/lib"), "org pins: anonymous sees pin");
884+ assert!(
885+ !anon.contains("Customize pins"),
886+ "org pins: anonymous has no edit link"
887+ );
894888 }
895889
890+ /// Pins, the popular-repos fallback and the display name, on one seeded site. The
891+ /// scenarios run in order, and each one sets the pins or name the next one reads.
896892 #[tokio::test]
897- async fn pins_show_on_the_overview_and_private_ones_only_to_the_owner() {
893+ async fn pins_fallback_and_display_name() {
898894 let site = seeded().await;
899895 let tahinli = user_id(&site.store, "tahinli").await;
900896 let repos = site.store.list_repos_by_owner(&tahinli).await.unwrap();
901- let open = repos
902- .iter()
903- .find(|r| r.name == "open-repo")
904- .unwrap()
905- .id
906- .clone();
907- let secret = repos
908- .iter()
909- .find(|r| r.name == "secret-repo")
910- .unwrap()
911- .id
912- .clone();
897+ let id_of = |name: &str| repos.iter().find(|r| r.name == name).unwrap().id.clone();
898+ let open = id_of("open-repo");
899+ let secret = id_of("secret-repo");
900+
901+ // Pins: anonymous visitors see the public pin only; the owner sees both.
913902 site.store
914- .set_profile_pins(&tahinli, &[open, secret])
903+ .set_profile_pins(&tahinli, &[open, secret.clone()])
915904 .await
916905 .unwrap();
917-
918906 let (_, anon) = get(&site.router, "/tahinli", None).await;
919- assert!(anon.contains("<h2>Pinned</h2>"));
920- assert_eq!(count(&anon, "class=\"pin-card\""), 1);
921- assert!(anon.contains("tahinli/open-repo"));
922- assert!(!anon.contains("tahinli/secret-repo"));
923- assert!(!anon.contains("Customize pins"));
924-
925- let cookie = sign_in(&site.store, &tahinli, "tahinli-token").await;
907+ assert!(anon.contains("<h2>Pinned</h2>"), "pins: section shown");
908+ assert_eq!(
909+ count(&anon, "class=\"pin-card\""),
910+ 1,
911+ "pins: anonymous pin count"
912+ );
913+ assert!(anon.contains("tahinli/open-repo"), "pins: public pin");
914+ assert!(
915+ !anon.contains("tahinli/secret-repo"),
916+ "pins: private pin hidden"
917+ );
918+ assert!(
919+ !anon.contains("Customize pins"),
920+ "pins: anonymous has no customize link"
921+ );
922+
923+ let cookie = sign_in(&site.store, &tahinli, "pins-owner-token").await;
926924 let (_, owner) = get(&site.router, "/tahinli", Some(&cookie)).await;
927- assert_eq!(count(&owner, "class=\"pin-card\""), 2);
928- assert!(owner.contains("tahinli/secret-repo"));
929- assert!(owner.contains("Customize pins"));
930- assert!(owner.contains("href=\"/settings/pins\""));
931- }
932-
933- #[tokio::test]
934- async fn overview_falls_back_to_popular_repos_when_no_pin_is_visible() {
935- let site = seeded().await;
936- let tahinli = user_id(&site.store, "tahinli").await;
937- let secret = site
938- .store
939- .list_repos_by_owner(&tahinli)
940- .await
941- .unwrap()
942- .into_iter()
943- .find(|r| r.name == "secret-repo")
944- .unwrap()
945- .id;
925+ assert_eq!(
926+ count(&owner, "class=\"pin-card\""),
927+ 2,
928+ "pins: owner pin count"
929+ );
930+ assert!(
931+ owner.contains("tahinli/secret-repo"),
932+ "pins: owner sees private pin"
933+ );
934+ assert!(
935+ owner.contains("Customize pins"),
936+ "pins: owner customize link"
937+ );
938+ assert!(
939+ owner.contains("href=\"/settings/pins\""),
940+ "pins: owner settings link"
941+ );
942+
943+ // Fallback: with no visible pin, the overview shows popular repos instead.
946944 site.store
947945 .set_profile_pins(&tahinli, &[secret])
948946 .await
949947 .unwrap();
950-
951948 let (_, anon) = get(&site.router, "/tahinli", None).await;
952- assert!(anon.contains("Popular repositories"));
953- assert!(anon.contains("tahinli/open-repo"));
954- assert!(!anon.contains("tahinli/secret-repo"));
955- }
956-
957- #[tokio::test]
958- async fn display_name_is_the_heading_with_the_username_below() {
959- let site = seeded().await;
960- let tahinli = user_id(&site.store, "tahinli").await;
949+ assert!(anon.contains("Popular repositories"), "fallback: heading");
950+ assert!(anon.contains("tahinli/open-repo"), "fallback: public repo");
951+ assert!(
952+ !anon.contains("tahinli/secret-repo"),
953+ "fallback: private repo hidden"
954+ );
955+
956+ // Display name: the heading uses it with the username below; a blank name falls back.
961957 site.store
962958 .set_display_name(&tahinli, "Ahmet Kaan Gümüş")
963959 .await
964960 .unwrap();
965961 let (status, body) = get(&site.router, "/tahinli", None).await;
966- assert_eq!(status, 200);
967- assert!(body.contains("<h1>Ahmet Kaan Gümüş</h1>"), "{body}");
968- assert!(body.contains("<p class=\"muted\">tahinli</p>"), "{body}");
962+ assert_eq!(status, 200, "display name: page");
963+ assert!(
964+ body.contains("<h1>Ahmet Kaan Gümüş</h1>"),
965+ "display name: heading {body}"
966+ );
967+ assert!(
968+ body.contains("<p class=\"muted\">tahinli</p>"),
969+ "display name: username below {body}"
970+ );
969971
970972 site.store.set_display_name(&tahinli, " ").await.unwrap();
971973 let (_, body) = get(&site.router, "/tahinli", None).await;
972- assert!(body.contains("<h1>tahinli</h1>"), "{body}");
973- assert!(!body.contains("<p class=\"muted\">tahinli</p>"), "{body}");
974+ assert!(
975+ body.contains("<h1>tahinli</h1>"),
976+ "blank name: heading {body}"
977+ );
978+ assert!(
979+ !body.contains("<p class=\"muted\">tahinli</p>"),
980+ "blank name: no username line {body}"
981+ );
974982 }
975983
976- #[tokio::test]
977- async fn only_the_owner_sees_the_edit_profile_button() {
978- let site = seeded().await;
979- let tahinli = user_id(&site.store, "tahinli").await;
980- let cookie = sign_in(&site.store, &tahinli, "tahinli-token").await;
981- let (_, owner) = get(&site.router, "/tahinli", Some(&cookie)).await;
982- assert!(owner.contains("class=\"button profile-edit\" href=\"/settings/profile\""));
983-
984- let (_, anon) = get(&site.router, "/tahinli", None).await;
985- assert!(!anon.contains("profile-edit"));
984+ fn count(body: &str, needle: &str) -> usize {
985+ body.matches(needle).count()
986+ }
986987
987- let bob = site
988+ /// A user with 35 public repos, `bulk-00` to `bulk-34`.
989+ async fn bulk_site() -> Site {
990+ let site = site().await;
991+ let tahinli = site
988992 .store
989- .create_user("bob", None, "not-a-real-hash", false)
993+ .create_user("tahinli", None, "not-a-real-hash", false)
990994 .await
991995 .unwrap();
992- let cookie = sign_in(&site.store, &bob.id, "bob-token").await;
993- let (_, other) = get(&site.router, "/tahinli", Some(&cookie)).await;
994- assert!(!other.contains("profile-edit"));
996+ for i in 0..35 {
997+ site.store
998+ .create_repo(
999+ &tahinli.id,
1000+ &format!("bulk-{i:02}"),
1001+ "",
1002+ Visibility::Public,
1003+ "main",
1004+ )
1005+ .await
1006+ .unwrap();
1007+ }
1008+ site
1009+ }
1010+
1011+ async fn user_id(store: &Store, name: &str) -> String {
1012+ store.user_by_username(name).await.unwrap().unwrap().id
9951013 }
9961014
1015+ /// Pagination and the name filter on one 35-repo site.
9971016 #[tokio::test]
998- async fn org_pins_show_on_the_org_profile_with_an_edit_link_for_owners() {
999- let site = seeded().await;
1000- let tahinli = user_id(&site.store, "tahinli").await;
1001- let acme = site.store.create_org("acme", &tahinli).await.unwrap();
1002- let lib = site
1003- .store
1004- .create_repo(&acme.id, "lib", "", Visibility::Public, "main")
1005- .await
1006- .unwrap();
1007- site.store
1008- .set_profile_pins(&acme.id, &[lib.id])
1009- .await
1010- .unwrap();
1017+ async fn repositories_tab_paging_and_name_filter() {
1018+ let site = bulk_site().await;
10111019
1012- let cookie = sign_in(&site.store, &tahinli, "tahinli-token").await;
1013- let (_, owner) = get(&site.router, "/acme", Some(&cookie)).await;
1014- assert!(owner.contains("acme/lib"));
1015- assert!(owner.contains("href=\"/org/acme/settings/pins\""));
1020+ // Thirty repos per page, the rest on page two.
1021+ let (status, first) = get(&site.router, "/tahinli?tab=repositories&sort=name", None).await;
1022+ assert_eq!(status, 200, "paging: first page");
1023+ assert_eq!(
1024+ count(&first, "class=\"repo-name\""),
1025+ 30,
1026+ "paging: first page size"
1027+ );
1028+ assert!(first.contains("page=2"), "paging: next link: {first}");
10161029
1017- let (_, anon) = get(&site.router, "/acme", None).await;
1018- assert!(anon.contains("acme/lib"));
1019- assert!(!anon.contains("Customize pins"));
1030+ let (_, second) = get(
1031+ &site.router,
1032+ "/tahinli?tab=repositories&sort=name&page=2",
1033+ None,
1034+ )
1035+ .await;
1036+ assert_eq!(
1037+ count(&second, "class=\"repo-name\""),
1038+ 5,
1039+ "paging: second page size"
1040+ );
1041+ assert!(
1042+ second.contains("tahinli/bulk-34"),
1043+ "paging: last repo on page two"
1044+ );
1045+ assert!(
1046+ !second.contains("tahinli/bulk-00"),
1047+ "paging: first repo not on page two"
1048+ );
1049+
1050+ // The name filter is a case-insensitive substring match.
1051+ let (_, body) = get(&site.router, "/tahinli?tab=repositories&q=BULK-1", None).await;
1052+ assert_eq!(
1053+ count(&body, "class=\"repo-name\""),
1054+ 10,
1055+ "filter: match count"
1056+ );
1057+ assert!(body.contains("tahinli/bulk-12"), "filter: match");
1058+ assert!(!body.contains("tahinli/bulk-22"), "filter: non-match");
10201059 }
10211060 }
crates/forge-web/src/pages/profile_pins.rsmodified+75 -55
@@ -317,10 +317,24 @@ mod tests {
317317 .collect()
318318 }
319319
320+ /// The owner saves pins and the form reflects them. The bad submissions that follow
321+ /// (too many pins, a wrong CSRF token, a foreign repo, another user) must leave the saved
322+ /// pins alone. The scenarios run in order on one seed, and each reads the state before it.
320323 #[tokio::test]
321- async fn owner_saves_pins_and_is_sent_back_to_the_profile() {
324+ async fn owner_pins_save_and_bad_submissions_leave_them_alone() {
322325 let s = seeded().await;
323- let cookie = sign_in(&s.site.store, &s.tahinli, "tahinli-token").await;
326+ let cookie = sign_in(&s.site.store, &s.tahinli, "pins-owner-token").await;
327+ let carol = s
328+ .site
329+ .store
330+ .user_by_username("carol")
331+ .await
332+ .unwrap()
333+ .unwrap();
334+ let carol_cookie = sign_in(&s.site.store, &carol.id, "pins-carol-token").await;
335+ let saved = ["secret-repo", "open-repo"];
336+
337+ // Saving redirects to the profile and stores the pins in the chosen order.
324338 let reply = send(
325339 &s.site,
326340 "POST",
@@ -329,44 +343,51 @@ mod tests {
329343 &[("csrf", CSRF), ("repo", &s.secret), ("repo", &s.open)],
330344 )
331345 .await;
332- assert_eq!(reply.status, 303);
333- assert_eq!(reply.location.as_deref(), Some("/tahinli"));
346+ assert_eq!(reply.status, 303, "save: redirect");
347+ assert_eq!(
348+ reply.location.as_deref(),
349+ Some("/tahinli"),
350+ "save: location"
351+ );
334352 assert_eq!(
335353 pinned_names(&s.site.store, &s.tahinli).await,
336- ["secret-repo", "open-repo"]
354+ saved,
355+ "save: stored pins"
337356 );
338357
358+ // The form ticks the pinned repos.
339359 let form = send(&s.site, "GET", "/settings/pins", Some(&cookie), &[]).await;
340- assert_eq!(form.status, 200);
341- assert!(form.body.contains("checked"), "pinned repos are ticked");
342- assert!(form.body.contains("tahinli/open-repo"));
343- }
360+ assert_eq!(form.status, 200, "form: status");
361+ assert!(
362+ form.body.contains("checked"),
363+ "form: pinned repos are ticked"
364+ );
365+ assert!(form.body.contains("tahinli/open-repo"), "form: lists repos");
344366
345- #[tokio::test]
346- async fn more_than_six_pins_shows_the_error_and_keeps_the_old_pins() {
347- let s = seeded().await;
348- let cookie = sign_in(&s.site.store, &s.tahinli, "tahinli-token").await;
367+ // Seven pins is one too many: the form is shown again and the saved pins stay.
349368 let repos = s.site.store.list_repos_by_owner(&s.tahinli).await.unwrap();
350369 assert!(repos.len() >= 7, "seed has enough repos");
351370 let ids: Vec<String> = repos.iter().map(|r| r.id.clone()).collect();
352371 let mut fields: Vec<(&str, &str)> = vec![("csrf", CSRF)];
353372 fields.extend(ids.iter().map(|id| ("repo", id.as_str())));
354-
355- let reply = send(&s.site, "POST", "/settings/pins", Some(&cookie), &fields).await;
356- assert_eq!(reply.status, 200, "the form is shown again, not redirected");
373+ let six = send(&s.site, "POST", "/settings/pins", Some(&cookie), &fields).await;
374+ assert_eq!(
375+ six.status, 200,
376+ "six limit: form shown again, not redirected"
377+ );
357378 assert!(
358- reply.body.contains("at most six"),
359- "friendly error: {}",
360- reply.body
379+ six.body.contains("at most six"),
380+ "six limit: friendly error: {}",
381+ six.body
382+ );
383+ assert_eq!(
384+ pinned_names(&s.site.store, &s.tahinli).await,
385+ saved,
386+ "six limit: saved pins kept"
361387 );
362- assert!(pinned_names(&s.site.store, &s.tahinli).await.is_empty());
363- }
364388
365- #[tokio::test]
366- async fn a_missing_csrf_token_is_refused() {
367- let s = seeded().await;
368- let cookie = sign_in(&s.site.store, &s.tahinli, "tahinli-token").await;
369- let reply = send(
389+ // A wrong CSRF token is refused and nothing changes.
390+ let bad_csrf = send(
370391 &s.site,
371392 "POST",
372393 "/settings/pins",
@@ -374,15 +395,15 @@ mod tests {
374395 &[("csrf", "wrong"), ("repo", &s.open)],
375396 )
376397 .await;
377- assert_eq!(reply.status, 403);
378- assert!(pinned_names(&s.site.store, &s.tahinli).await.is_empty());
379- }
398+ assert_eq!(bad_csrf.status, 403, "csrf: refused");
399+ assert_eq!(
400+ pinned_names(&s.site.store, &s.tahinli).await,
401+ saved,
402+ "csrf: saved pins kept"
403+ );
380404
381- #[tokio::test]
382- async fn another_users_repo_cannot_be_pinned() {
383- let s = seeded().await;
384- let cookie = sign_in(&s.site.store, &s.tahinli, "tahinli-token").await;
385- let reply = send(
405+ // A repo owned by someone else cannot be pinned, even alongside the owner's own.
406+ let foreign = send(
386407 &s.site,
387408 "POST",
388409 "/settings/pins",
@@ -390,35 +411,34 @@ mod tests {
390411 &[("csrf", CSRF), ("repo", &s.open), ("repo", &s.carols)],
391412 )
392413 .await;
393- assert_ne!(reply.status, 303, "a foreign repo is refused");
394- assert!(pinned_names(&s.site.store, &s.tahinli).await.is_empty());
395- }
414+ assert_ne!(foreign.status, 303, "foreign repo: refused");
415+ assert_eq!(
416+ pinned_names(&s.site.store, &s.tahinli).await,
417+ saved,
418+ "foreign repo: saved pins kept"
419+ );
396420
397- #[tokio::test]
398- async fn only_the_signed_in_user_edits_their_own_pins() {
399- let s = seeded().await;
400- let carol = s
401- .site
402- .store
403- .user_by_username("carol")
404- .await
405- .unwrap()
406- .unwrap();
407- let cookie = sign_in(&s.site.store, &carol.id, "carol-token").await;
408- // Carol's form lists her own repos; she cannot reach tahinli's pins through it.
409- let reply = send(
421+ // Carol's form cannot touch tahinli's pins; anonymous visitors are sent to log in.
422+ let by_carol = send(
410423 &s.site,
411424 "POST",
412425 "/settings/pins",
413- Some(&cookie),
426+ Some(&carol_cookie),
414427 &[("csrf", CSRF), ("repo", &s.open)],
415428 )
416429 .await;
417- assert_ne!(reply.status, 303);
418- assert!(pinned_names(&s.site.store, &s.tahinli).await.is_empty());
430+ assert_ne!(by_carol.status, 303, "other user: refused");
431+ assert_eq!(
432+ pinned_names(&s.site.store, &s.tahinli).await,
433+ saved,
434+ "other user: saved pins kept"
435+ );
419436 let anon = send(&s.site, "POST", "/settings/pins", None, &[("csrf", CSRF)]).await;
420- assert_eq!(anon.status, 303, "anonymous visitors are sent to log in");
421- assert!(anon.location.unwrap_or_default().starts_with("/login"));
437+ assert_eq!(anon.status, 303, "anonymous: sent to log in");
438+ assert!(
439+ anon.location.unwrap_or_default().starts_with("/login"),
440+ "anonymous: login"
441+ );
422442 }
423443
424444 #[tokio::test]
crates/forge-web/src/pages/settings_appearance.rsmodified+128 -54
@@ -506,32 +506,79 @@ mod tests {
506506 use super::*;
507507
508508 #[test]
509- fn only_offered_choices_pass() {
510- assert!(check_choice(Lang::En, "dark", "tr").is_ok());
511- assert!(check_choice(Lang::Tr, "auto", "auto").is_ok());
512- assert!(check_choice(Lang::En, "neon", "en").is_err());
513- assert!(check_choice(Lang::En, "light", "de").is_err());
514- assert!(check_choice(Lang::Tr, "light", "").is_err());
515- assert!(accent_choice(Lang::En, Some("ocean"), "sage").is_ok());
516- assert!(accent_choice(Lang::En, Some("neon"), "sage").is_err());
517- assert!(accent_choice(Lang::En, Some("Ocean"), "sage").is_err());
518- assert!(accent_choice(Lang::En, Some(""), "sage").is_err());
519- assert!(base_choice(Lang::En, Some("ink"), "fern").is_ok());
520- assert!(base_choice(Lang::En, Some("neon"), "fern").is_err());
521- assert!(base_choice(Lang::En, Some(""), "fern").is_err());
522- }
509+ fn offered_choices_pass_and_others_are_refused() {
510+ assert!(
511+ check_choice(Lang::En, "dark", "tr").is_ok(),
512+ "theme: offered"
513+ );
514+ assert!(
515+ check_choice(Lang::Tr, "auto", "auto").is_ok(),
516+ "theme: auto"
517+ );
518+ assert!(
519+ check_choice(Lang::En, "neon", "en").is_err(),
520+ "theme: unknown"
521+ );
522+ assert!(
523+ check_choice(Lang::En, "light", "de").is_err(),
524+ "language: unknown"
525+ );
526+ assert!(
527+ check_choice(Lang::Tr, "light", "").is_err(),
528+ "language: empty"
529+ );
530+ assert!(
531+ accent_choice(Lang::En, Some("ocean"), "sage").is_ok(),
532+ "accent: offered"
533+ );
534+ assert!(
535+ accent_choice(Lang::En, Some("neon"), "sage").is_err(),
536+ "accent: unknown"
537+ );
538+ assert!(
539+ accent_choice(Lang::En, Some("Ocean"), "sage").is_err(),
540+ "accent: wrong case"
541+ );
542+ assert!(
543+ accent_choice(Lang::En, Some(""), "sage").is_err(),
544+ "accent: empty"
545+ );
546+ assert!(
547+ base_choice(Lang::En, Some("ink"), "fern").is_ok(),
548+ "base: offered"
549+ );
550+ assert!(
551+ base_choice(Lang::En, Some("neon"), "fern").is_err(),
552+ "base: unknown"
553+ );
554+ assert!(
555+ base_choice(Lang::En, Some(""), "fern").is_err(),
556+ "base: empty"
557+ );
523558
524- #[test]
525- fn the_newer_colours_pass_and_their_wrong_cases_do_not() {
526559 for id in [
527560 "sage", "spark", "ocean", "plum", "rose", "gold", "hue-0", "hue-359",
528561 ] {
529- assert_eq!(accent_choice(Lang::En, Some(id), "sage").unwrap(), id);
530- assert!(accent_choice(Lang::Tr, Some(&id.to_uppercase()), "sage").is_err());
562+ assert_eq!(
563+ accent_choice(Lang::En, Some(id), "sage").unwrap(),
564+ id,
565+ "accent {id}"
566+ );
567+ assert!(
568+ accent_choice(Lang::Tr, Some(&id.to_uppercase()), "sage").is_err(),
569+ "accent upper case {id}"
570+ );
531571 }
532572 for id in ["fern", "spark", "graphite", "dusk", "ink", "hue-120"] {
533- assert_eq!(base_choice(Lang::Tr, Some(id), "fern").unwrap(), id);
534- assert!(base_choice(Lang::Tr, Some(&id.to_uppercase()), "fern").is_err());
573+ assert_eq!(
574+ base_choice(Lang::Tr, Some(id), "fern").unwrap(),
575+ id,
576+ "base {id}"
577+ );
578+ assert!(
579+ base_choice(Lang::Tr, Some(&id.to_uppercase()), "fern").is_err(),
580+ "base upper case {id}"
581+ );
535582 }
536583 // Removed presets, and hue values that are out of range or not canonical, are refused.
537584 for id in [
@@ -544,7 +591,10 @@ mod tests {
544591 "hue-",
545592 "hue-+5",
546593 ] {
547- assert!(accent_choice(Lang::En, Some(id), "sage").is_err(), "{id}");
594+ assert!(
595+ accent_choice(Lang::En, Some(id), "sage").is_err(),
596+ "accent refused {id}"
597+ );
548598 }
549599 for id in [
550600 "dune",
@@ -555,14 +605,23 @@ mod tests {
555605 "hue-360",
556606 "hue-07",
557607 ] {
558- assert!(base_choice(Lang::En, Some(id), "fern").is_err(), "{id}");
608+ assert!(
609+ base_choice(Lang::En, Some(id), "fern").is_err(),
610+ "base refused {id}"
611+ );
559612 }
560- }
561613
562- #[test]
563- fn an_absent_colour_keeps_the_stored_value() {
564- assert_eq!(accent_choice(Lang::En, None, "plum").unwrap(), "plum");
565- assert_eq!(base_choice(Lang::En, None, "mist").unwrap(), "mist");
614+ // An absent colour keeps the stored value.
615+ assert_eq!(
616+ accent_choice(Lang::En, None, "plum").unwrap(),
617+ "plum",
618+ "accent: absent"
619+ );
620+ assert_eq!(
621+ base_choice(Lang::En, None, "mist").unwrap(),
622+ "mist",
623+ "base: absent"
624+ );
566625 }
567626
568627 #[test]
@@ -576,15 +635,17 @@ mod tests {
576635 assert!(base_err.to_string().contains("background"), "{base_err}");
577636 }
578637
638+ /// The colour groups mark the stored theme, accent and base as selected. A custom hue
639+ /// fills its stripe and checks no preset; a preset moves the knob to its own hue.
579640 #[test]
580- fn the_stored_theme_accent_and_base_are_selected() {
641+ fn stored_colours_are_selected_and_hues_drive_the_stripes() {
581642 let options = choices(THEME_CODES, "dark", |code| theme_label(Lang::En, code));
582643 let selected: Vec<&str> = options
583644 .iter()
584645 .filter(|c| c.selected)
585646 .map(|c| c.value)
586647 .collect();
587- assert_eq!(selected, ["dark"], "theme");
648+ assert_eq!(selected, ["dark"], "theme: selected");
588649
589650 let codes: Vec<&'static str> = accent::ids().collect();
590651 let options = choices(&codes, "plum", |id| accent_name(Lang::En, id));
@@ -593,8 +654,12 @@ mod tests {
593654 .filter(|c| c.selected)
594655 .map(|c| c.value)
595656 .collect();
596- assert_eq!(selected, ["plum"]);
597- assert_eq!(options[0].value, crate::accent_palette::DEFAULT);
657+ assert_eq!(selected, ["plum"], "accent: selected");
658+ assert_eq!(
659+ options[0].value,
660+ crate::accent_palette::DEFAULT,
661+ "accent: default first"
662+ );
598663
599664 let group = colour_group(Lang::En, true, "ink", "plum");
600665 let bases: Vec<&str> = group
@@ -603,36 +668,45 @@ mod tests {
603668 .filter(|c| c.selected)
604669 .map(|c| c.value)
605670 .collect();
606- assert_eq!(bases, ["ink"]);
607- assert_eq!(group.bases[0].value, crate::accent_palette::BASE_DEFAULT);
608- }
671+ assert_eq!(bases, ["ink"], "base: selected");
672+ assert_eq!(
673+ group.bases[0].value,
674+ crate::accent_palette::BASE_DEFAULT,
675+ "base: default first"
676+ );
609677
610- #[test]
611- fn a_stored_hue_checks_custom_and_a_stored_preset_moves_the_knob() {
678+ // A custom hue fills the stripe and checks no preset.
612679 let group = colour_group(Lang::En, false, "hue-200", "hue-40");
613- assert!(group.base_stripe.custom);
614- assert_eq!(group.base_stripe.hue, 200);
615- assert!(group.accent_stripe.custom);
616- assert_eq!(group.accent_stripe.hue, 40);
617- assert!(group.bases.iter().all(|c| !c.selected));
618- assert!(group.accents.iter().all(|c| !c.selected));
680+ assert!(group.base_stripe.custom, "custom base hue");
681+ assert_eq!(group.base_stripe.hue, 200, "custom base hue value");
682+ assert!(group.accent_stripe.custom, "custom accent hue");
683+ assert_eq!(group.accent_stripe.hue, 40, "custom accent hue value");
684+ assert!(
685+ group.bases.iter().all(|c| !c.selected),
686+ "custom hue: no base preset checked"
687+ );
688+ assert!(
689+ group.accents.iter().all(|c| !c.selected),
690+ "custom hue: no accent preset checked"
691+ );
619692
693+ // A preset moves the knob to its own hue.
620694 let group = colour_group(Lang::En, true, "ink", "plum");
621695 let plum_hue = preset_accent_hue("plum").unwrap();
622696 let ink_hue = preset_base_hue("ink").unwrap();
623- assert!(!group.accent_stripe.custom);
624- assert_eq!(group.accent_stripe.hue, plum_hue);
625- assert!(!group.base_stripe.custom);
626- assert_eq!(group.base_stripe.hue, ink_hue);
697+ assert!(!group.accent_stripe.custom, "preset accent: not custom");
698+ assert_eq!(group.accent_stripe.hue, plum_hue, "preset accent: knob hue");
699+ assert!(!group.base_stripe.custom, "preset base: not custom");
700+ assert_eq!(group.base_stripe.hue, ink_hue, "preset base: knob hue");
627701 let plum = group.accents.iter().find(|c| c.value == "plum").unwrap();
628- assert!(plum.selected);
629- assert_eq!(plum.hue, plum_hue.to_string());
630-
631- assert_eq!(hue_of("hue-359"), Some(359));
632- assert_eq!(hue_of("hue-360"), None);
633- assert_eq!(hue_of("hue-"), None);
634- assert_eq!(hue_of("hue-+5"), None);
635- assert_eq!(hue_of("sage"), None);
702+ assert!(plum.selected, "preset accent: checked");
703+ assert_eq!(plum.hue, plum_hue.to_string(), "preset accent: hue value");
704+
705+ assert_eq!(hue_of("hue-359"), Some(359), "hue: max");
706+ assert_eq!(hue_of("hue-360"), None, "hue: out of range");
707+ assert_eq!(hue_of("hue-"), None, "hue: empty");
708+ assert_eq!(hue_of("hue-+5"), None, "hue: sign");
709+ assert_eq!(hue_of("sage"), None, "hue: preset id");
636710 }
637711
638712 #[test]
crates/forge-web/src/pages/settings_live.rsmodified+69 -48
@@ -179,20 +179,10 @@ mod tests {
179179
180180 const CSRF: &str = "settings-live-csrf";
181181
182+ /// The settings stream needs a session, and the settings pages name it (and not the old
183+ /// theme stream).
182184 #[tokio::test]
183- async fn the_stream_needs_a_session() {
184- let dir = tempfile::tempdir().expect("tempdir");
185- let router = app_router(test_state(dir.path()).await);
186- let request = Request::builder()
187- .method("GET")
188- .uri("/settings/events")
189- .body(Body::empty())
190- .expect("request");
191- assert_eq!(router.handle(request).await.status().as_u16(), 401);
192- }
193-
194- #[tokio::test]
195- async fn the_settings_sidebar_names_the_settings_stream() {
185+ async fn the_settings_stream_needs_a_session_and_the_sidebar_names_it() {
196186 let dir = tempfile::tempdir().expect("tempdir");
197187 let state = test_state(dir.path()).await;
198188 let store = state.store.clone();
@@ -203,6 +193,17 @@ mod tests {
203193 create_session(&store, &owner.id, "owner-token", CSRF).await;
204194 let router = app_router(state);
205195
196+ let request = Request::builder()
197+ .method("GET")
198+ .uri("/settings/events")
199+ .body(Body::empty())
200+ .expect("request");
201+ assert_eq!(
202+ router.handle(request).await.status().as_u16(),
203+ 401,
204+ "signed out: stream refused"
205+ );
206+
206207 let page = Request::builder()
207208 .method("GET")
208209 .uri("/settings/profile")
@@ -213,8 +214,14 @@ mod tests {
213214 let html =
214215 String::from_utf8_lossy(&to_bytes(res.into_body(), usize::MAX).await.expect("body"))
215216 .into_owned();
216- assert!(html.contains("data-live=\"/settings/events\""));
217- assert!(!html.contains("/settings/theme/events"));
217+ assert!(
218+ html.contains("data-live=\"/settings/events\""),
219+ "sidebar names the stream"
220+ );
221+ assert!(
222+ !html.contains("/settings/theme/events"),
223+ "old theme stream is gone"
224+ );
218225 }
219226
220227 #[tokio::test]
@@ -247,12 +254,22 @@ mod tests {
247254 let res = router.handle(request).await;
248255 to_bytes(res.into_body(), usize::MAX).await.expect("body");
249256
250- assert!(owner_wake.has_changed().expect("open"));
251- assert!(!other_wake.has_changed().expect("open"));
257+ assert!(
258+ owner_wake.has_changed().expect("open"),
259+ "owner's topic woken"
260+ );
261+ assert!(
262+ !other_wake.has_changed().expect("open"),
263+ "other user's topic untouched"
264+ );
252265 }
253266
267+ /// Two live streams on one app. The settings stream sends one changed event per write to
268+ /// the account. The alive stream sends the appearance only when it changes: a bump that
269+ /// changes nothing sends nothing, and a theme and language change sends the theme event
270+ /// first, then the language event.
254271 #[tokio::test]
255- async fn the_settings_stream_sends_a_changed_event_per_write() {
272+ async fn the_settings_stream_sends_changes_and_the_alive_stream_sends_appearance() {
256273 let dir = tempfile::tempdir().expect("tempdir");
257274 let state = test_state(dir.path()).await;
258275 let store = state.store.clone();
@@ -262,8 +279,13 @@ mod tests {
262279 .await
263280 .expect("user");
264281 create_session(&store, &owner.id, "owner-token", CSRF).await;
282+ store
283+ .set_ui_prefs(&owner.id, "light", "en")
284+ .await
285+ .expect("prefs");
265286 let router = app_router(state);
266287
288+ // Settings stream: a retry hint first, then one changed event per write.
267289 let request = Request::builder()
268290 .method("GET")
269291 .uri("/settings/events")
@@ -271,33 +293,23 @@ mod tests {
271293 .body(Body::empty())
272294 .expect("request");
273295 let res = router.handle(request).await;
274- assert_eq!(res.status().as_u16(), 200);
296+ assert_eq!(res.status().as_u16(), 200, "settings stream: status");
275297 let mut frames = res.into_body().into_data_stream();
276298 let retry = frames.next().await.expect("a frame").expect("data");
277- assert!(retry.starts_with(b"retry: 1000"), "{retry:?}");
299+ assert!(
300+ retry.starts_with(b"retry: 1000"),
301+ "settings stream: {retry:?}"
302+ );
278303
279304 live.bump(&Topic::Account(owner.id.clone()));
280305 let changed = frames.next().await.expect("a frame").expect("data");
281- assert_eq!(&changed[..], b"event: changed\ndata: 1\n\n");
282- }
283-
284- #[tokio::test]
285- async fn the_alive_stream_sends_the_appearance_only_when_it_changes() {
286- let dir = tempfile::tempdir().expect("tempdir");
287- let state = test_state(dir.path()).await;
288- let store = state.store.clone();
289- let live = state.live.clone();
290- let owner = store
291- .create_user("tahinli", None, "h", false)
292- .await
293- .expect("user");
294- create_session(&store, &owner.id, "owner-token", CSRF).await;
295- store
296- .set_ui_prefs(&owner.id, "light", "en")
297- .await
298- .expect("prefs");
299- let router = app_router(state);
306+ assert_eq!(
307+ &changed[..],
308+ b"event: changed\ndata: 1\n\n",
309+ "settings stream: changed event"
310+ );
300311
312+ // Alive stream: no event for a bump that changes no appearance.
301313 let request = Request::builder()
302314 .method("GET")
303315 .uri("/-/alive")
@@ -305,11 +317,10 @@ mod tests {
305317 .body(Body::empty())
306318 .expect("request");
307319 let res = router.handle(request).await;
308- let mut frames = res.into_body().into_data_stream();
309- let retry = frames.next().await.expect("a frame").expect("data");
310- assert!(retry.starts_with(b"retry: 1000"), "{retry:?}");
320+ let mut alive = res.into_body().into_data_stream();
321+ let retry = alive.next().await.expect("a frame").expect("data");
322+ assert!(retry.starts_with(b"retry: 1000"), "alive stream: {retry:?}");
311323
312- // A bump that changes no appearance sends nothing; the next change is the theme event.
313324 live.bump(&Topic::Account(owner.id.clone()));
314325 // One change of theme and language: the theme event first, then the language event.
315326 store
@@ -317,11 +328,21 @@ mod tests {
317328 .await
318329 .expect("prefs");
319330 live.bump(&Topic::Account(owner.id.clone()));
320- let event = frames.next().await.expect("a frame").expect("data");
331+ let event = alive.next().await.expect("a frame").expect("data");
321332 let text = String::from_utf8_lossy(&event).into_owned();
322- assert!(text.starts_with("event: theme\n"), "{text}");
323- assert!(text.contains("data-theme=dark;"), "{text}");
324- let language = frames.next().await.expect("a frame").expect("data");
325- assert_eq!(&language[..], b"event: language\ndata: 1\n\n");
333+ assert!(
334+ text.starts_with("event: theme\n"),
335+ "alive stream: theme first {text}"
336+ );
337+ assert!(
338+ text.contains("data-theme=dark;"),
339+ "alive stream: theme value {text}"
340+ );
341+ let language = alive.next().await.expect("a frame").expect("data");
342+ assert_eq!(
343+ &language[..],
344+ b"event: language\ndata: 1\n\n",
345+ "alive stream: language event"
346+ );
326347 }
327348 }
crates/forge-web/src/pages/settings_notifications.rsmodified+22 -23
@@ -288,17 +288,18 @@ mod tests {
288288 .email_notifications
289289 }
290290
291+ /// The page needs a session, and once signed in it shows the box and its notes. The
292+ /// box saves itself but is locked, because this test server sends no email.
291293 #[tokio::test]
292- async fn the_page_needs_a_session() {
294+ async fn the_page_needs_a_session_then_shows_the_checkbox_and_notes() {
293295 let fx = fixture().await;
294296 let (status, body) = send(&fx.router, "GET", "/settings/notifications", None, None).await;
295- assert_ne!(status, 200, "{body}");
296- assert!(!body.contains("Email me about notifications"));
297- }
297+ assert_ne!(status, 200, "signed out: {body}");
298+ assert!(
299+ !body.contains("Email me about notifications"),
300+ "signed out: no box"
301+ );
298302
299- #[tokio::test]
300- async fn the_page_shows_the_checkbox_and_the_notes() {
301- let fx = fixture().await;
302303 let (status, body) = send(
303304 &fx.router,
304305 "GET",
@@ -324,48 +325,46 @@ mod tests {
324325 );
325326 }
326327
328+ /// The flag starts on. A wrong CSRF token changes nothing; a valid form turns it off and
329+ /// back on. The scenarios run in order on one fixture.
327330 #[tokio::test]
328- async fn the_checkbox_toggles_the_flag() {
331+ async fn the_checkbox_toggles_the_flag_and_a_wrong_csrf_token_changes_nothing() {
329332 let fx = fixture().await;
330333 assert!(flag(&fx).await, "on by default");
331334
332- let off = format!("csrf={CSRF}");
333335 let (status, _) = send(
334336 &fx.router,
335337 "POST",
336338 "/settings/notifications",
337339 Some(TOKEN),
338- Some(off),
340+ Some("csrf=wrong".to_owned()),
339341 )
340342 .await;
341- assert_eq!(status, 303);
342- assert!(!flag(&fx).await, "an unchecked box turns it off");
343+ assert_ne!(status, 303, "wrong csrf: refused");
344+ assert!(flag(&fx).await, "wrong csrf: still on");
343345
344- let on = format!("csrf={CSRF}&email_notifications=1");
346+ let off = format!("csrf={CSRF}");
345347 let (status, _) = send(
346348 &fx.router,
347349 "POST",
348350 "/settings/notifications",
349351 Some(TOKEN),
350- Some(on),
352+ Some(off),
351353 )
352354 .await;
353- assert_eq!(status, 303);
354- assert!(flag(&fx).await);
355- }
355+ assert_eq!(status, 303, "unchecked: status");
356+ assert!(!flag(&fx).await, "an unchecked box turns it off");
356357
357- #[tokio::test]
358- async fn a_wrong_csrf_token_changes_nothing() {
359- let fx = fixture().await;
358+ let on = format!("csrf={CSRF}&email_notifications=1");
360359 let (status, _) = send(
361360 &fx.router,
362361 "POST",
363362 "/settings/notifications",
364363 Some(TOKEN),
365- Some("csrf=wrong".to_owned()),
364+ Some(on),
366365 )
367366 .await;
368- assert_ne!(status, 303);
369- assert!(flag(&fx).await, "still on");
367+ assert_eq!(status, 303, "checked: status");
368+ assert!(flag(&fx).await, "a checked box turns it on");
370369 }
371370 }
crates/forge-web/src/pages/settings_profile.rsmodified+217 -162
@@ -608,170 +608,159 @@ pub(crate) mod tests {
608608 .await
609609 }
610610
611+ /// The profile fields the form can change, read back from the store.
612+ async fn saved_fields(fx: &Fixture) -> (String, String, String, Option<String>) {
613+ let user = fx.store.user_by_id(&fx.user.id).await.unwrap().unwrap();
614+ (user.username, user.about, user.timezone, user.display_name)
615+ }
616+
617+ /// The profile form: round trips, the saved flash, and every rejection leaves the stored
618+ /// fields alone. The scenarios run in order on one fixture, and each rejection compares
619+ /// against the fields the step before it left behind.
611620 #[tokio::test]
612- async fn one_save_changes_capitalization_about_and_timezone() {
621+ async fn profile_form_saves_and_rejects_bad_input() {
613622 let fx = fixture().await;
623+
624+ // About and timezone round-trip through the form and show on the page.
614625 let form =
615- format!("csrf={CSRF}&username=Tahinli&about=Hello+*world*&timezone=Europe%2FIstanbul");
626+ format!("csrf={CSRF}&username=tahinli&about=Hello+*world*&timezone=Europe%2FIstanbul");
616627 let (status, location, _) =
617628 send(&fx.router, "POST", "/settings/profile", true, Some(&form)).await;
618- assert_eq!(status, 303);
619- assert_eq!(location.as_deref(), Some("/settings/profile?saved=1"));
620-
621- let stored = fx.store.user_by_id(&fx.user.id).await.unwrap().unwrap();
622- assert_eq!(stored.username, "Tahinli");
623- assert_eq!(stored.about, "Hello *world*");
624- assert_eq!(stored.timezone, "Europe/Istanbul");
629+ assert_eq!(status, 303, "round trip: status");
630+ assert_eq!(
631+ location.as_deref(),
632+ Some("/settings/profile?saved=1"),
633+ "round trip: location"
634+ );
635+ let got = saved_fields(&fx).await;
636+ assert_eq!(got.0, "tahinli", "round trip: username");
637+ assert_eq!(got.1, "Hello *world*", "round trip: about");
638+ assert_eq!(got.2, "Europe/Istanbul", "round trip: timezone");
639+ let (status, _, body) = send(&fx.router, "GET", "/settings/profile", true, None).await;
640+ assert_eq!(status, 200, "round trip: page");
641+ assert!(
642+ body.contains("Hello *world*"),
643+ "round trip: about shown {body}"
644+ );
645+ assert!(
646+ body.contains(r#"value="Europe/Istanbul" selected"#),
647+ "round trip: timezone shown {body}"
648+ );
625649
650+ // A capitalization-only change is saved, shows in the nav and gets the saved flash.
651+ let form =
652+ format!("csrf={CSRF}&username=Tahinli&about=Hello+*world*&timezone=Europe%2FIstanbul");
653+ let (status, location, _) =
654+ send(&fx.router, "POST", "/settings/profile", true, Some(&form)).await;
655+ assert_eq!(status, 303, "capitalization: status");
656+ assert_eq!(
657+ location.as_deref(),
658+ Some("/settings/profile?saved=1"),
659+ "capitalization: location"
660+ );
661+ assert_eq!(
662+ saved_fields(&fx).await.0,
663+ "Tahinli",
664+ "capitalization: stored"
665+ );
626666 let (status, _, body) = send(&fx.router, "GET", "/", true, None).await;
627- assert_eq!(status, 200);
628- assert!(body.contains("<summary aria-label=\"Tahinli\">"), "{body}");
629-
667+ assert_eq!(status, 200, "capitalization: nav");
668+ assert!(
669+ body.contains("<summary aria-label=\"Tahinli\">"),
670+ "capitalization: nav {body}"
671+ );
630672 let (status, _, body) =
631673 send(&fx.router, "GET", "/settings/profile?saved=1", true, None).await;
632- assert_eq!(status, 200);
633- assert!(body.contains("Profile saved."), "{body}");
634- }
674+ assert_eq!(status, 200, "capitalization: flash page");
675+ assert!(
676+ body.contains("Profile saved."),
677+ "capitalization: flash {body}"
678+ );
635679
636- #[tokio::test]
637- async fn a_different_name_is_rejected_and_nothing_is_saved() {
638- let fx = fixture().await;
680+ // A different name is rejected and nothing is saved.
681+ let before = saved_fields(&fx).await;
639682 let form = format!("csrf={CSRF}&username=other&about=kept&timezone=UTC");
640683 let (status, _, body) =
641684 send(&fx.router, "POST", "/settings/profile", true, Some(&form)).await;
642- assert_eq!(status, 200);
685+ assert_eq!(status, 200, "different name: status");
643686 assert!(
644687 body.contains("Only the capitalization can be changed."),
645- "{body}"
688+ "different name: {body}"
646689 );
647- let stored = fx.store.user_by_id(&fx.user.id).await.unwrap().unwrap();
648- assert_eq!(stored.username, "tahinli");
649- assert_eq!(stored.about, "");
650- }
651-
652- #[tokio::test]
653- async fn post_without_a_valid_csrf_token_is_rejected() {
654- let fx = fixture().await;
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- }
668- let stored = fx.store.user_by_id(&fx.user.id).await.unwrap().unwrap();
669- assert_eq!(stored.username, "tahinli");
670- assert_eq!(stored.about, "");
671- }
672-
673- #[tokio::test]
674- async fn anonymous_requests_are_sent_to_login() {
675- let fx = fixture().await;
676- let (status, location, _) = send(&fx.router, "GET", "/settings/profile", false, None).await;
677- assert_eq!(status, 303);
678- assert!(location.unwrap_or_default().starts_with("/login?next="));
679-
680- let form = format!("csrf={CSRF}&username=Tahinli");
681- let (status, location, _) =
682- send(&fx.router, "POST", "/settings/profile", false, Some(&form)).await;
683- assert_eq!(status, 303);
684- assert!(location.unwrap_or_default().starts_with("/login?next="));
685- let stored = fx.store.user_by_id(&fx.user.id).await.unwrap().unwrap();
686- assert_eq!(stored.username, "tahinli");
687- }
688-
689- #[tokio::test]
690- async fn about_and_timezone_round_trip() {
691- let fx = fixture().await;
692- let form =
693- format!("csrf={CSRF}&username=tahinli&about=Hello+*world*&timezone=Europe%2FIstanbul");
694- let (status, location, _) =
695- send(&fx.router, "POST", "/settings/profile", true, Some(&form)).await;
696- assert_eq!(status, 303);
697- assert_eq!(location.as_deref(), Some("/settings/profile?saved=1"));
698-
699- let stored = fx.store.user_by_id(&fx.user.id).await.unwrap().unwrap();
700- assert_eq!(stored.username, "tahinli");
701- assert_eq!(stored.about, "Hello *world*");
702- assert_eq!(stored.timezone, "Europe/Istanbul");
703-
704- let (status, _, body) = send(&fx.router, "GET", "/settings/profile", true, None).await;
705- assert_eq!(status, 200);
706- assert!(body.contains("Hello *world*"), "{body}");
707- assert!(
708- body.contains(r#"value="Europe/Istanbul" selected"#),
709- "{body}"
690+ assert_eq!(
691+ saved_fields(&fx).await,
692+ before,
693+ "different name: nothing saved"
710694 );
711- }
712695
713- #[tokio::test]
714- async fn a_bad_timezone_is_rejected_and_nothing_is_saved() {
715- let fx = fixture().await;
696+ // A bad timezone is rejected and nothing is saved.
697+ let before = saved_fields(&fx).await;
716698 let form = format!("csrf={CSRF}&username=Tahinli&about=kept&timezone=Mars%2FOlympus");
717699 let (status, location, body) =
718700 send(&fx.router, "POST", "/settings/profile", true, Some(&form)).await;
719- assert_eq!(status, 200);
720- assert!(location.is_none());
721- assert!(body.contains(r#"role="alert""#), "{body}");
722- // The valid username and about text wait for the timezone to be fixed too.
723- let stored = fx.store.user_by_id(&fx.user.id).await.unwrap().unwrap();
724- assert_eq!(stored.username, "tahinli");
725- assert_eq!(stored.timezone, "UTC");
726- assert_eq!(stored.about, "");
727- }
701+ assert_eq!(status, 200, "bad timezone: status");
702+ assert!(location.is_none(), "bad timezone: no redirect");
703+ assert!(
704+ body.contains(r#"role="alert""#),
705+ "bad timezone: alert {body}"
706+ );
707+ assert_eq!(
708+ saved_fields(&fx).await,
709+ before,
710+ "bad timezone: nothing saved"
711+ );
728712
729- #[tokio::test]
730- async fn display_name_saves_shows_in_the_field_and_blank_clears_it() {
731- let fx = fixture().await;
713+ // A display name saves, shows in the field, and a blank one clears it.
732714 let form = format!(
733715 "csrf={CSRF}&display_name=+Ahmet+Kaan+G%C3%BCm%C3%BC%C5%9F+&username=tahinli&about=&timezone=UTC"
734716 );
735717 let (status, location, _) =
736718 send(&fx.router, "POST", "/settings/profile", true, Some(&form)).await;
737- assert_eq!(status, 303);
738- assert_eq!(location.as_deref(), Some("/settings/profile?saved=1"));
739- let stored = fx.store.user_by_id(&fx.user.id).await.unwrap().unwrap();
740- assert_eq!(stored.display_name.as_deref(), Some("Ahmet Kaan Gümüş"));
741-
719+ assert_eq!(status, 303, "display name: status");
720+ assert_eq!(
721+ location.as_deref(),
722+ Some("/settings/profile?saved=1"),
723+ "display name: location"
724+ );
725+ assert_eq!(
726+ saved_fields(&fx).await.3.as_deref(),
727+ Some("Ahmet Kaan Gümüş"),
728+ "display name: stored"
729+ );
742730 let (status, _, body) = send(&fx.router, "GET", "/settings/profile", true, None).await;
743- assert_eq!(status, 200);
731+ assert_eq!(status, 200, "display name: page");
744732 assert!(
745733 body.contains(r#"name="display_name""#) && body.contains("Ahmet Kaan Gümüş"),
746- "{body}"
734+ "display name: field shows it {body}"
747735 );
748-
749736 let blank = format!("csrf={CSRF}&display_name=+++&username=tahinli&about=&timezone=UTC");
750737 let (status, _, _) =
751738 send(&fx.router, "POST", "/settings/profile", true, Some(&blank)).await;
752- assert_eq!(status, 303);
753- let stored = fx.store.user_by_id(&fx.user.id).await.unwrap().unwrap();
754- assert_eq!(stored.display_name, None);
755- }
739+ assert_eq!(status, 303, "blank display name: status");
740+ assert_eq!(
741+ saved_fields(&fx).await.3,
742+ None,
743+ "blank display name: cleared"
744+ );
756745
757- #[tokio::test]
758- async fn a_bad_display_name_is_rejected_and_nothing_is_saved() {
759- let fx = fixture().await;
746+ // A name that is too long, or has a line break, is rejected and nothing is saved.
747+ let before = saved_fields(&fx).await;
760748 let long = "x".repeat(81);
761749 let form =
762750 format!("csrf={CSRF}&display_name={long}&username=tahinli&about=kept&timezone=UTC");
763751 let (status, location, body) =
764752 send(&fx.router, "POST", "/settings/profile", true, Some(&form)).await;
765- assert_eq!(status, 200);
766- assert!(location.is_none());
753+ assert_eq!(status, 200, "long display name: status");
754+ assert!(location.is_none(), "long display name: no redirect");
767755 assert!(
768756 body.contains("The name must be at most 80 characters."),
769- "{body}"
757+ "long display name: {body}"
758+ );
759+ assert_eq!(
760+ saved_fields(&fx).await,
761+ before,
762+ "long display name: nothing saved"
770763 );
771- // A bad name holds back the valid "about" text too.
772- let stored = fx.store.user_by_id(&fx.user.id).await.unwrap().unwrap();
773- assert_eq!(stored.display_name, None);
774- assert_eq!(stored.about, "");
775764
776765 let control =
777766 format!("csrf={CSRF}&display_name=two%0Alines&username=tahinli&about=&timezone=UTC");
@@ -783,17 +772,55 @@ pub(crate) mod tests {
783772 Some(&control),
784773 )
785774 .await;
786- assert_eq!(status, 200);
775+ assert_eq!(status, 200, "line break: status");
787776 assert!(
788777 body.contains("The name must not contain line breaks or control characters."),
789- "{body}"
778+ "line break: {body}"
779+ );
780+ assert_eq!(saved_fields(&fx).await, before, "line break: nothing saved");
781+
782+ // A missing or forged CSRF token is refused.
783+ let cases = [
784+ ("forged", "csrf=wrong&username=Tahinli&about=&timezone=UTC"),
785+ ("missing", "username=Tahinli&about=&timezone=UTC"),
786+ (
787+ "missing with about",
788+ "username=Tahinli&about=x&timezone=UTC",
789+ ),
790+ ];
791+ for (name, form) in cases {
792+ let (status, _, _) =
793+ send(&fx.router, "POST", "/settings/profile", true, Some(form)).await;
794+ assert_eq!(status, 403, "csrf case {name}");
795+ }
796+ assert_eq!(saved_fields(&fx).await, before, "csrf: nothing saved");
797+
798+ // Anonymous requests are sent to log in and change nothing.
799+ let (status, location, _) = send(&fx.router, "GET", "/settings/profile", false, None).await;
800+ assert_eq!(status, 303, "anonymous GET: status");
801+ assert!(
802+ location.unwrap_or_default().starts_with("/login?next="),
803+ "anonymous GET: login"
804+ );
805+ let form = format!("csrf={CSRF}&username=Tahinli");
806+ let (status, location, _) =
807+ send(&fx.router, "POST", "/settings/profile", false, Some(&form)).await;
808+ assert_eq!(status, 303, "anonymous POST: status");
809+ assert!(
810+ location.unwrap_or_default().starts_with("/login?next="),
811+ "anonymous POST: login"
790812 );
813+ assert_eq!(saved_fields(&fx).await, before, "anonymous: nothing saved");
791814 }
792815
816+ /// Avatars: a missing token and an SVG are rejected, then a PNG is uploaded, served,
817+ /// shown and removed. The scenarios run in order on one fixture.
793818 #[tokio::test]
794- async fn avatar_writes_without_csrf_are_rejected() {
819+ async fn avatar_rejections_then_upload_and_removal() {
795820 let fx = fixture().await;
796821 let png = png_bytes();
822+
823+ // Uploads and removals without a CSRF token are refused.
797824 let (content_type, body) = multipart(&[("avatar", Some(("a.png", "image/png")), &png[..])]);
798825 let reply = send_full(
799826 &fx.router,
@@ -804,8 +831,11 @@ pub(crate) mod tests {
804831 body,
805832 )
806833 .await;
807- assert_eq!(reply.status, 403, "upload");
808- assert!(fx.store.avatar_hash(&fx.user.id).await.unwrap().is_none());
834+ assert_eq!(reply.status, 403, "no csrf: upload");
835+ assert!(
836+ fx.store.avatar_hash(&fx.user.id).await.unwrap().is_none(),
837+ "no csrf: nothing stored"
838+ );
809839
810840 let (status, _, _) = send(
811841 &fx.router,
@@ -815,12 +845,9 @@ pub(crate) mod tests {
815845 Some("csrf=nope"),
816846 )
817847 .await;
818- assert_eq!(status, 403, "remove");
819- }
848+ assert_eq!(status, 403, "no csrf: remove");
820849
821- #[tokio::test]
822- async fn svg_upload_is_rejected_and_nothing_is_stored() {
823- let fx = fixture().await;
850+ // An SVG upload is rejected and nothing is stored.
824851 let svg = br#"<svg xmlns="http://www.w3.org/2000/svg"><script>alert(1)</script></svg>"#;
825852 let (content_type, body) = multipart(&[
826853 ("csrf", None, CSRF.as_bytes()),
@@ -835,34 +862,36 @@ pub(crate) mod tests {
835862 body,
836863 )
837864 .await;
838- assert_eq!(reply.status, 200);
839- assert!(reply.text().contains(r#"role="alert""#));
840- assert!(fx.store.avatar_hash(&fx.user.id).await.unwrap().is_none());
841- }
842-
843- #[tokio::test]
844- async fn avatar_upload_then_remove_is_served_correctly() {
845- let fx = fixture().await;
846- let png = png_bytes();
865+ assert_eq!(reply.status, 200, "svg: status");
866+ assert!(reply.text().contains(r#"role="alert""#), "svg: alert");
867+ assert!(
868+ fx.store.avatar_hash(&fx.user.id).await.unwrap().is_none(),
869+ "svg: nothing stored"
870+ );
847871
872+ // A PNG upload is stored, shown and served with its hash as the version.
848873 let reply = upload_avatar(&fx.router, CSRF, &png).await;
849- assert_eq!(reply.status, 303);
874+ assert_eq!(reply.status, 303, "upload: status");
850875 assert_eq!(
851876 reply.header("location").as_deref(),
852- Some("/settings/profile?saved=avatar")
877+ Some("/settings/profile?saved=avatar"),
878+ "upload: location"
853879 );
854880 let stored_hash = fx.store.avatar_hash(&fx.user.id).await.unwrap().unwrap();
855- assert_eq!(stored_hash.len(), 16);
881+ assert_eq!(stored_hash.len(), 16, "upload: hash length");
856882
857883 // The page shows the new avatar with the hash as its version.
858884 let (_, _, body) = send(&fx.router, "GET", "/settings/profile", true, None).await;
859- assert!(body.contains(&format!("?v={stored_hash}")), "{body}");
860- assert!(body.contains("Remove photo"), "{body}");
885+ assert!(
886+ body.contains(&format!("?v={stored_hash}")),
887+ "page: version {body}"
888+ );
889+ assert!(body.contains("Remove photo"), "page: remove item {body}");
861890
862891 // The top-nav avatar uses the real hash too, not the default URL.
863892 let (_, _, body) = send(&fx.router, "GET", "/", true, None).await;
864893 let nav_src = format!(r#"src="/avatars/tahinli?v={stored_hash}""#);
865- assert!(body.contains(&nav_src), "{body}");
894+ assert!(body.contains(&nav_src), "nav: avatar url {body}");
866895
867896 // Served as a stored PNG with a hash ETag, and 304 on a match.
868897 let served = send_full(
@@ -874,26 +903,39 @@ pub(crate) mod tests {
874903 Vec::new(),
875904 )
876905 .await;
877- assert_eq!(served.status, 200);
878- assert_eq!(served.header("content-type").as_deref(), Some("image/png"));
879- assert_eq!(served.header("etag"), Some(format!("\"{stored_hash}\"")));
906+ assert_eq!(served.status, 200, "served: status");
907+ assert_eq!(
908+ served.header("content-type").as_deref(),
909+ Some("image/png"),
910+ "served: type"
911+ );
912+ assert_eq!(
913+ served.header("etag"),
914+ Some(format!("\"{stored_hash}\"")),
915+ "served: etag"
916+ );
880917 assert_eq!(
881918 served.header("x-content-type-options").as_deref(),
882- Some("nosniff")
919+ Some("nosniff"),
920+ "served: nosniff"
921+ );
922+ assert!(
923+ served.body.starts_with(&[0x89, b'P', b'N', b'G']),
924+ "served: png bytes"
883925 );
884- assert!(served.body.starts_with(&[0x89, b'P', b'N', b'G']));
885926
886927 let uri = format!("/avatars/tahinli?v={stored_hash}");
887928 let immutable = send_full(&fx.router, "GET", &uri, false, None, Vec::new()).await;
888929 assert_eq!(
889930 immutable.header("cache-control").as_deref(),
890- Some("public, max-age=31536000, immutable")
931+ Some("public, max-age=31536000, immutable"),
932+ "versioned: cache-control"
891933 );
892934 let etag = format!("\"{stored_hash}\"");
893935 let mut request = Request::builder().method("GET").uri(&uri);
894936 request = request.header("if-none-match", etag.as_str());
895937 let not_modified = fx.router.handle(request.body(Body::empty()).unwrap()).await;
896- assert_eq!(not_modified.status().as_u16(), 304);
938+ assert_eq!(not_modified.status().as_u16(), 304, "versioned: 304");
897939
898940 // Removing gives the generated default SVG.
899941 let form = format!("csrf={CSRF}");
@@ -905,20 +947,27 @@ pub(crate) mod tests {
905947 Some(&form),
906948 )
907949 .await;
908- assert_eq!(status, 303);
950+ assert_eq!(status, 303, "remove: status");
909951 assert_eq!(
910952 location.as_deref(),
911- Some("/settings/profile?saved=avatar-removed")
953+ Some("/settings/profile?saved=avatar-removed"),
954+ "remove: location"
955+ );
956+ assert!(
957+ fx.store.avatar_hash(&fx.user.id).await.unwrap().is_none(),
958+ "remove: cleared"
912959 );
913- assert!(fx.store.avatar_hash(&fx.user.id).await.unwrap().is_none());
914960 let (_, _, body) = send(&fx.router, "GET", "/", true, None).await;
915961 assert!(
916962 body.contains(r#"src="/avatars/tahinli?v=default""#),
917- "{body}"
963+ "remove: nav default {body}"
918964 );
919965 // With no photo there is nothing to remove, so the menu leaves that item out.
920966 let (_, _, body) = send(&fx.router, "GET", "/settings/profile", true, None).await;
921- assert!(!body.contains("Remove photo"), "{body}");
967+ assert!(
968+ !body.contains("Remove photo"),
969+ "remove: no remove item {body}"
970+ );
922971
923972 let default = send_full(
924973 &fx.router,
@@ -929,15 +978,21 @@ pub(crate) mod tests {
929978 Vec::new(),
930979 )
931980 .await;
932- assert_eq!(default.status, 200);
981+ assert_eq!(default.status, 200, "default: status");
933982 assert_eq!(
934983 default.header("content-type").as_deref(),
935- Some("image/svg+xml")
984+ Some("image/svg+xml"),
985+ "default: type"
936986 );
937987 assert_eq!(
938988 default.header("x-content-type-options").as_deref(),
939- Some("nosniff")
989+ Some("nosniff"),
990+ "default: nosniff"
991+ );
992+ assert!(
993+ default.text().starts_with("<svg"),
994+ "default: svg {}",
995+ default.text()
940996 );
941- assert!(default.text().starts_with("<svg"), "{}", default.text());
942997 }
943998 }