-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema_test.go
67 lines (48 loc) · 1.51 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
package main
import (
"testing"
)
func TestNewSchema(t *testing.T) {
schema := NewSchema("test")
if schema.name != "test" {
t.Error("expected schema to be named 'test'")
}
}
func TestAddEntry(t *testing.T) {
schema := NewSchema("test")
schema.addEntry("fieldName", "yup.bool()")
if len(schema.Fields) < 1 {
t.Error("failed to find any fields after call to 'addEntry'")
}
}
func TestName(t *testing.T) {
schema := NewSchema("test")
if schema.Name() != "testSchema" {
t.Error("expected Schema.Name() to return 'testSchema'")
}
}
func TestFilename(t *testing.T) {
schema := NewSchema("test")
if schema.Filename(true) != "test_schema.js" {
t.Error("expected Schema.Filename() to return 'test_schema.js'")
}
if schema.Filename(false) != "TestSchema.js" {
t.Error("expected Schema.Filename() to return 'TestSchema.js'")
}
}
func TestToJS(t *testing.T) {
schema := NewSchema("test")
schema.addEntry("fieldName", "yup.bool()")
expected := "const testSchema = yup.object({\n\tfieldName: yup.bool(),\n})\n"
if expected != schema.ToJS(Yup()) {
t.Errorf("failed to match \nwant=%s\nhave=%s", expected, schema.ToJS(Yup()))
}
}
func TestToJSFile(t *testing.T) {
schema := NewSchema("test")
schema.addEntry("fieldName", "yup.bool()")
expected := "import * as yup from 'yup';\n\nconst testSchema = yup.object({\n\tfieldName: yup.bool(),\n})\n\nexport default testSchema;\n"
if expected != schema.ToJSFile(Yup()) {
t.Errorf("failed to match \nwant=%s\nhave=%s", expected, schema.ToJSFile(Yup()))
}
}