2018-11-26 21:17:33 +01:00
|
|
|
// Vikunja is a todo-list application to facilitate your life.
|
|
|
|
// Copyright 2018 Vikunja and contributors. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// 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-07-27 14:47:52 +02:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2018-08-30 08:09:17 +02:00
|
|
|
func TestListTask_Create(t *testing.T) {
|
2018-07-27 15:52:50 +02:00
|
|
|
//assert.NoError(t, PrepareTestDatabase())
|
2018-07-27 14:47:52 +02:00
|
|
|
|
2018-08-30 08:09:17 +02:00
|
|
|
// Fake list task
|
|
|
|
listtask := ListTask{
|
2018-07-27 14:47:52 +02:00
|
|
|
Text: "Lorem",
|
|
|
|
Description: "Lorem Ipsum BACKERY",
|
|
|
|
ListID: 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add one point to a list
|
2018-08-30 19:14:02 +02:00
|
|
|
doer, err := GetUserByID(1)
|
2018-07-27 14:47:52 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2018-08-30 08:09:17 +02:00
|
|
|
assert.True(t, listtask.CanCreate(&doer))
|
2018-07-27 14:47:52 +02:00
|
|
|
|
2018-08-30 08:09:17 +02:00
|
|
|
err = listtask.Create(&doer)
|
2018-07-27 14:47:52 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Update it
|
2018-08-30 08:09:17 +02:00
|
|
|
listtask.Text = "Test34"
|
|
|
|
assert.True(t, listtask.CanUpdate(&doer))
|
|
|
|
err = listtask.Update()
|
2018-07-27 14:47:52 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Check if it was updated
|
2018-08-30 08:09:17 +02:00
|
|
|
li, err := GetListTaskByID(listtask.ID)
|
2018-07-27 14:47:52 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, li.Text, "Test34")
|
|
|
|
|
2018-08-30 08:09:17 +02:00
|
|
|
// Delete the task
|
|
|
|
assert.True(t, listtask.CanDelete(&doer))
|
|
|
|
err = listtask.Delete()
|
2018-07-27 14:47:52 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2018-08-30 08:09:17 +02:00
|
|
|
// Delete a nonexistant task
|
|
|
|
listtask.ID = 0
|
|
|
|
err = listtask.Delete()
|
2018-07-27 14:47:52 +02:00
|
|
|
assert.Error(t, err)
|
2018-08-30 08:09:17 +02:00
|
|
|
assert.True(t, IsErrListTaskDoesNotExist(err))
|
2018-07-27 14:47:52 +02:00
|
|
|
|
2018-08-30 08:09:17 +02:00
|
|
|
// Try adding a list task with an empty text
|
|
|
|
listtask.Text = ""
|
|
|
|
err = listtask.Create(&doer)
|
2018-07-27 14:47:52 +02:00
|
|
|
assert.Error(t, err)
|
2018-08-30 08:09:17 +02:00
|
|
|
assert.True(t, IsErrListTaskCannotBeEmpty(err))
|
2018-07-27 14:47:52 +02:00
|
|
|
|
|
|
|
// Try adding one to a nonexistant list
|
2018-08-30 08:09:17 +02:00
|
|
|
listtask.ListID = 99993939
|
|
|
|
listtask.Text = "Lorem Ipsum"
|
|
|
|
err = listtask.Create(&doer)
|
2018-07-27 14:47:52 +02:00
|
|
|
assert.Error(t, err)
|
|
|
|
assert.True(t, IsErrListDoesNotExist(err))
|
|
|
|
|
2018-08-30 08:09:17 +02:00
|
|
|
// Try updating a nonexistant task
|
|
|
|
listtask.ID = 94829352
|
|
|
|
err = listtask.Update()
|
2018-07-27 14:47:52 +02:00
|
|
|
assert.Error(t, err)
|
2018-08-30 08:09:17 +02:00
|
|
|
assert.True(t, IsErrListTaskDoesNotExist(err))
|
2018-07-27 14:47:52 +02:00
|
|
|
|
2018-08-30 08:09:17 +02:00
|
|
|
// Try inserting an task with a nonexistant user
|
2018-07-27 14:47:52 +02:00
|
|
|
nUser := &User{ID: 9482385}
|
2018-08-30 08:09:17 +02:00
|
|
|
listtask.ListID = 1
|
|
|
|
err = listtask.Create(nUser)
|
2018-07-27 14:47:52 +02:00
|
|
|
assert.Error(t, err)
|
|
|
|
assert.True(t, IsErrUserDoesNotExist(err))
|
|
|
|
}
|