From 15e8e2e08d6a73cc364bf471dcb64ab4c5aaf9f7 Mon Sep 17 00:00:00 2001 From: Wessie Date: Sun, 26 May 2024 15:17:24 +0100 Subject: [PATCH] radio: make User.IsValid use username as empty-indicator instead website/admin: fix tests not using valid users --- radio.go | 2 +- radio_test.go | 11 ++++++++++- website/admin/songs_test.go | 10 +++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/radio.go b/radio.go index 31401a2..ba722f6 100644 --- a/radio.go +++ b/radio.go @@ -249,7 +249,7 @@ func (u User) ComparePassword(passwd string) error { } func (u *User) IsValid() bool { - return u != nil && u.ID != 0 + return u != nil && u.Username != "" } var bcryptCost = 14 diff --git a/radio_test.go b/radio_test.go index 6bdf51c..03e4890 100644 --- a/radio_test.go +++ b/radio_test.go @@ -427,7 +427,16 @@ func TestUserIsValid(t *testing.T) { { name: "actual value", user: &User{ - ID: 500, + ID: 500, + Username: "test", + }, + expected: true, + }, + { + name: "value with 0 ID", + user: &User{ + ID: 0, + Username: "test", }, expected: true, }, diff --git a/website/admin/songs_test.go b/website/admin/songs_test.go index f4aaddb..258988f 100644 --- a/website/admin/songs_test.go +++ b/website/admin/songs_test.go @@ -200,7 +200,9 @@ func TestPostSongs(t *testing.T) { getArg = testSong.TrackID getRet = testSong - user := radio.User{} + user := radio.User{ + Username: "test", + } req := prepReq(user, testValues) w := httptest.NewRecorder() @@ -224,6 +226,7 @@ func TestPostSongs(t *testing.T) { deleteArg = testSong.TrackID user := radio.User{ + Username: "test", UserPermissions: radio.UserPermissions{ radio.PermActive: struct{}{}, radio.PermDatabaseEdit: struct{}{}, @@ -258,6 +261,7 @@ func TestPostSongs(t *testing.T) { deleteArg = testSong.TrackID user := radio.User{ + Username: "test", UserPermissions: radio.UserPermissions{ radio.PermActive: struct{}{}, radio.PermDatabaseEdit: struct{}{}, @@ -287,6 +291,7 @@ func TestPostSongs(t *testing.T) { deleteArg = testSong.TrackID user := radio.User{ + Username: "test", UserPermissions: radio.UserPermissions{ radio.PermActive: struct{}{}, radio.PermDatabaseEdit: struct{}{}, @@ -312,6 +317,7 @@ func TestPostSongs(t *testing.T) { getRet = testSong user := radio.User{ + Username: "test", UserPermissions: radio.UserPermissions{ radio.PermActive: struct{}{}, radio.PermDatabaseEdit: struct{}{}, @@ -337,6 +343,7 @@ func TestPostSongs(t *testing.T) { getRet = testSong user := radio.User{ + Username: "test", UserPermissions: radio.UserPermissions{ radio.PermActive: struct{}{}, radio.PermDatabaseEdit: struct{}{}, @@ -367,6 +374,7 @@ func TestPostSongs(t *testing.T) { getRet = &c user := radio.User{ + Username: "test", UserPermissions: radio.UserPermissions{ radio.PermActive: struct{}{}, radio.PermDatabaseEdit: struct{}{},