Files
bibliomane/internal/inventaire/inventaire_test.go

156 lines
4.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package inventaire
import (
"testing"
"github.com/stretchr/testify/assert"
)
func getBaseInventaireUrl() string {
return "https://inventaire.io"
}
func TestCallInventaireSearch_NoParameters(t *testing.T) {
result, err := CallInventaireSearch(getBaseInventaireUrl(), "salammbo", "", 0, 0)
if err != nil {
t.Error(err)
}
assert.Equal(t, int64(17), result.Total)
assert.Equal(t, 10, len(result.Results))
}
func TestCallInventaireSearch_NoLimit(t *testing.T) {
result, err := CallInventaireSearch(getBaseInventaireUrl(), "salammbo", "fr", 0, 0)
if err != nil {
t.Error(err)
}
assert.Equal(t, int64(17), result.Total)
assert.Equal(t, 10, len(result.Results))
}
func TestCallInventaireSearch_Limit(t *testing.T) {
result, err := CallInventaireSearch(getBaseInventaireUrl(), "salammbo", "fr", 5, 0)
if err != nil {
t.Error(err)
}
assert.Equal(t, int64(17), result.Total)
assert.Equal(t, 5, len(result.Results))
}
func TestCallInventaireSearch_Offset(t *testing.T) {
result, err := CallInventaireSearch(getBaseInventaireUrl(), "salammbo", "fr", 0, 15)
if err != nil {
t.Error(err)
}
assert.Equal(t, int64(17), result.Total)
assert.Equal(t, 2, len(result.Results))
}
func TestCallInventaireBook_BraveNewWorld(t *testing.T) {
result, err := callInventaireBook(getBaseInventaireUrl(), "wd:Q191949", "fr")
if err != nil {
t.Error(err)
}
assert.Equal(t, "Le Meilleur des mondes", result.Title)
assert.Equal(t, "roman de Aldous Huxley", result.Description)
assert.Equal(t, "Q81447", result.Author.ID)
assert.Equal(t, "Aldous Huxley", result.Author.Name)
assert.Equal(t, "écrivain, romancier et philosophe britannique (18941963)", result.Author.Description)
}
func TestCallInventaireEditionFromWork_TestLimit(t *testing.T) {
result, err := CallInventaireEditionFromWork(getBaseInventaireUrl(), "wd:Q339761", "fr", 10, 0)
if err != nil {
t.Error(err)
}
assert.Equal(t, int64(34), result.Count)
assert.Equal(t, 10, len(result.Results))
}
func TestCallInventaireEditionFromWork_TestOffset(t *testing.T) {
result, err := CallInventaireEditionFromWork(getBaseInventaireUrl(), "wd:Q3213142", "fr", 0, 0)
if err != nil {
t.Error(err)
}
assert.Equal(t, 3, len(result.Results))
assert.Equal(t,
InventaireEditionResultBook{
Id: "isbn:9782070138098",
Title: "La théorie de l'information",
ISBN: "978-2-07-013809-8",
Publisher: "Éditions Gallimard",
ReleaseDate: "2012",
Image: "https://inventaire.io/img/entities/a7b9d05c041b98e98c2f429e11cb2b424d78223b",
Lang: "fr",
},
result.Results[0])
assert.Equal(t,
InventaireEditionResultBook{
Id: "isbn:9782070456260",
Title: "La théorie de l'information",
ISBN: "978-2-07-045626-0",
ReleaseDate: "2014",
Image: "https://inventaire.io/img/entities/5044c2265cc42675ac4335387aef189862cbeec1",
Lang: "fr",
},
result.Results[1])
assert.Equal(t,
InventaireEditionResultBook{
Id: "isbn:9782072525216",
Title: "La théorie de l'information",
ISBN: "978-2-07-252521-6",
ReleaseDate: "",
Image: "https://inventaire.io/img/entities/fac578440d9bf7afc7f4c5698aa618b8a4d80d21",
Lang: "fr",
},
result.Results[2])
}
func TestCallInventaireEdition(t *testing.T) {
result, err := CallInventaireEdition(getBaseInventaireUrl(), "isbn:9782266003698", "fr")
if err != nil {
t.Error(err)
}
assert.Equal(t,
InventaireEditionDetailedSingleResult{
Id: "isbn:9782266003698",
Title: "Bel-Ami",
Author: &InventaireAuthorResult{
ID: "Q9327",
Name: "Guy de Maupassant",
Description: "écrivain et journaliste littéraire français (1850-1893)",
},
Description: "roman de Guy De Maupassant",
ISBN: "978-2-266-00369-8",
Publisher: "Pocket",
ReleaseDate: "1977",
Image: "https://inventaire.io/img/entities/b237c0b5de5f6c765928d9eee26b55804a33557a",
Lang: "fr",
},
result)
}
func TestCallInventaireEditionFromISBN(t *testing.T) {
result, err := CallInventaireFromISBN(getBaseInventaireUrl(), "9782070379248", "fr")
if err != nil {
t.Error(err)
}
assert.Equal(t,
&InventaireEditionDetailedSingleResult{
Id: "isbn:9782070379248",
Title: "Du côté de chez swann",
Author: &InventaireAuthorResult{
ID: "Q7199",
Name: "Marcel Proust",
Description: "écrivain, critique et essayiste français",
},
Description: "roman de Marcel Proust",
ISBN: "978-2-07-037924-8",
Publisher: "Éditions Gallimard",
ReleaseDate: "1988",
Image: "https://inventaire.io/img/entities/646a3ef031d6a1adc27cb5f556d2a403a2f525a7",
Lang: "fr",
},
result)
}