github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/pkg/sys/it/impl_describe_test.go (about) 1 /* 2 * Copyright (c) 2020-present unTill Pro, Ltd. 3 */ 4 5 package sys_it 6 7 import ( 8 "encoding/json" 9 "strings" 10 "testing" 11 12 "github.com/stretchr/testify/require" 13 "github.com/voedger/voedger/pkg/istructs" 14 it "github.com/voedger/voedger/pkg/vit" 15 ) 16 17 func TestBasicUsage_DescribeSchema(t *testing.T) { 18 require := require.New(t) 19 vit := it.NewVIT(t, &it.SharedConfig_App1) 20 defer vit.TearDown() 21 22 prnApp1 := vit.GetPrincipal(istructs.AppQName_test1_app1, "login") 23 prnApp2 := vit.GetPrincipal(istructs.AppQName_test1_app2, "login") 24 25 t.Run("describe package names", func(t *testing.T) { 26 body := `{"args":{},"elements":[{"fields":["Names"]}]}` 27 namesStr := vit.PostProfile(prnApp1, "q.sys.DescribePackageNames", body).SectionRow()[0].(string) 28 names := strings.Split(namesStr, ",") 29 require.Len(names, 2) 30 require.Contains(names, "sys") 31 require.Contains(names, "app1pkg") 32 }) 33 34 t.Run("describe package", func(t *testing.T) { 35 body := `{"args":{"PackageName":"app2pkg"},"elements":[{"fields":["PackageDesc"]}]}` 36 desc := vit.PostProfile(prnApp2, "q.sys.DescribePackage", body).SectionRow()[0].(string) 37 38 actual := map[string]interface{}{} 39 require.NoError(json.Unmarshal([]byte(desc), &actual)) 40 41 expected := map[string]interface{}{ 42 "Path": "github.com/voedger/voedger/pkg/vit/app2pkg", 43 "Structures": map[string]interface{}{ 44 "app2pkg.test_ws": map[string]interface{}{ 45 "Fields": []interface{}{ 46 map[string]interface{}{ 47 "Data": "sys.QName", 48 "Name": "sys.QName", 49 "Required": true, 50 }, map[string]interface{}{ 51 "Data": "sys.RecordID", 52 "Name": "sys.ID", 53 "Required": true, 54 }, map[string]interface{}{ 55 "Data": "sys.bool", 56 "Name": "sys.IsActive", 57 }, map[string]interface{}{ 58 "Data": "sys.int32", 59 "Name": "IntFld", 60 "Required": true, 61 }, map[string]interface{}{ 62 "Data": "sys.string", 63 "Name": "StrFld", 64 }, 65 }, 66 "Kind": "CDoc", 67 "Singleton": true, 68 }, 69 "app2pkg.doc1": map[string]interface{}{ 70 "Fields": []interface{}{ 71 map[string]interface{}{ 72 "Data": "sys.QName", 73 "Name": "sys.QName", 74 "Required": true, 75 }, map[string]interface{}{ 76 "Data": "sys.RecordID", 77 "Name": "sys.ID", 78 "Required": true, 79 }, map[string]interface{}{ 80 "Data": "sys.bool", 81 "Name": "sys.IsActive", 82 }, 83 }, 84 "Kind": "CDoc", 85 }, 86 }, 87 "Extensions": map[string]interface{}{ 88 "Commands": map[string]interface{}{ 89 "app2pkg.testCmd": map[string]interface{}{ 90 "Engine": "BuiltIn", 91 "Name": "testCmd", 92 }, 93 }, 94 }, 95 } 96 require.EqualValues(expected, actual) 97 }) 98 }