2019-12-04 20:39:56 +01:00
|
|
|
// Vikunja is a todo-list application to facilitate your life.
|
|
|
|
// Copyright 2018-2019 Vikunja and contributors. All rights reserved.
|
2018-11-26 21:17:33 +01:00
|
|
|
//
|
2019-12-04 20:39:56 +01:00
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2018-11-26 21:17:33 +01:00
|
|
|
//
|
2019-12-04 20:39:56 +01:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
2018-11-26 21:17:33 +01:00
|
|
|
//
|
2019-12-04 20:39:56 +01:00
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-11-26 21:17:33 +01:00
|
|
|
|
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
|
2019-04-21 20:18:17 +02:00
|
|
|
//assert.NoError(t, LoadFixtures())
|
2018-07-27 15:11:47 +02:00
|
|
|
|
|
|
|
// Get all lists for our namespace
|
2018-12-04 11:16:42 +01:00
|
|
|
lists, err := GetListsByNamespaceID(1, &User{})
|
2018-07-27 15:11:47 +02:00
|
|
|
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{}
|
2019-10-23 23:11:40 +02:00
|
|
|
lists3, _, _, err := lists2.ReadAll(u, "", 1, 50)
|
|
|
|
|
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)
|
2019-07-18 18:38:21 +02:00
|
|
|
assert.Equal(t, 16, s.Len())
|
2018-07-27 15:11:47 +02:00
|
|
|
|
|
|
|
// Try getting lists for a nonexistant user
|
2019-10-23 23:11:40 +02:00
|
|
|
_, _, _, err = lists2.ReadAll(&User{ID: 984234}, "", 1, 50)
|
2018-07-27 15:11:47 +02:00
|
|
|
assert.Error(t, err)
|
|
|
|
assert.True(t, IsErrUserDoesNotExist(err))
|
|
|
|
}
|