Skip to content

Commit

Permalink
radio: make User.IsValid use username as empty-indicator instead
Browse files Browse the repository at this point in the history
website/admin: fix tests not using valid users
  • Loading branch information
Wessie committed May 26, 2024
1 parent c201578 commit 15e8e2e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion radio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion radio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
10 changes: 9 additions & 1 deletion website/admin/songs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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{}{},
Expand Down Expand Up @@ -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{}{},
Expand Down Expand Up @@ -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{}{},
Expand All @@ -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{}{},
Expand All @@ -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{}{},
Expand Down Expand Up @@ -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{}{},
Expand Down

0 comments on commit 15e8e2e

Please sign in to comment.