Added author tests
This commit is contained in:
parent
aa6bc74405
commit
d0202aea41
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue