1
Fork 0

TODO: mutations test. Thumbnail resolver test working?

This commit is contained in:
Peter - Ubuntu dual boot 2021-09-20 14:13:21 +01:00
parent d636b57c4c
commit 82f4785f2b
1 changed files with 59 additions and 72 deletions

View File

@ -12,10 +12,10 @@ import (
// "github.com/pkg/errors" // "github.com/pkg/errors"
// "gorm.io/gorm" // "gorm.io/gorm"
"github.com/99designs/gqlgen/client"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/photoview/photoview/api/test_utils" "github.com/photoview/photoview/api/test_utils"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/client"
) )
// func NewResolver() api.Config { // func NewResolver() api.Config {
@ -73,22 +73,22 @@ func TestAlbumCover(t *testing.T) {
}, },
{ {
Title: "pic3", Title: "pic3",
Path: "/photos/pic3", Path: "/photos/child1/pic3",
AlbumID: 2, AlbumID: 2,
}, },
{ {
Title: "pic4", Title: "pic4",
Path: "/photos/pic4", Path: "/photos/child1/pic4",
AlbumID: 2, AlbumID: 2,
}, },
{ {
Title: "pic5", Title: "pic5",
Path: "/photos/pic5", Path: "/photos/child2/pic5",
AlbumID: 3, AlbumID: 3,
}, },
{ {
Title: "pic6", Title: "pic6",
Path: "/photos/pic6", Path: "/photos/child2/pic6",
AlbumID: 3, AlbumID: 3,
}, },
} }
@ -97,79 +97,66 @@ func TestAlbumCover(t *testing.T) {
return return
} }
// verifyResult := func(t *testing.T, expected_albums []*models.Album, result []*models.Album) { verifyResult := func(t *testing.T, expected_media []*models.Media, result []*models.Media) {
// assert.Equal(t, len(expected_albums), len(result)) assert.Equal(t, len(expected_media), len(result))
for _, expected := range expected_media {
found_expected := false
for _, item := range result {
if item.Title == expected.Title && item.Path == expected.Path && item.AlbumID == expected.AlbumID {
found_expected = true
break
}
}
if !found_expected {
assert.Failf(t, "media did not match", "expected to find item: %v", expected)
}
}
}
// //
// for _, expected := range expected_albums {
// found_expected := false
// for _, item := range result {
// if item.Title == expected.Title && item.Path == expected.Path {
// found_expected = true
// break
// }
// }
// if !found_expected {
// assert.Failf(t, "albums did not match", "expected to find item: %v", expected)
// }
// }
// }
// //
c := client.New(handler.NewDefaultServer(api.NewExecutableSchema(api.Config{Resolvers: &resolvers.Resolver{ c := client.New(handler.NewDefaultServer(api.NewExecutableSchema(api.Config{Resolvers: &resolvers.Resolver{
Database: db, Database: db,
}}))) }})))
// t.Run("Album get cover photos", func(t *testing.T) { t.Run("Album get cover photos", func(t *testing.T) {
// root_children, err := rootAlbum.GetChildren(db, nil)
// if !assert.NoError(t, err) {
// return
// }
//
// expected_children := []*models.Album{
// {
// Title: "root",
// Path: "/photos",
// },
// {
// Title: "child1",
// Path: "/photos/child1",
// },
// {
// Title: "child2",
// Path: "/photos/child2",
// },
// {
// Title: "subchild",
// Path: "/photos/child1/subchild",
// },
// }
//
// verifyResult(t, expected_children, root_children)
// })
// t.Run("Album get parents", func(t *testing.T) { var resp []*models.Media
// parents, err := sub_child.GetParents(db, nil)
// if !assert.NoError(t, err) { c.MustPost(`query { Thumbnail( album(id:1)) {
// return Title, Path, AlbumID
// } }}`, &resp[0])
// c.MustPost(`query { Thumbnail( album(id:1)) {
// expected_parents := []*models.Album{ Title, Path, AlbumID
// { }}`, &resp[1])
// Title: "root", c.MustPost(`query { Thumbnail( album(id:1)) {
// Path: "/photos", Title, Path, AlbumID
// }, }}`, &resp[2])
// {
// Title: "child1",
// Path: "/photos/child1",
// }, expected_thumbnails := []*models.Media{
// { {
// Title: "subchild", Title: "pic1",
// Path: "/photos/child1/subchild", Path: "/photos/pic1",
// }, AlbumID: 1,
// } },
// {
// verifyResult(t, expected_parents, parents) Title: "pic3",
// }) Path: "/photos/child1/pic3",
AlbumID: 2,
},
{
Title: "pic6",
Path: "/photos/child2/pic6",
AlbumID: 3,
},
}
verifyResult(t, expected_thumbnails, resp)
})
} }