chore: import upstream snapshot with attribution
CI / license-header (push) Has been skipped
CI / e2e-dry-run (push) Has been skipped
CI / fast-gate (push) Failing after 0s
Test PR Label Logic / test-pr-labels (push) Failing after 1s
Skill Format Check / check-format (push) Failing after 2s
CI / security (push) Failing after 5s
CI / unit-test (push) Has been skipped
CI / lint (push) Has been skipped
CI / script-test (push) Has been skipped
CI / deterministic-gate (push) Has been skipped
CI / coverage (push) Has been skipped
CI / results (push) Has been cancelled
CI / deadcode (push) Has been cancelled
CI / e2e-live (push) Has been cancelled
CI / license-header (push) Has been skipped
CI / e2e-dry-run (push) Has been skipped
CI / fast-gate (push) Failing after 0s
Test PR Label Logic / test-pr-labels (push) Failing after 1s
Skill Format Check / check-format (push) Failing after 2s
CI / security (push) Failing after 5s
CI / unit-test (push) Has been skipped
CI / lint (push) Has been skipped
CI / script-test (push) Has been skipped
CI / deterministic-gate (push) Has been skipped
CI / coverage (push) Has been skipped
CI / results (push) Has been cancelled
CI / deadcode (push) Has been cancelled
CI / e2e-live (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package task
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/larksuite/cli/internal/httpmock"
|
||||
)
|
||||
|
||||
func TestCompleteTask(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
taskId string
|
||||
isCompleted bool
|
||||
formatFlag string
|
||||
expectedOutput []string
|
||||
}{
|
||||
{
|
||||
name: "task already completed",
|
||||
taskId: "task-123",
|
||||
isCompleted: true,
|
||||
formatFlag: "pretty",
|
||||
expectedOutput: []string{
|
||||
"✅ Task completed successfully!",
|
||||
"Task ID: task-123",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "task not completed",
|
||||
taskId: "task-456",
|
||||
isCompleted: false,
|
||||
formatFlag: "pretty",
|
||||
expectedOutput: []string{
|
||||
"✅ Task completed successfully!",
|
||||
"Task ID: task-456",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "task not completed json format",
|
||||
taskId: "task-789",
|
||||
isCompleted: false,
|
||||
formatFlag: "json",
|
||||
expectedOutput: []string{
|
||||
`"guid": "task-789"`,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
f, stdout, _, reg := taskShortcutTestFactory(t)
|
||||
warmTenantToken(t, f, reg)
|
||||
|
||||
completedAt := "0"
|
||||
if tt.isCompleted {
|
||||
completedAt = "1775174400000"
|
||||
}
|
||||
|
||||
reg.Register(&httpmock.Stub{
|
||||
Method: "GET",
|
||||
URL: "/open-apis/task/v2/tasks/" + tt.taskId,
|
||||
Body: map[string]interface{}{
|
||||
"code": 0, "msg": "success",
|
||||
"data": map[string]interface{}{
|
||||
"task": map[string]interface{}{
|
||||
"guid": tt.taskId,
|
||||
"summary": "Test Task " + tt.taskId,
|
||||
"completed_at": completedAt,
|
||||
"url": "https://example.com/" + tt.taskId,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if !tt.isCompleted {
|
||||
reg.Register(&httpmock.Stub{
|
||||
Method: "PATCH",
|
||||
URL: "/open-apis/task/v2/tasks/" + tt.taskId,
|
||||
Body: map[string]interface{}{
|
||||
"code": 0, "msg": "success",
|
||||
"data": map[string]interface{}{
|
||||
"task": map[string]interface{}{
|
||||
"guid": tt.taskId,
|
||||
"summary": "Test Task " + tt.taskId,
|
||||
"completed_at": "1775174400000",
|
||||
"url": "https://example.com/" + tt.taskId,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
err := runMountedTaskShortcut(t, CompleteTask, []string{"+complete", "--task-id", tt.taskId, "--format", tt.formatFlag, "--as", "bot"}, f, stdout)
|
||||
if err != nil {
|
||||
t.Fatalf("expected no error, got %v", err)
|
||||
}
|
||||
|
||||
out := stdout.String()
|
||||
outNorm := strings.ReplaceAll(out, `":"`, `": "`)
|
||||
|
||||
for _, expected := range tt.expectedOutput {
|
||||
if !strings.Contains(outNorm, expected) && !strings.Contains(out, expected) {
|
||||
t.Errorf("output missing expected string (%s), got: %s", expected, out)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user