Added author tests

This commit is contained in:
konrad 2018-01-16 11:53:27 +01:00 committed by kolaente
parent aa6bc74405
commit d0202aea41
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 24 additions and 2 deletions

View File

@ -16,11 +16,24 @@ func TestAddOrUpdateAuthor(t *testing.T) {
author1, err := AddOrUpdateAuthor(testauthor)
assert.NoError(t, err)
// And anotherone
_, err = AddOrUpdateAuthor(testauthor)
assert.NoError(t, err)
// As of now, we should have 2 author in total. Get the list and check.
allauthors, err := ListAuthors("")
assert.NoError(t, err)
for _, author := range allauthors {
assert.Equal(t, testauthor.Forename, author.Forename)
assert.Equal(t, testauthor.Lastname, author.Lastname)
}
// Get the new author
author2, exists, err := GetAuthorByID(author1.ID)
gotauthor, exists, err := GetAuthorByID(author1.ID)
assert.NoError(t, err)
assert.True(t, exists)
assert.Equal(t, author2.Forename, testauthor.Forename)
assert.Equal(t, gotauthor.Forename, testauthor.Forename)
// Pass an empty author to see if it fails
_, err = AddOrUpdateAuthor(Author{})
@ -32,4 +45,13 @@ func TestAddOrUpdateAuthor(t *testing.T) {
author1updated, err := AddOrUpdateAuthor(testauthor)
assert.NoError(t, err)
assert.Equal(t, testauthor.Forename, author1updated.Forename)
// Delete the author
err = DeleteAuthorByID(author1.ID)
assert.NoError(t, err)
// Check if it is gone
_, exists, err = GetAuthorByID(author1.ID)
assert.NoError(t, err)
assert.False(t, exists)
}