2020-05-29 12:21:17 +02:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-11-24 17:51:39 +01:00
|
|
|
"github.com/dustin/go-humanize/english"
|
|
|
|
|
2020-05-29 12:21:17 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMomentsTime(t *testing.T) {
|
|
|
|
t.Run("result found", func(t *testing.T) {
|
|
|
|
results, err := MomentsTime(1)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if len(results) < 4 {
|
|
|
|
t.Error("at least 4 results expected")
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("MomentsTime %+v", results)
|
|
|
|
|
|
|
|
for _, moment := range results {
|
2021-11-18 00:46:34 +01:00
|
|
|
t.Logf("Title: %s", moment.Title())
|
|
|
|
t.Logf("Slug: %s", moment.Slug())
|
|
|
|
t.Logf("Title Slug: %s", moment.TitleSlug())
|
|
|
|
|
2020-05-29 18:04:30 +02:00
|
|
|
assert.Len(t, moment.Country, 0)
|
|
|
|
assert.GreaterOrEqual(t, moment.Year, 1990)
|
|
|
|
assert.LessOrEqual(t, moment.Year, 2800)
|
|
|
|
assert.GreaterOrEqual(t, moment.Month, 1)
|
|
|
|
assert.LessOrEqual(t, moment.Month, 12)
|
2020-05-29 12:21:17 +02:00
|
|
|
assert.GreaterOrEqual(t, moment.PhotoCount, 1)
|
2021-11-18 00:46:34 +01:00
|
|
|
assert.Regexp(t, "[a-zA-Z]+ [0-9]+", moment.Title())
|
|
|
|
assert.Regexp(t, "[a-z]+\\-[0-9]+", moment.Slug())
|
|
|
|
assert.Regexp(t, "[a-z]+\\-[0-9]+", moment.TitleSlug())
|
2020-05-29 12:21:17 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMomentsCountries(t *testing.T) {
|
|
|
|
t.Run("result found", func(t *testing.T) {
|
|
|
|
results, err := MomentsCountries(1)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("MomentsCountries %+v", results)
|
|
|
|
|
|
|
|
if len(results) < 1 {
|
|
|
|
t.Error("at least one result expected")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, moment := range results {
|
2021-11-18 00:46:34 +01:00
|
|
|
t.Logf("Title: %s", moment.Title())
|
|
|
|
t.Logf("Slug: %s", moment.Slug())
|
|
|
|
t.Logf("Title Slug: %s", moment.TitleSlug())
|
|
|
|
|
2020-05-29 18:04:30 +02:00
|
|
|
assert.Len(t, moment.Country, 2)
|
|
|
|
assert.GreaterOrEqual(t, moment.Year, 1990)
|
|
|
|
assert.LessOrEqual(t, moment.Year, 2800)
|
|
|
|
assert.Equal(t, moment.Month, 0)
|
2020-05-29 12:21:17 +02:00
|
|
|
assert.GreaterOrEqual(t, moment.PhotoCount, 1)
|
2021-11-18 00:46:34 +01:00
|
|
|
assert.Regexp(t, "[ \\&a-zA-Z0-9]+", moment.Title())
|
|
|
|
assert.Regexp(t, "[\\-a-z0-9]+", moment.Slug())
|
|
|
|
assert.Regexp(t, "[\\-a-z0-9]+", moment.TitleSlug())
|
2020-05-29 12:21:17 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMomentsStates(t *testing.T) {
|
|
|
|
t.Run("result found", func(t *testing.T) {
|
|
|
|
results, err := MomentsStates(1)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("MomentsStates %+v", results)
|
|
|
|
|
|
|
|
if len(results) < 1 {
|
|
|
|
t.Error("at least one result expected")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, moment := range results {
|
2021-11-18 00:46:34 +01:00
|
|
|
t.Logf("Title: %s", moment.Title())
|
|
|
|
t.Logf("Slug: %s", moment.Slug())
|
|
|
|
t.Logf("Title Slug: %s", moment.TitleSlug())
|
|
|
|
|
2020-05-29 18:04:30 +02:00
|
|
|
assert.Len(t, moment.Country, 2)
|
|
|
|
assert.NotEmpty(t, moment.State)
|
|
|
|
assert.Equal(t, moment.Year, 0)
|
|
|
|
assert.Equal(t, moment.Month, 0)
|
2020-05-29 12:21:17 +02:00
|
|
|
assert.GreaterOrEqual(t, moment.PhotoCount, 1)
|
2021-11-18 00:46:34 +01:00
|
|
|
assert.Regexp(t, "[ \\&a-zA-Z0-9]+", moment.Title())
|
|
|
|
assert.Regexp(t, "[\\-a-z0-9]+", moment.Slug())
|
|
|
|
assert.Regexp(t, "[\\-a-z0-9]+", moment.TitleSlug())
|
2020-05-29 12:21:17 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMomentsCategories(t *testing.T) {
|
|
|
|
t.Run("result found", func(t *testing.T) {
|
2020-05-30 01:41:47 +02:00
|
|
|
results, err := MomentsLabels(1)
|
2020-05-29 12:21:17 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-05-30 01:41:47 +02:00
|
|
|
t.Logf("MomentsLabels %+v", results)
|
2020-05-29 12:21:17 +02:00
|
|
|
|
|
|
|
if len(results) < 1 {
|
|
|
|
t.Error("at least one result expected")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, moment := range results {
|
2021-11-18 00:46:34 +01:00
|
|
|
t.Logf("Title: %s", moment.Title())
|
|
|
|
t.Logf("Slug: %s", moment.Slug())
|
|
|
|
t.Logf("Title Slug: %s", moment.TitleSlug())
|
|
|
|
|
2020-05-30 01:41:47 +02:00
|
|
|
assert.NotEmpty(t, moment.Label)
|
2020-05-29 18:04:30 +02:00
|
|
|
assert.Empty(t, moment.Country)
|
|
|
|
assert.Empty(t, moment.State)
|
|
|
|
assert.Equal(t, moment.Year, 0)
|
|
|
|
assert.Equal(t, moment.Month, 0)
|
2020-05-29 12:21:17 +02:00
|
|
|
assert.GreaterOrEqual(t, moment.PhotoCount, 1)
|
2021-11-18 00:46:34 +01:00
|
|
|
assert.Regexp(t, "[ \\&a-zA-Z0-9]+", moment.Title())
|
|
|
|
assert.Regexp(t, "[\\-a-z0-9]+", moment.Slug())
|
|
|
|
assert.Regexp(t, "[\\-a-z0-9]+", moment.TitleSlug())
|
2020-05-29 12:21:17 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-07-13 12:29:11 +02:00
|
|
|
|
|
|
|
func TestMoment_Title(t *testing.T) {
|
|
|
|
t.Run("country", func(t *testing.T) {
|
|
|
|
moment := Moment{
|
|
|
|
Label: "",
|
|
|
|
Country: "de",
|
|
|
|
State: "",
|
|
|
|
Year: 0,
|
|
|
|
Month: 0,
|
|
|
|
PhotoCount: 0,
|
|
|
|
}
|
|
|
|
|
2021-11-18 00:46:34 +01:00
|
|
|
assert.Equal(t, "Germany", moment.Title())
|
2021-03-03 11:49:32 +01:00
|
|
|
})
|
|
|
|
t.Run("country name", func(t *testing.T) {
|
|
|
|
moment := Moment{
|
|
|
|
Label: "",
|
|
|
|
Country: "de",
|
|
|
|
State: "",
|
|
|
|
Year: 1800,
|
|
|
|
Month: 0,
|
|
|
|
PhotoCount: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "Germany", moment.Title())
|
2020-07-13 12:29:11 +02:00
|
|
|
})
|
|
|
|
t.Run("country and year", func(t *testing.T) {
|
|
|
|
moment := Moment{
|
|
|
|
Label: "",
|
|
|
|
Country: "de",
|
|
|
|
State: "",
|
|
|
|
Year: 2010,
|
|
|
|
Month: 0,
|
|
|
|
PhotoCount: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "Germany 2010", moment.Title())
|
|
|
|
})
|
2020-07-13 13:12:32 +02:00
|
|
|
t.Run("country, state and year", func(t *testing.T) {
|
|
|
|
moment := Moment{
|
|
|
|
Label: "",
|
|
|
|
Country: "de",
|
|
|
|
State: "Pfalz",
|
|
|
|
Year: 2010,
|
|
|
|
Month: 0,
|
|
|
|
PhotoCount: 0,
|
|
|
|
}
|
|
|
|
|
2021-11-18 13:13:48 +01:00
|
|
|
assert.Equal(t, "Pfalz / 2010", moment.Title())
|
2020-07-13 13:12:32 +02:00
|
|
|
})
|
2020-07-13 12:29:11 +02:00
|
|
|
t.Run("state, country, month and year", func(t *testing.T) {
|
|
|
|
moment := Moment{
|
|
|
|
Label: "",
|
|
|
|
Country: "de",
|
|
|
|
State: "Pfalz",
|
|
|
|
Year: 2010,
|
|
|
|
Month: 12,
|
|
|
|
PhotoCount: 0,
|
|
|
|
}
|
|
|
|
|
2021-11-18 13:13:48 +01:00
|
|
|
assert.Equal(t, "Pfalz / December 2010", moment.Title())
|
2020-07-13 12:29:11 +02:00
|
|
|
})
|
|
|
|
t.Run("month", func(t *testing.T) {
|
|
|
|
moment := Moment{
|
|
|
|
Label: "",
|
|
|
|
Country: "",
|
|
|
|
State: "",
|
|
|
|
Year: 0,
|
2020-07-13 13:12:32 +02:00
|
|
|
Month: 12,
|
2020-07-13 12:29:11 +02:00
|
|
|
PhotoCount: 0,
|
|
|
|
}
|
|
|
|
|
2020-07-13 13:12:32 +02:00
|
|
|
assert.Equal(t, "December", moment.Title())
|
2020-07-13 12:29:11 +02:00
|
|
|
})
|
|
|
|
}
|
2021-11-24 17:51:39 +01:00
|
|
|
|
|
|
|
func TestRemoveDuplicateMoments(t *testing.T) {
|
|
|
|
t.Run("Success", func(t *testing.T) {
|
|
|
|
if removed, err := RemoveDuplicateMoments(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
|
|
|
t.Logf("moments: removed %s", english.Plural(removed, "duplicate", "duplicates"))
|
2022-03-28 12:14:05 +02:00
|
|
|
|
|
|
|
// TODO: Needs review, variable number of results.
|
|
|
|
assert.GreaterOrEqual(t, removed, 1)
|
2021-11-24 17:51:39 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|