From 2d6e73a8006ecdc54cb318b1a1b8da75ff99dc85 Mon Sep 17 00:00:00 2001 From: SoXX Date: Tue, 2 Jun 2026 21:29:38 +0200 Subject: [PATCH] test(actions): make TestFindFavLinks resilient to capture state Asserts exactly one of fav/unfav is set with a well-formed URL, instead of hardcoding the +Fav direction. The previous test broke whenever the capturing account favourited the target submission. Also points the test at submission 12345678 (the documented default FA_TEST_SUB_ID) so it matches what TestRefreshFixtures captures by default. --- actions_test.go | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/actions_test.go b/actions_test.go index a5ac590..43dc09c 100644 --- a/actions_test.go +++ b/actions_test.go @@ -364,16 +364,25 @@ func TestFindFavLinks_RealFixture(t *testing.T) { if err != nil { t.Fatalf("read doc: %v", err) } - // submission.html was captured for submission 65052636 (a "+Fav" page). - favURL, unfavURL := findFavLinks(doc, 65052636) - if favURL == "" { - t.Error("findFavLinks: favURL empty +Fav anchor not found in real markup") - } - if !strings.Contains(favURL, "/fav/65052636/") || !strings.Contains(favURL, "key=") { - t.Errorf("findFavLinks: favURL = %q; want a /fav/65052636/?key=... URL", favURL) - } - if unfavURL != "" { - t.Errorf("findFavLinks: unfavURL = %q; want empty on a not-yet-faved page", unfavURL) + // submission.html was captured for submission 12345678. FA renders either + // a +Fav or a -Fav anchor depending on the capturing account's current + // state never both, never neither (when authenticated). The test stays + // direction-agnostic so it doesn't break when the capturing account + // favourites/unfavourites this submission. + favURL, unfavURL := findFavLinks(doc, 12345678) + switch { + case favURL == "" && unfavURL == "": + t.Error("findFavLinks: both URLs empty fav/unfav anchor not found in real markup") + case favURL != "" && unfavURL != "": + t.Errorf("findFavLinks: both URLs set (fav=%q unfav=%q); expected exactly one", favURL, unfavURL) + case favURL != "": + if !strings.Contains(favURL, "/fav/12345678/") || !strings.Contains(favURL, "key=") { + t.Errorf("findFavLinks: favURL = %q; want a /fav/12345678/?key=... URL", favURL) + } + case unfavURL != "": + if !strings.Contains(unfavURL, "/unfav/12345678/") || !strings.Contains(unfavURL, "key=") { + t.Errorf("findFavLinks: unfavURL = %q; want a /unfav/12345678/?key=... URL", unfavURL) + } } }