2018-07-27 15:11:47 +02:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"reflect"
|
2018-07-27 15:53:01 +02:00
|
|
|
"testing"
|
2018-07-27 15:11:47 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestList_ReadAll(t *testing.T) {
|
|
|
|
// Create test database
|
2018-07-27 15:52:50 +02:00
|
|
|
//assert.NoError(t, PrepareTestDatabase())
|
2018-07-27 15:11:47 +02:00
|
|
|
|
|
|
|
// Get all lists for our namespace
|
|
|
|
lists, err := GetListsByNamespaceID(1)
|
|
|
|
assert.NoError(t, err)
|
2018-08-29 08:50:52 +02:00
|
|
|
assert.Equal(t, len(lists), 2)
|
2018-07-27 15:11:47 +02:00
|
|
|
|
|
|
|
// Get all lists our user has access to
|
2018-10-31 13:42:38 +01:00
|
|
|
u, err := GetUserByID(1)
|
2018-07-27 15:11:47 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
lists2 := List{}
|
2018-10-31 13:42:38 +01:00
|
|
|
lists3, err := lists2.ReadAll(&u)
|
2018-07-27 15:11:47 +02:00
|
|
|
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
|
2018-07-27 15:53:01 +02:00
|
|
|
_, err = lists2.ReadAll(&User{ID: 984234})
|
2018-07-27 15:11:47 +02:00
|
|
|
assert.Error(t, err)
|
|
|
|
assert.True(t, IsErrUserDoesNotExist(err))
|
|
|
|
}
|