mirror of
https://github.com/larksuite/cli.git
synced 2026-07-03 14:02:43 +08:00
fix: return raw base field and view responses (#378)
Co-authored-by: kongenpei <kongenpei@users.noreply.github.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
})
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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"}}
|
||||
@@ -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) {
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user