Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions shortcuts/base/base_execute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func TestBaseFieldExecuteCRUD(t *testing.T) {
if err := runShortcut(t, BaseFieldList, []string{"+field-list", "--base-token", "app_x", "--table-id", "tbl_x", "--offset", "0", "--limit", "1"}, factory, stdout); err != nil {
t.Fatalf("err=%v", err)
}
if got := stdout.String(); !strings.Contains(got, `"total": 2`) || !strings.Contains(got, `"field_name": "Amount"`) {
if got := stdout.String(); !strings.Contains(got, `"total": 2`) || !strings.Contains(got, `"fields"`) || !strings.Contains(got, `"name": "Amount"`) || strings.Contains(got, `"items"`) || strings.Contains(got, `"offset"`) || strings.Contains(got, `"limit"`) || strings.Contains(got, `"count"`) || strings.Contains(got, `"field_name": "Amount"`) {
t.Fatalf("stdout=%s", got)
}
})
Expand Down Expand Up @@ -427,7 +427,7 @@ func TestBaseTableExecuteReadAndDelete(t *testing.T) {
if err := runShortcut(t, BaseTableGet, []string{"+table-get", "--base-token", "app_x", "--table-id", "tbl_x"}, factory, stdout); err != nil {
t.Fatalf("err=%v", err)
}
if got := stdout.String(); !strings.Contains(got, `"name": "Orders"`) || !strings.Contains(got, `"primary_field": "fld_x"`) || !strings.Contains(got, `"vew_x"`) {
if got := stdout.String(); !strings.Contains(got, `"name": "Orders"`) || !strings.Contains(got, `"primary_field": "fld_x"`) || !strings.Contains(got, `"id": "fld_x"`) || !strings.Contains(got, `"name": "OrderNo"`) || !strings.Contains(got, `"id": "vew_x"`) || !strings.Contains(got, `"name": "Main"`) || strings.Contains(got, `"field_name": "OrderNo"`) || strings.Contains(got, `"view_name": "Main"`) {
t.Fatalf("stdout=%s", got)
}
})
Expand Down Expand Up @@ -739,7 +739,7 @@ func TestBaseViewExecuteReadCreateDeleteAndFilter(t *testing.T) {
if err := runShortcut(t, BaseViewList, []string{"+view-list", "--base-token", "app_x", "--table-id", "tbl_x", "--offset", "0", "--limit", "1"}, factory, stdout); err != nil {
t.Fatalf("err=%v", err)
}
if got := stdout.String(); !strings.Contains(got, `"total": 3`) || !strings.Contains(got, `"view_name": "Main"`) {
if got := stdout.String(); !strings.Contains(got, `"total": 3`) || !strings.Contains(got, `"views"`) || !strings.Contains(got, `"name": "Main"`) || strings.Contains(got, `"items"`) || strings.Contains(got, `"offset"`) || strings.Contains(got, `"limit"`) || strings.Contains(got, `"count"`) || strings.Contains(got, `"view_name": "Main"`) {
t.Fatalf("stdout=%s", got)
}
})
Expand Down
2 changes: 1 addition & 1 deletion shortcuts/base/field_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func executeFieldList(runtime *common.RuntimeContext) error {
if total == 0 {
total = len(fields)
}
runtime.Out(map[string]interface{}{"items": simplifyFields(fields), "offset": offset, "limit": limit, "count": len(fields), "total": total}, nil)
runtime.Out(map[string]interface{}{"fields": fields, "total": total}, nil)
return nil
}

Expand Down
39 changes: 0 additions & 39 deletions shortcuts/base/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,45 +662,6 @@ func viewName(view map[string]interface{}) string {
return v
}

func viewType(view map[string]interface{}) string {
if v, _ := view["type"].(string); v != "" {
return v
}
v, _ := view["view_type"].(string)
return v
}

func simplifyFields(fields []map[string]interface{}) []interface{} {
items := make([]interface{}, 0, len(fields))
for _, field := range fields {
entry := map[string]interface{}{
"field_id": fieldID(field),
"field_name": fieldName(field),
"type": fieldTypeName(field),
}
if style, ok := field["style"].(map[string]interface{}); ok && len(style) > 0 {
entry["style"] = style
}
if multiple, ok := field["multiple"].(bool); ok {
entry["multiple"] = multiple
}
items = append(items, entry)
}
return items
}

func simplifyViews(views []map[string]interface{}) []interface{} {
items := make([]interface{}, 0, len(views))
for _, view := range views {
items = append(items, map[string]interface{}{
"view_id": viewID(view),
"view_name": viewName(view),
"view_type": viewType(view),
})
}
return items
}

func canonicalValue(v interface{}) string {
switch val := v.(type) {
case nil:
Expand Down
13 changes: 1 addition & 12 deletions shortcuts/base/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func TestRecordAndChunkHelpers(t *testing.T) {
}
}

func TestResolveAndSimplifyHelpers(t *testing.T) {
func TestResolveHelpers(t *testing.T) {
fields := []map[string]interface{}{{"id": "fld_1", "name": "Name", "type": "text"}, {"field_id": "fld_2", "field_name": "Age", "type": "number", "multiple": true}}
tables := []map[string]interface{}{{"id": "tbl_1", "name": "Orders"}}
views := []map[string]interface{}{{"id": "vew_1", "name": "Main", "type": "grid"}}
Expand All @@ -214,14 +214,6 @@ func TestResolveAndSimplifyHelpers(t *testing.T) {
if _, err := resolveViewRef(views, "Missing"); err == nil || !strings.Contains(err.Error(), "not found") {
t.Fatalf("err=%v", err)
}
simplifiedFields := simplifyFields(fields)
if len(simplifiedFields) != 2 {
t.Fatalf("simplifiedFields=%v", simplifiedFields)
}
simplifiedViews := simplifyViews(views)
if len(simplifiedViews) != 1 {
t.Fatalf("simplifiedViews=%v", simplifiedViews)
}
}

func TestFilterAndSortHelpers(t *testing.T) {
Expand Down Expand Up @@ -314,9 +306,6 @@ func TestIdentifierAndValueHelpers(t *testing.T) {
if viewName(map[string]interface{}{"view_name": "Main"}) != "Main" {
t.Fatalf("viewName alt key failed")
}
if viewType(map[string]interface{}{"view_type": "grid"}) != "grid" {
t.Fatalf("viewType alt key failed")
}
if !valueEmpty(nil) || !valueEmpty(" ") || !valueEmpty([]interface{}{}) || !valueEmpty(map[string]interface{}{}) {
t.Fatalf("valueEmpty empty cases failed")
}
Expand Down
4 changes: 2 additions & 2 deletions shortcuts/base/table_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func executeTableGet(runtime *common.RuntimeContext) error {
}
runtime.Out(map[string]interface{}{
"table": table,
"fields": simplifyFields(fields),
"views": simplifyViews(views),
"fields": fields,
"views": views,
}, nil)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion shortcuts/base/view_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func executeViewList(runtime *common.RuntimeContext) error {
if total == 0 {
total = len(views)
}
runtime.Out(map[string]interface{}{"items": simplifyViews(views), "offset": offset, "limit": limit, "count": len(views), "total": total}, nil)
runtime.Out(map[string]interface{}{"views": views, "total": total}, nil)
return nil
}

Expand Down
Loading