Add more tests

This commit is contained in:
Deluan 2021-07-18 21:55:11 -04:00 committed by Deluan Quintão
parent 58ee4c60ca
commit 69f71be98a
3 changed files with 14 additions and 6 deletions

View File

@ -3,12 +3,10 @@ package persistence
import (
"context"
"github.com/navidrome/navidrome/log"
"github.com/deluan/rest"
. "github.com/Masterminds/squirrel"
"github.com/astaxie/beego/orm"
"github.com/deluan/rest"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model"
)

View File

@ -5,6 +5,7 @@ import (
"time"
"github.com/Masterminds/squirrel"
"github.com/navidrome/navidrome/model"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
@ -58,7 +59,7 @@ var _ = Describe("Helpers", func() {
e := exists("album", squirrel.Eq{"id": 1})
sql, args, err := e.ToSql()
Expect(sql).To(Equal("exists (select 1 from album where id = ?)"))
Expect(args).To(Equal([]interface{}{1}))
Expect(args).To(ConsistOf(1))
Expect(err).To(BeNil())
})
})
@ -74,4 +75,14 @@ var _ = Describe("Helpers", func() {
Expect(getMostFrequentMbzID(context.TODO(), "1 2 3 4 2", "", "")).To(Equal("2"))
})
})
Describe("getGenres", func() {
It("returns unique genres", func() {
expected := model.Genres{{ID: "1"}, {ID: "2"}, {ID: "3"}, {ID: "5"}, {ID: "4"}}
Expect(getGenres("1 2 3 5 3 2 4 ")).To(Equal(expected))
})
It("returns empty list when there are no genres", func() {
Expect(getGenres("")).To(BeEmpty())
})
})
})

View File

@ -6,7 +6,6 @@ import (
"github.com/astaxie/beego/orm"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/db"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/tests"
. "github.com/onsi/ginkgo"