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
11 changes: 11 additions & 0 deletions shortcuts/base/base_execute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ func runShortcutWithAuthTypes(t *testing.T, shortcut common.Shortcut, authTypes
parent.SilenceErrors = true
parent.SilenceUsage = true
stdout.Reset()
if stderr, ok := factory.IOStreams.ErrOut.(*bytes.Buffer); ok {
stderr.Reset()
}
return parent.ExecuteContext(context.Background())
}

func TestBaseWorkspaceExecuteCreate(t *testing.T) {
factory, stdout, reg := newExecuteFactory(t)
stderr, _ := factory.IOStreams.ErrOut.(*bytes.Buffer)
permStub := &httpmock.Stub{
Method: "POST",
URL: "/open-apis/drive/v1/permissions/app_x/members?need_notification=false&type=bitable",
Expand All @@ -96,6 +100,9 @@ func TestBaseWorkspaceExecuteCreate(t *testing.T) {
if data["created"] != true {
t.Fatalf("created = %#v, want true", data["created"])
}
if !strings.Contains(stderr.String(), baseCreateHint) {
t.Fatalf("stderr = %q, want %q", stderr.String(), baseCreateHint)
}
base, _ := data["base"].(map[string]interface{})
if got := common.GetString(base, "app_token"); got != "app_x" {
t.Fatalf("base.app_token = %q, want %q", got, "app_x")
Expand Down Expand Up @@ -184,6 +191,7 @@ func TestBaseWorkspaceExecuteGetAndCopy(t *testing.T) {

func TestBaseWorkspaceExecuteCreateBotAutoGrantSkippedWithoutCurrentUser(t *testing.T) {
factory, stdout, reg := newExecuteFactoryWithUserOpenID(t, "")
stderr, _ := factory.IOStreams.ErrOut.(*bytes.Buffer)
reg.Register(&httpmock.Stub{
Method: "POST",
URL: "/open-apis/base/v3/bases",
Expand All @@ -198,6 +206,9 @@ func TestBaseWorkspaceExecuteCreateBotAutoGrantSkippedWithoutCurrentUser(t *test
}

data := decodeBaseEnvelope(t, stdout)
if !strings.Contains(stderr.String(), baseCreateHint) {
t.Fatalf("stderr = %q, want %q", stderr.String(), baseCreateHint)
}
grant, _ := data["permission_grant"].(map[string]interface{})
if grant["status"] != common.PermissionGrantSkipped {
t.Fatalf("permission_grant.status = %#v, want %q", grant["status"], common.PermissionGrantSkipped)
Expand Down
4 changes: 4 additions & 0 deletions shortcuts/base/base_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ package base

import (
"context"
"fmt"
"strings"

"github.com/larksuite/cli/shortcuts/common"
)

const baseCreateHint = "Tip: New bases include a default empty table with 5-10 blank records. After finishing table/field setup on this base, ask whether to delete that default table. If yes, run +table-list first, then delete the default table."

func dryRunBaseGet(_ context.Context, runtime *common.RuntimeContext) *common.DryRunAPI {
return common.NewDryRunAPI().
GET("/open-apis/base/v3/bases/:base_token").
Expand Down Expand Up @@ -65,6 +68,7 @@ func executeBaseCreate(runtime *common.RuntimeContext) error {
out := map[string]interface{}{"base": data, "created": true}
augmentBasePermissionGrant(runtime, out, data)
runtime.Out(out, nil)
fmt.Fprintln(runtime.IO().ErrOut, baseCreateHint)
return nil
}

Expand Down
Loading