Improved tests for lists
This commit is contained in:
parent
f7bc88c825
commit
ba606515d1
2 changed files with 60 additions and 5 deletions
|
@ -38,11 +38,11 @@ func TestList_Create(t *testing.T) {
|
|||
// Check if the user can see it
|
||||
assert.True(t, dummylist.CanRead(&doer))
|
||||
|
||||
// Check failing with no title
|
||||
list2 := List{}
|
||||
err = list2.Create(&doer)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrListTitleCannotBeEmpty(err))
|
||||
// Try updating a list
|
||||
assert.True(t, dummylist.CanUpdate(&doer))
|
||||
dummylist.Description = "Lorem Ipsum dolor sit amet."
|
||||
err = dummylist.Update()
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Delete it
|
||||
assert.True(t, dummylist.CanDelete(&doer))
|
||||
|
@ -50,6 +50,22 @@ func TestList_Create(t *testing.T) {
|
|||
err = dummylist.Delete()
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Try updating a nonexistant list
|
||||
err = dummylist.Update()
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrListDoesNotExist(err))
|
||||
|
||||
// Delete a nonexistant list
|
||||
err = dummylist.Delete()
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrListDoesNotExist(err))
|
||||
|
||||
// Check failing with no title
|
||||
list2 := List{}
|
||||
err = list2.Create(&doer)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrListTitleCannotBeEmpty(err))
|
||||
|
||||
// Check creation with a nonexistant namespace
|
||||
list3 := List{
|
||||
Title: "test",
|
||||
|
@ -60,4 +76,10 @@ func TestList_Create(t *testing.T) {
|
|||
err = list3.Create(&doer)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrNamespaceDoesNotExist(err))
|
||||
|
||||
// Try creating with a nonexistant owner
|
||||
nUser := &User{ID: 9482385}
|
||||
err = dummylist.Create(nUser)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrUserDoesNotExist(err))
|
||||
}
|
||||
|
|
33
models/lists_get_test.go
Normal file
33
models/lists_get_test.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func TestList_ReadAll(t *testing.T) {
|
||||
// Create test database
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
|
||||
// Get all lists for our namespace
|
||||
lists, err := GetListsByNamespaceID(1)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, len(lists), 1)
|
||||
|
||||
// Get all lists our user has access to
|
||||
user, _, err := GetUserByID(1)
|
||||
assert.NoError(t, err)
|
||||
|
||||
lists2 := List{}
|
||||
lists3, err := lists2.ReadAll(&user)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, reflect.TypeOf(lists3).Kind(), reflect.Slice)
|
||||
s := reflect.ValueOf(lists3)
|
||||
assert.Equal(t, s.Len(), 1)
|
||||
|
||||
// Try getting lists for a nonexistant user
|
||||
_, err = lists2.ReadAll(&User{ID:984234})
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrUserDoesNotExist(err))
|
||||
}
|
Loading…
Reference in a new issue