home to your local SPACEGIRL 💫 arimelody.space
1
fork

Configure Feed

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

model function unit tests!

+254 -16
+1 -1
admin/components/release/release-list-item.html
··· 7 7 <h3 class="release-title"> 8 8 <a href="/admin/release/{{.ID}}">{{.Title}}</a> 9 9 <small> 10 - <span title="{{.PrintReleaseDate}}">{{.GetReleaseYear}}</span> 10 + <span title="{{.PrintReleaseDate}}">{{.ReleaseDate.Year}}</span> 11 11 {{if not .Visible}}(hidden){{end}} 12 12 </small> 13 13 </h3>
-4
model/artist.go
··· 9 9 } 10 10 ) 11 11 12 - func (artist Artist) GetWebsite() string { 13 - return artist.Website 14 - } 15 - 16 12 func (artist Artist) GetAvatar() string { 17 13 if artist.Avatar == "" { 18 14 return "/img/default-avatar.png"
+23
model/artist_test.go
··· 1 + package model 2 + 3 + import ( 4 + "testing" 5 + ) 6 + 7 + func Test_Artist_GetAvatar(t *testing.T) { 8 + want := "testavatar.png" 9 + artist := Artist{ Avatar: want } 10 + 11 + got := artist.GetAvatar() 12 + if want != got { 13 + t.Errorf(`correct value not returned when avatar is populated (want "%s", got "%s")`, want, got) 14 + } 15 + 16 + artist = Artist{} 17 + 18 + want = "/img/default-avatar.png" 19 + got = artist.GetAvatar() 20 + if want != got { 21 + t.Errorf(`default value not returned when avatar is empty (want "%s", got "%s")`, want, got) 22 + } 23 + }
+2 -2
model/link.go
··· 11 11 } 12 12 13 13 func (link Link) NormaliseName() string { 14 - rgx := regexp.MustCompile(`[^a-z0-9]`) 15 - return strings.ToLower(rgx.ReplaceAllString(link.Name, "")) 14 + rgx := regexp.MustCompile(`[^a-z0-9\-]`) 15 + return rgx.ReplaceAllString(strings.ToLower(link.Name), "") 16 16 }
-4
model/release.go
··· 50 50 return release.ReleaseDate.Format("02 January 2006") 51 51 } 52 52 53 - func (release Release) GetReleaseYear() int { 54 - return release.ReleaseDate.Year() 55 - } 56 - 57 53 func (release Release) GetArtwork() string { 58 54 if release.Artwork == "" { 59 55 return "/img/default-cover-art.png"
+157
model/release_test.go
··· 1 + package model 2 + 3 + import ( 4 + "testing" 5 + "time" 6 + ) 7 + 8 + func Test_Release_DescriptionHTML(t *testing.T) { 9 + release := Release{ 10 + Description: "this is\na test\n<strong>description!</strong>", 11 + } 12 + 13 + // descriptions are set by privileged users, 14 + // so we'll allow HTML injection here 15 + want := "this is<br>a test<br><strong>description!</strong>" 16 + got := release.GetDescriptionHTML() 17 + if want != string(got) { 18 + t.Errorf(`release description incorrectly formatted (want "%s", got "%s")`, want, got) 19 + } 20 + } 21 + 22 + func Test_Release_ReleaseDate(t *testing.T) { 23 + release := Release{ 24 + ReleaseDate: time.Date(2025, time.July, 26, 16, 0, 0, 0, time.UTC), 25 + } 26 + 27 + want := "2025-07-26T16:00" 28 + got := release.TextReleaseDate() 29 + if want != got { 30 + t.Errorf(`release date incorrectly formatted (want "%s", got "%s")`, want, got) 31 + } 32 + 33 + want = "26 July 2025" 34 + got = release.PrintReleaseDate() 35 + if want != got { 36 + t.Errorf(`release date (print) incorrectly formatted (want "%s", got "%s")`, want, got) 37 + } 38 + } 39 + 40 + func Test_Release_Artwork(t *testing.T) { 41 + want := "testartwork.png" 42 + release := Release{ Artwork: want } 43 + 44 + got := release.GetArtwork() 45 + if want != got { 46 + t.Errorf(`correct value not returned when artwork is populated (want "%s", got "%s")`, want, got) 47 + } 48 + 49 + release = Release{} 50 + 51 + want = "/img/default-cover-art.png" 52 + got = release.GetArtwork() 53 + if want != got { 54 + t.Errorf(`default value not returned when artwork is empty (want "%s", got "%s")`, want, got) 55 + } 56 + } 57 + 58 + func Test_Release_IsSingle(t *testing.T) { 59 + release := Release{ 60 + Tracks: []*Track{}, 61 + } 62 + 63 + if release.IsSingle() { 64 + t.Errorf("IsSingle() == true when no tracks are present") 65 + } 66 + 67 + release.Tracks = append(release.Tracks, &Track{}) 68 + if !release.IsSingle() { 69 + t.Errorf("IsSingle() == false when one track is present") 70 + } 71 + 72 + release.Tracks = append(release.Tracks, &Track{}) 73 + if release.IsSingle() { 74 + t.Errorf("IsSingle() == true when >1 tracks are present") 75 + } 76 + } 77 + 78 + func Test_Release_IsReleased(t *testing.T) { 79 + release := Release { 80 + ReleaseDate: time.Now(), 81 + } 82 + 83 + if !release.IsReleased() { 84 + t.Errorf("IsRelease() == false when release date in the past") 85 + } 86 + 87 + release.ReleaseDate = time.Now().Add(time.Hour) 88 + if release.IsReleased() { 89 + t.Errorf("IsRelease() == true when release date in the future") 90 + } 91 + } 92 + 93 + func Test_Release_PrintArtists(t *testing.T) { 94 + artist1 := "ari melody" 95 + artist2 := "aridoodle" 96 + artist3 := "idk" 97 + artist4 := "guest" 98 + 99 + release := Release { 100 + Credits: []*Credit{ 101 + { Artist: Artist{ Name: artist1 }, Primary: true }, 102 + { Artist: Artist{ Name: artist2 }, Primary: true }, 103 + { Artist: Artist{ Name: artist3 }, Primary: false }, 104 + { Artist: Artist{ Name: artist4 }, Primary: true }, 105 + }, 106 + } 107 + 108 + { 109 + want := []string{ artist1, artist2, artist4 } 110 + got := release.GetUniqueArtistNames(true) 111 + if len(want) != len(got) { 112 + t.Errorf(`len(GetUniqueArtistNames) (primary only) == %d, want %d`, len(got), len(want)) 113 + } 114 + for i := range got { 115 + if want[i] != got[i] { 116 + t.Errorf(`GetUniqueArtistNames[%d] (primary only) == %s, want %s`, i, got[i], want[i]) 117 + } 118 + } 119 + 120 + want = []string{ artist1, artist2, artist3, artist4 } 121 + got = release.GetUniqueArtistNames(false) 122 + if len(want) != len(got) { 123 + t.Errorf(`len(GetUniqueArtistNames) == %d, want %d`, len(got), len(want)) 124 + } 125 + for i := range got { 126 + if want[i] != got[i] { 127 + t.Errorf(`GetUniqueArtistNames[%d] == %s, want %s`, i, got[i], want[i]) 128 + } 129 + } 130 + } 131 + 132 + { 133 + want := "ari melody, aridoodle & guest" 134 + got := release.PrintArtists(true, true) 135 + if want != got { 136 + t.Errorf(`PrintArtists (primary only, ampersand) == "%s", want "%s"`, want, got) 137 + } 138 + 139 + want = "ari melody, aridoodle, guest" 140 + got = release.PrintArtists(true, false) 141 + if want != got { 142 + t.Errorf(`PrintArtists (primary only) == "%s", want "%s"`, want, got) 143 + } 144 + 145 + want = "ari melody, aridoodle, idk & guest" 146 + got = release.PrintArtists(false, true) 147 + if want != got { 148 + t.Errorf(`PrintArtists (all, ampersand) == "%s", want "%s"`, want, got) 149 + } 150 + 151 + want = "ari melody, aridoodle, idk, guest" 152 + got = release.PrintArtists(false, false) 153 + if want != got { 154 + t.Errorf(`PrintArtists (all) == "%s", want "%s"`, want, got) 155 + } 156 + } 157 + }
+43
model/track_test.go
··· 1 + package model 2 + 3 + import ( 4 + "testing" 5 + ) 6 + 7 + func Test_Track_DescriptionHTML(t *testing.T) { 8 + track := Track{ 9 + Description: "this is\na test\n<strong>description!</strong>", 10 + } 11 + 12 + // descriptions are set by privileged users, 13 + // so we'll allow HTML injection here 14 + want := "this is<br>a test<br><strong>description!</strong>" 15 + got := track.GetDescriptionHTML() 16 + if want != string(got) { 17 + t.Errorf(`track description incorrectly formatted (want "%s", got "%s")`, want, got) 18 + } 19 + } 20 + 21 + func Test_Track_LyricsHTML(t *testing.T) { 22 + track := Track{ 23 + Lyrics: "these are\ntest\n<strong>lyrics!</strong>", 24 + } 25 + 26 + // lyrics are set by privileged users, 27 + // so we'll allow HTML injection here 28 + want := "these are<br>test<br><strong>lyrics!</strong>" 29 + got := track.GetLyricsHTML() 30 + if want != string(got) { 31 + t.Errorf(`track lyrics incorrectly formatted (want "%s", got "%s")`, want, got) 32 + } 33 + } 34 + 35 + func Test_Track_Add(t *testing.T) { 36 + track := Track{} 37 + 38 + want := 4 39 + got := track.Add(2, 2) 40 + if want != got { 41 + t.Errorf(`somehow, we screwed up addition. (want %d, got %d)`, want, got) 42 + } 43 + }
+5 -5
views/music-gateway.html
··· 4 4 5 5 <meta name="description" content="Stream &quot;{{.Title}}&quot; by {{.PrintArtists true true}} on all platforms!"> 6 6 <meta name="author" content="{{.PrintArtists true true}}"> 7 - <meta name="keywords" content="{{.PrintArtists true false}}, music, {{.Title}}, {{.ID}}, {{.GetReleaseYear}}"> 7 + <meta name="keywords" content="{{.PrintArtists true false}}, music, {{.Title}}, {{.ID}}, {{.ReleaseDate.Year}}"> 8 8 9 9 <meta property="og:url" content="https://arimelody.me/music/{{.ID}}"> 10 10 <meta property="og:type" content="website"> ··· 54 54 <div id="overview"> 55 55 <div id="title-container"> 56 56 <h1 id="title">{{.Title}}</h1> 57 - <span id="year" title="{{.PrintReleaseDate}}">{{.GetReleaseYear}}</span> 57 + <span id="year" title="{{.PrintReleaseDate}}">{{.ReleaseDate.Year}}</span> 58 58 </div> 59 59 <p id="artist">{{.PrintArtists true true}}</p> 60 60 {{if .IsReleased}} ··· 91 91 {{end}} 92 92 93 93 {{if and .Copyright .CopyrightURL}} 94 - <p id="copyright">{{.Title}} &copy; {{.GetReleaseYear}} by {{.PrintArtists true true}} is licensed under <a href="{{.CopyrightURL}}" target="_blank">{{.Copyright}}</a></p> 94 + <p id="copyright">{{.Title}} &copy; {{.ReleaseDate.Year}} by {{.PrintArtists true true}} is licensed under <a href="{{.CopyrightURL}}" target="_blank">{{.Copyright}}</a></p> 95 95 {{end}} 96 96 97 97 <button id="share">share</button> ··· 105 105 <ul> 106 106 {{range .Credits}} 107 107 {{$Artist := .Artist}} 108 - {{if $Artist.GetWebsite}} 109 - <li><strong><a href="{{$Artist.GetWebsite}}">{{$Artist.Name}}</a></strong>: {{.Role}}</li> 108 + {{if $Artist.Website}} 109 + <li><strong><a href="{{$Artist.Website}}">{{$Artist.Name}}</a></strong>: {{.Role}}</li> 110 110 {{else}} 111 111 <li><strong>{{$Artist.Name}}</strong>: {{.Role}}</li> 112 112 {{end}}