Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

test: add comprehensive coverage for canonical URL filter

- Verify clean URL passthrough behavior
- Test query parameter removal functionality
- Test fragment removal functionality
- Test combined query params and fragments handling
- Ensure graceful degradation for malformed URLs

+61
+61
bskyweb/cmd/bskyweb/filters_test.go
··· 1 + package main 2 + 3 + import ( 4 + "testing" 5 + 6 + "github.com/flosch/pongo2/v6" 7 + ) 8 + 9 + func TestCanonicalFilter(t *testing.T) { 10 + tests := []struct { 11 + name string 12 + input string 13 + expected string 14 + }{ 15 + { 16 + name: "clean URL", 17 + input: "https://bsky.app/profile/user", 18 + expected: "https://bsky.app/profile/user", 19 + }, 20 + { 21 + name: "URL with query params", 22 + input: "https://bsky.app/profile/user?utm_source=test", 23 + expected: "https://bsky.app/profile/user", 24 + }, 25 + { 26 + name: "URL with multiple params", 27 + input: "https://bsky.app/profile/user?utm_source=twitter&utm_campaign=test", 28 + expected: "https://bsky.app/profile/user", 29 + }, 30 + { 31 + name: "URL with fragment", 32 + input: "https://bsky.app/profile/user#section", 33 + expected: "https://bsky.app/profile/user", 34 + }, 35 + { 36 + name: "URL with both params and fragment", 37 + input: "https://bsky.app/profile/user?param=1#section", 38 + expected: "https://bsky.app/profile/user", 39 + }, 40 + { 41 + name: "malformed URL", 42 + input: "not-a-url", 43 + expected: "not-a-url", // Should return original on error 44 + }, 45 + } 46 + 47 + for _, tt := range tests { 48 + t.Run(tt.name, func(t *testing.T) { 49 + inputValue := pongo2.AsValue(tt.input) 50 + result, err := filterCanonical(inputValue, nil) 51 + if err != nil { 52 + t.Errorf("filterCanonical() error = %v", err) 53 + return 54 + } 55 + 56 + if result.String() != tt.expected { 57 + t.Errorf("filterCanonical() = %v, want %v", result.String(), tt.expected) 58 + } 59 + }) 60 + } 61 + }