vikunja-api/models/list_create_test.go

64 lines
1.3 KiB
Go
Raw Normal View History

2018-07-26 10:29:19 +02:00
package models
import (
"github.com/stretchr/testify/assert"
2018-07-26 10:50:03 +02:00
"testing"
2018-07-26 10:29:19 +02:00
)
func TestList_Create(t *testing.T) {
// Create test database
assert.NoError(t, PrepareTestDatabase())
// Get our doer
doer, _, err := GetUserByID(1)
assert.NoError(t, err)
// Dummy list for testing
dummylist := List{
2018-07-26 10:50:03 +02:00
Title: "test",
2018-07-26 10:29:19 +02:00
Description: "Lorem Ipsum",
2018-07-26 10:49:17 +02:00
NamespaceID: 1,
2018-07-26 10:29:19 +02:00
}
2018-07-26 10:49:17 +02:00
// Check if the user can create
assert.True(t, dummylist.CanCreate(&doer))
2018-07-26 10:29:19 +02:00
// Create it
err = dummylist.Create(&doer)
assert.NoError(t, err)
// Get the list
2018-07-26 10:50:03 +02:00
newdummy := List{ID: dummylist.ID}
2018-07-26 10:29:19 +02:00
err = newdummy.ReadOne()
assert.NoError(t, err)
assert.Equal(t, dummylist.Title, newdummy.Title)
assert.Equal(t, dummylist.Description, newdummy.Description)
assert.Equal(t, dummylist.OwnerID, doer.ID)
2018-07-26 10:49:17 +02:00
// Check if the user can see it
assert.True(t, dummylist.CanRead(&doer))
2018-07-26 10:29:19 +02:00
// Check failing with no title
list2 := List{}
err = list2.Create(&doer)
assert.Error(t, err)
assert.True(t, IsErrListTitleCannotBeEmpty(err))
2018-07-26 10:49:17 +02:00
// Delete it
assert.True(t, dummylist.CanDelete(&doer))
err = dummylist.Delete()
assert.NoError(t, err)
// Check creation with a nonexistant namespace
list3 := List{
2018-07-26 10:50:03 +02:00
Title: "test",
2018-07-26 10:49:17 +02:00
Description: "Lorem Ipsum",
NamespaceID: 876694,
}
err = list3.Create(&doer)
assert.Error(t, err)
assert.True(t, IsErrNamespaceDoesNotExist(err))
2018-07-26 10:29:19 +02:00
}