clone

a self-hosted multitenant nostr relay with sites, file storage, git hosting, and inbox and outbox delivery

main
tinyrelay / internal / daemon / social_categories_test.go
social_categories_test.go 2.3K
1package daemon23import (4 "testing"56 "github.com/FelineStateMachine/tinyrelay/internal/event"7)89func TestSocialCategoriesRespectMediaMetadataAndURLs(t *testing.T) {10 for _, tc := range []struct {11 name, category string12 row event.Event13 want bool14 }{15 {16 name: "extensionless image tag", category: "photos",17 row: event.Event{Kind: 1, Tags: [][]string{{"image", "https://cdn.example/photo"}}}, want: true,18 },19 {20 name: "mime wins over extension", category: "photos",21 row: event.Event{Kind: 1, Tags: [][]string{{"imeta", "url https://cdn.example/audio.mp3", "m image/jpeg"}}}, want: true,22 },23 {24 name: "audio note remains a note", category: "podcasts",25 row: event.Event{Kind: 1, Tags: [][]string{{"imeta", "url https://cdn.example/photo.jpg", "m audio/mpeg"}}}, want: false,26 },27 {28 name: "native F4 audio", category: "podcasts",29 row: event.Event{Kind: 54, Tags: [][]string{{"audio", "https://cdn.example/episode", "audio/mpeg"}}}, want: true,30 },31 {32 name: "metadata URL does not regain extension family", category: "podcasts",33 row: event.Event{Kind: 1, Content: "https://cdn.example/audio.mp3", Tags: [][]string{{"imeta", "url https://cdn.example/audio.mp3", "m image/jpeg"}}}, want: false,34 },35 {36 name: "cover URL keeps image family", category: "podcasts",37 row: event.Event{Kind: 30023, Content: "https://cdn.example/cover.mp3", Tags: [][]string{{"image", "https://cdn.example/cover.mp3"}}}, want: false,38 },39 {40 name: "invalid imeta URL", category: "photos",41 row: event.Event{Kind: 1, Tags: [][]string{{"imeta", "url https://user:pass@cdn.example/photo.jpg", "m image/jpeg"}}}, want: false,42 },43 {44 name: "extensionless article markdown image", category: "photos",45 row: event.Event{Kind: 30023, Content: "![cover](https://cdn.example/photo)"}, want: true,46 },47 {48 name: "fenced URL ignored", category: "podcasts",49 row: event.Event{Kind: 1, Content: "```\nhttps://cdn.example/episode.mp3\n```"}, want: false,50 },51 {52 name: "inline code URL ignored", category: "podcasts",53 row: event.Event{Kind: 1, Content: "Use `https://cdn.example/episode.mp3` as an example."}, want: false,54 },55 } {56 t.Run(tc.name+"/"+tc.category, func(t *testing.T) {57 if got := socialCategoryMatches(tc.row, tc.category); got != tc.want {58 t.Fatalf("category match = %v, want %v", got, tc.want)59 }60 })61 }62}