mirror of
https://github.com/larksuite/cli.git
synced 2026-09-14 18:42:53 +08:00
2a1613484a
* feat: add framework flag aliases and unified IM pagination Introduce declarative exact-name flag aliases at the shortcut framework boundary while keeping semantic compatibility domain-owned. Add a shared, format-aware IM pagination pipeline with consistent flags, metadata, safety bounds, resumable cursors, and request throttling. * fix: align alias attribution and pagination contracts * fix: align alias contracts and documentation * test: remove environment-dependent contact bot e2e * test: restore contact bot e2e * docs: reduce IM pagination guidance noise --------- Co-authored-by: liangshuo-1 <266696938+liangshuo-1@users.noreply.github.com>
79 lines
2.9 KiB
Go
79 lines
2.9 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package mail
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
clie2e "github.com/larksuite/cli/tests/cli_e2e"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestMail_TriageDryRunPreservesMailboxInRequestChain(t *testing.T) {
|
|
setMailTriageDryRunEnv(t)
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
t.Cleanup(cancel)
|
|
|
|
result, err := clie2e.RunCmd(ctx, clie2e.Request{
|
|
Args: []string{
|
|
"mail", "+triage",
|
|
"--mailbox", "alias@example.com",
|
|
"--filter", `{"folder_id":"INBOX"}`,
|
|
"--max", "3",
|
|
"--dry-run",
|
|
},
|
|
DefaultAs: "user",
|
|
})
|
|
require.NoError(t, err)
|
|
result.AssertExitCode(t, 0)
|
|
|
|
require.Equal(t, int64(2), clie2e.DryRunGet(result.Stdout, "api.#").Int(), "stdout:\n%s", result.Stdout)
|
|
require.Equal(t, "GET", clie2e.DryRunGet(result.Stdout, "api.0.method").String(), "stdout:\n%s", result.Stdout)
|
|
require.Equal(t, "/open-apis/mail/v1/user_mailboxes/alias@example.com/messages", clie2e.DryRunGet(result.Stdout, "api.0.url").String(), "stdout:\n%s", result.Stdout)
|
|
require.Equal(t, int64(3), clie2e.DryRunGet(result.Stdout, "api.0.params.page_size").Int(), "stdout:\n%s", result.Stdout)
|
|
require.Equal(t, "INBOX", clie2e.DryRunGet(result.Stdout, "api.0.params.folder_id").String(), "stdout:\n%s", result.Stdout)
|
|
|
|
require.Equal(t, "POST", clie2e.DryRunGet(result.Stdout, "api.1.method").String(), "stdout:\n%s", result.Stdout)
|
|
require.Equal(t, "/open-apis/mail/v1/user_mailboxes/alias@example.com/messages/batch_get", clie2e.DryRunGet(result.Stdout, "api.1.url").String(), "stdout:\n%s", result.Stdout)
|
|
require.Equal(t, "metadata", clie2e.DryRunGet(result.Stdout, "api.1.body.format").String(), "stdout:\n%s", result.Stdout)
|
|
}
|
|
|
|
func TestMail_TriageDryRunUsesPageSizeAsExactMaxAlias(t *testing.T) {
|
|
setMailTriageDryRunEnv(t)
|
|
|
|
tests := []struct {
|
|
name string
|
|
args []string
|
|
want int64
|
|
}{
|
|
{name: "alias only", args: []string{"--page-size", "5"}, want: 5},
|
|
{name: "alias last", args: []string{"--max", "7", "--page-size", "5"}, want: 5},
|
|
{name: "canonical last", args: []string{"--page-size", "5", "--max", "7"}, want: 7},
|
|
}
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
t.Cleanup(cancel)
|
|
args := []string{"mail", "+triage", "--mailbox", "me"}
|
|
args = append(args, test.args...)
|
|
args = append(args, "--dry-run")
|
|
result, err := clie2e.RunCmd(ctx, clie2e.Request{Args: args, DefaultAs: "user"})
|
|
require.NoError(t, err)
|
|
result.AssertExitCode(t, 0)
|
|
require.Equal(t, test.want, clie2e.DryRunGet(result.Stdout, "api.0.params.page_size").Int(), result.Stdout)
|
|
})
|
|
}
|
|
}
|
|
|
|
func setMailTriageDryRunEnv(t *testing.T) {
|
|
t.Helper()
|
|
t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir())
|
|
t.Setenv("LARKSUITE_CLI_APP_ID", "mail_triage_dryrun_test")
|
|
t.Setenv("LARKSUITE_CLI_APP_SECRET", "mail_triage_dryrun_secret")
|
|
t.Setenv("LARKSUITE_CLI_BRAND", "feishu")
|
|
}
|