Files
bibliomane/internal/openlibrary/openlibrary_test.go
Arthur Lefebvre 1bb841332c Open Library search API
If nothing is found on the server, returns results from open library
API. Clicking on a book imports it.
2025-12-30 18:13:11 +01:00

68 lines
3.4 KiB
Go

package openlibrary_test
import (
"testing"
"git.artlef.fr/PersonalLibraryManager/internal/openlibrary"
"github.com/stretchr/testify/assert"
)
func TestCallOpenLibrarySearch(t *testing.T) {
result, err := openlibrary.CallOpenLibrarySearch("man in high castle", 0, 0)
assert.Nil(t, err)
assert.Equal(t, 25, result.NumFound)
assert.Equal(t, 25, len(result.Books))
}
func TestCallOpenLibrarySearchLimit(t *testing.T) {
result, err := openlibrary.CallOpenLibrarySearch("man in high castle", 10, 0)
assert.Nil(t, err)
assert.Equal(t, 10, len(result.Books))
}
func TestCallOpenLibrarySearchOffset(t *testing.T) {
result, err := openlibrary.CallOpenLibrarySearch("man in high castle", 0, 10)
assert.Nil(t, err)
assert.Equal(t, 15, len(result.Books))
}
func TestCallOpenLibraryBook_FirstAuthorFormat(t *testing.T) {
result, err := openlibrary.CallOpenLibraryBook("OL21177W")
assert.Nil(t, err)
assert.Equal(t, openlibrary.OpenLibraryBookResult{
Title: "Wuthering Heights",
Description: "Wuthering Heights is an 1847 novel by Emily Brontë, initially published under the pseudonym Ellis Bell. It concerns two families of the landed gentry living on the West Yorkshire moors, the Earnshaws and the Lintons, and their turbulent relationships with Earnshaw's adopted son, Heathcliff. The novel was influenced by Romanticism and Gothic fiction.",
AuthorID: "OL24529A",
}, result)
}
func TestCallOpenLibraryBook_SecondAuthorFormat(t *testing.T) {
result, err := openlibrary.CallOpenLibraryBook("OL18388220M")
assert.Nil(t, err)
assert.Equal(t, openlibrary.OpenLibraryBookResult{
Title: "Dr Bloodmoney",
Description: "",
AuthorID: "OL274606A",
}, result)
}
func TestCallOpenLibraryAuthor_SimpleBioFormat(t *testing.T) {
result, err := openlibrary.CallOpenLibraryAuthor("OL24529A")
assert.Nil(t, err)
expectedAuthorBio := "Emily Jane Brontë was an English novelist and poet, now best remembered for her novel [Wuthering Heights][1], a classic of English literature. Emily was the second eldest of the three surviving Brontë sisters, between Charlotte and Anne. She published under the androgynous pen name Ellis Bell. ([Source][2].)\r\n\r\n\r\n [1]: http://upstream.openlibrary.org/works/OL10427528W/Wuthering_Heights\r\n [2]: http://en.wikipedia.org/wiki/Emily_Bronte"
assert.Equal(t, openlibrary.OpenLibraryAuthorResult{
Name: "Emily Brontë",
Description: expectedAuthorBio,
}, result)
}
func TestCallOpenLibraryAuthor_OtherBioFormat(t *testing.T) {
result, err := openlibrary.CallOpenLibraryAuthor("OL274606A")
assert.Nil(t, err)
expectedAuthorBio := "Philip Kindred Dick was an American novelist, short story writer, and essayist whose published work during his lifetime was almost entirely in the science fiction genre. Dick explored sociological, political and metaphysical themes in novels dominated by monopolistic corporations, authoritarian governments, and altered states. In his later works, Dick's thematic focus strongly reflected his personal interest in metaphysics and theology. He often drew upon his own life experiences and addressed the nature of drug abuse, paranoia and schizophrenia, and transcendental experiences in novels such as A Scanner Darkly and VALIS.\r\n\r\nSource and more information: [Wikipedia (EN)](http://en.wikipedia.org/wiki/Philip_K._Dick)"
assert.Equal(t, openlibrary.OpenLibraryAuthorResult{
Name: "Philip K. Dick",
Description: expectedAuthorBio,
}, result)
}