forked from fenos/dqlx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema_test.go
79 lines (60 loc) · 1.48 KB
/
schema_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package dqlx_test
import (
dql "github.com/fenos/dqlx"
"github.com/stretchr/testify/require"
"testing"
)
func Test_Schema_ToDQL(t *testing.T) {
t.Run("add a simple Predicate", func(t *testing.T) {
schema := dql.NewSchema()
schema.Predicate("name", dql.ScalarString)
schema.Predicate("surname", dql.ScalarString)
dqlSchema, err := schema.ToDQL()
expected := dql.Minify(`
name: string .
surname: string .
`)
require.NoError(t, err)
require.Equal(t, expected, dql.Minify(dqlSchema))
})
t.Run("add types and its Predicates to the schema", func(t *testing.T) {
schema := dql.NewSchema()
schema.Type("Author", func(author *dql.TypeBuilder) {
author.String("name")
author.Int("age")
})
dqlSchema, err := schema.ToDQL()
expected := dql.Minify(`
Author.name: string .
Author.age: int .
type Author {
Author.name
Author.age
}
`)
require.NoError(t, err)
require.Equal(t, expected, dql.Minify(dqlSchema))
})
t.Run("should not duplicate Predicates", func(t *testing.T) {
schema := dql.NewSchema()
author := schema.Type("Author", dql.WithTypePrefix(false))
author.String("name")
author.Int("age")
film := schema.Type("Film", dql.WithTypePrefix(false))
film.String("name")
dqlSchema, err := schema.ToDQL()
expected := dql.Minify(`
name: string .
age: int .
type Author {
name
age
}
type Film {
name
}
`)
require.NoError(t, err)
require.Equal(t, expected, dql.Minify(dqlSchema))
})
}