From 3f0e75ea0a81f085afb72bf8a2b39fa8fa53126d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=91=9E=E8=BE=BE?= Date: Tue, 18 Aug 2026 21:46:48 +0800 Subject: [PATCH] test(todo): cover validation branches --- internal/shortcut/smart/assign.go | 4 --- internal/shortcut/smart/remind.go | 3 --- ...additional_cross_platform_coverage_test.go | 21 ++++++++++++++- ...additional_cross_platform_coverage_test.go | 26 +++++++++++-------- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/internal/shortcut/smart/assign.go b/internal/shortcut/smart/assign.go index df5ee361..a8b4a7a9 100644 --- a/internal/shortcut/smart/assign.go +++ b/internal/shortcut/smart/assign.go @@ -19,7 +19,6 @@ import ( "github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/corecmd" "github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/corecmd/contract" - apperrors "github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/errors" "github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/output" "github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/shortcut" todoshortcut "github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/shortcut/todo" @@ -77,9 +76,6 @@ var Assign = shortcut.Shortcut{ Execute: func(rt *shortcut.RuntimeContext) error { name := strings.TrimSpace(rt.Str("to")) task := strings.TrimSpace(rt.Str("task")) - if name == "" || task == "" { - return apperrors.NewValidation("--to 与 --task 均不能为空") - } var dueMillis int64 if rt.Changed("due") { var err error diff --git a/internal/shortcut/smart/remind.go b/internal/shortcut/smart/remind.go index 5282842b..9c447622 100644 --- a/internal/shortcut/smart/remind.go +++ b/internal/shortcut/smart/remind.go @@ -84,9 +84,6 @@ var Remind = shortcut.Shortcut{ Tips: []string{`dws todo +remind --task "交周报" --at 2026-03-10T18:00:00+08:00`}, Execute: func(rt *shortcut.RuntimeContext) error { task := strings.TrimSpace(rt.Str("task")) - if task == "" { - return apperrors.NewValidation("--task 不能为空") - } var dueMillis int64 if rt.Changed("at") { var err error diff --git a/internal/shortcut/smart/shortcut_additional_cross_platform_coverage_test.go b/internal/shortcut/smart/shortcut_additional_cross_platform_coverage_test.go index 5b924a1c..392ffe23 100644 --- a/internal/shortcut/smart/shortcut_additional_cross_platform_coverage_test.go +++ b/internal/shortcut/smart/shortcut_additional_cross_platform_coverage_test.go @@ -177,17 +177,32 @@ func TestCrossPlatformCoverageCalendarSmartReadCommands(t *testing.T) { } func TestCrossPlatformCoverageTodoSmartWriteBranches(t *testing.T) { + for name, args := range map[string][]string{ + "assign-empty-task": {"todo", "+assign", "--task", " ", "--to", "fixture person", "--yes"}, + "assign-bad-due": {"todo", "+assign", "--task", "task", "--to", "fixture person", "--due", "tomorrow", "--yes"}, + "remind-empty-task": {"todo", "+remind", "--task", " ", "--yes"}, + } { + t.Run(name, func(t *testing.T) { + if _, _, err := runCalendarSmartCLI(t, &calendarSmartTestCaller{}, args...); err == nil { + t.Fatal("invalid todo shortcut arguments accepted") + } + }) + } + assignDry := &calendarSmartTestCaller{steps: map[string][]calendarSmartTestStep{"contact/search_contact_by_key_word": {{text: smartContact().text}}}} if _, _, err := runCalendarSmartCLI(t, assignDry, "todo", "+assign", "--task", "task", "--to", "fixture person", "--due", smartCoverageEnd, "--dry-run", "--yes"); err != nil { t.Fatal(err) } + if _, _, err := runCalendarSmartCLI(t, &calendarSmartTestCaller{}, "todo", "+assign", "--task", "task", "--to", "fixture person", "--yes"); err == nil { + t.Fatal("assign contact resolution failure accepted") + } for name, responses := range map[string]map[string][]calendarSmartTestStep{ "call": {"contact/search_contact_by_key_word": {{text: smartContact().text}}, "todo/create_personal_todo": {{err: errors.New("write")}}}, "verify": {"contact/search_contact_by_key_word": {{text: smartContact().text}}, "todo/create_personal_todo": {{text: `{"result":{}}`}}}, "success": {"contact/search_contact_by_key_word": {{text: smartContact().text}}, "todo/create_personal_todo": {{text: `{"success":true,"result":{"taskId":"task-placeholder"}}`}}, "todo/get_todo_detail": {{text: `{"success":true,"result":{"todoDetailModel":{"taskId":"task-placeholder","subject":"task"}}}`}}}, } { t.Run("assign-"+name, func(t *testing.T) { - _, _, err := runCalendarSmartCLI(t, &calendarSmartTestCaller{steps: responses}, "todo", "+assign", "--task", "task", "--to", "fixture person", "--yes") + _, _, err := runCalendarSmartCLI(t, &calendarSmartTestCaller{steps: responses}, "todo", "+assign", "--task", "task", "--to", "fixture person", "--due", smartCoverageEnd, "--yes") if name == "success" { if err != nil { t.Fatal(err) @@ -232,6 +247,10 @@ func TestCrossPlatformCoverageTodoSmartWriteBranches(t *testing.T) { if _, _, err := runCalendarSmartCLI(t, remindDry, "todo", "+remind", "--task", "task", "--at", smartCoverageEnd, "--dry-run", "--yes"); err != nil { t.Fatal(err) } + remindProfileFailure := &calendarSmartTestCaller{steps: map[string][]calendarSmartTestStep{"contact/get_current_user_profile": {{err: errors.New("profile")}}}} + if _, _, err := runCalendarSmartCLI(t, remindProfileFailure, "todo", "+remind", "--task", "task", "--yes"); err == nil { + t.Fatal("remind profile failure accepted") + } remindSuccess := &calendarSmartTestCaller{steps: map[string][]calendarSmartTestStep{"contact/get_current_user_profile": {{text: `{"result":{"userId":"user-placeholder"}}`}}, "todo/create_personal_todo": {{text: `{"success":true,"result":{"taskId":"task-placeholder"}}`}}, "todo/get_todo_detail": {{text: `{"success":true,"result":{"todoDetailModel":{"taskId":"task-placeholder","subject":"task"}}}`}}}} if _, _, err := runCalendarSmartCLI(t, remindSuccess, "todo", "+remind", "--task", "task", "--yes"); err != nil { t.Fatal(err) diff --git a/internal/shortcut/todo/todo_additional_cross_platform_coverage_test.go b/internal/shortcut/todo/todo_additional_cross_platform_coverage_test.go index 47d46685..f04f7c85 100644 --- a/internal/shortcut/todo/todo_additional_cross_platform_coverage_test.go +++ b/internal/shortcut/todo/todo_additional_cross_platform_coverage_test.go @@ -91,7 +91,7 @@ func TestCrossPlatformCoverageTodoCommonStrictBranches(t *testing.T) { if _, err := requireTodoResponse(map[string]any{"result": map[string]any{}}, "todo/test"); err != nil { t.Fatalf("response without optional success rejected: %v", err) } - for _, response := range []map[string]any{{}, {"result": map[string]any{}}, {"success": false}} { + for _, response := range []map[string]any{{}, {"result": map[string]any{}}, {"success": "yes"}, {"success": false}} { if err := requireTodoWriteReceipt(response, "todo/test"); err == nil { t.Fatalf("bad receipt accepted: %#v", response) } @@ -431,11 +431,14 @@ func TestCrossPlatformCoverageTodoCommentAndReminder(t *testing.T) { } for name, args := range map[string][]string{ - "none": {"--task-id", "task-1", "--yes"}, - "both": {"--task-id", "task-1", "--clear", "--base-time", "dueTime", "--yes"}, - "due-offset": {"--task-id", "task-1", "--base-time", "dueTime", "--yes"}, - "custom-at": {"--task-id", "task-1", "--base-time", "customTime", "--yes"}, - "custom-value": {"--task-id", "task-1", "--base-time", "customTime", "--at", "bad", "--yes"}, + "none": {"--task-id", "task-1", "--yes"}, + "both": {"--task-id", "task-1", "--clear", "--base-time", "dueTime", "--yes"}, + "clear-offset": {"--task-id", "task-1", "--clear", "--due-date-offset", "-30", "--yes"}, + "due-offset": {"--task-id", "task-1", "--base-time", "dueTime", "--yes"}, + "due-at": {"--task-id", "task-1", "--base-time", "dueTime", "--due-date-offset", "-30", "--at", todoCoverageTime, "--yes"}, + "custom-at": {"--task-id", "task-1", "--base-time", "customTime", "--yes"}, + "custom-offset": {"--task-id", "task-1", "--base-time", "customTime", "--at", todoCoverageTime, "--due-date-offset", "-30", "--yes"}, + "custom-value": {"--task-id", "task-1", "--base-time", "customTime", "--at", "bad", "--yes"}, } { t.Run("reminder-"+name, func(t *testing.T) { if err := runTodoCoverage(t, Reminder, &todoCoverageCaller{responses: map[string][]string{}}, args...); err == nil { @@ -542,11 +545,12 @@ func TestCrossPlatformCoverageTodoVerificationHelpers(t *testing.T) { func TestCrossPlatformCoverageTodoGetMyTasksAndListLeaves(t *testing.T) { for name, args := range map[string][]string{ - "page": {"--page", "0"}, - "size": {"--size", "21"}, - "priority": {"--priority", "11"}, - "role": {"--role-types", "owner"}, - "max": {"--all", "--max-pages", "0"}, + "page": {"--page", "0"}, + "size": {"--size", "21"}, + "priority": {"--priority", "11"}, + "role": {"--role-types", "owner"}, + "max": {"--all", "--max-pages", "0"}, + "max-alone": {"--max-pages", "1"}, } { t.Run(name, func(t *testing.T) { if err := runTodoCoverage(t, GetMyTasks, &todoCoverageCaller{responses: map[string][]string{}}, args...); err == nil {