-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: expand folder one level in message content with children_count hint #2560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
yjhcjykwbk-jlsec
wants to merge
3
commits into
larksuite:main
from
yjhcjykwbk-jlsec:feat/im-folder-children
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
71458c3
feat: expand folder one level in message content with children_count …
jackie3927 70f3b62
fix: folder children 路径加 folder 语义 /resources/folder/:file_key/children
jackie3927 0849b2f
feat: folder expand via /files/:file_key/folder (11050 endpoint) with…
jackie3927 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package convertlib | ||
|
|
||
| // C4-C6:fetchFolderChildrenTree 单测(mock httpmock,不依赖真实 openapi) | ||
| // 覆盖 XML 一层输出(folder name+key+child_count / file name+key / 子文件夹 child_count / has_more) | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/larksuite/cli/internal/core" | ||
| "github.com/larksuite/cli/internal/httpmock" | ||
| "github.com/larksuite/cli/internal/cmdutil" | ||
| "github.com/larksuite/cli/shortcuts/common" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func folderTestRuntime(t *testing.T) (*common.RuntimeContext, *httpmock.Registry) { | ||
| t.Helper() | ||
| cfg := &core.CliConfig{Brand: core.BrandFeishu, AppID: "cli_x"} | ||
| f, _, _, reg := cmdutil.TestFactory(t, cfg) | ||
| rt := common.TestNewRuntimeContextForAPI(context.Background(), &cobra.Command{Use: "+x"}, cfg, f, core.AsUser) | ||
| return rt, reg | ||
| } | ||
|
|
||
| // C4:正常展开一层(文件 + 子文件夹 + child_count),无 has_more(items == all_count) | ||
| func TestFetchFolderChildrenTree_XMLOneLevel(t *testing.T) { | ||
| rt, reg := folderTestRuntime(t) | ||
| reg.Register(&httpmock.Stub{ | ||
| Method: "GET", | ||
| URL: "/open-apis/im/v1/files/fld_root/folder", | ||
| Body: map[string]interface{}{ | ||
| "code": 0, | ||
| "data": map[string]interface{}{ | ||
| "items": []interface{}{ | ||
| map[string]interface{}{"file_key": "f1", "name": "报告.pdf", "is_folder": false}, | ||
| map[string]interface{}{"file_key": "f2", "name": "文档.docx", "is_folder": false}, | ||
| map[string]interface{}{"file_key": "f3", "name": "子文件夹", "is_folder": true, "children_count": float64(3)}, | ||
| }, | ||
| "all_count": float64(3), | ||
| }, | ||
| }, | ||
| }) | ||
| got := fetchFolderChildrenTree(rt, "fld_root", "tmpavatra", "om_123") | ||
| want := `<folder name="tmpavatra" key="fld_root" child_count="3"><file name="报告.pdf" key="f1"/><file name="文档.docx" key="f2"/><folder name="子文件夹" key="f3" child_count="3"/></folder>` | ||
| if got != want { | ||
| t.Fatalf("fetchFolderChildrenTree() = %q, want %q", got, want) | ||
| } | ||
| } | ||
|
|
||
| // C4b:items < all_count 时根 folder 带 has_more="true" | ||
| func TestFetchFolderChildrenTree_HasMore(t *testing.T) { | ||
| rt, reg := folderTestRuntime(t) | ||
| reg.Register(&httpmock.Stub{ | ||
| Method: "GET", | ||
| URL: "/open-apis/im/v1/files/fld_root/folder", | ||
| Body: map[string]interface{}{ | ||
| "code": 0, | ||
| "data": map[string]interface{}{ | ||
| "items": []interface{}{ | ||
| map[string]interface{}{"file_key": "f1", "name": "a.pdf", "is_folder": false}, | ||
| }, | ||
| "all_count": float64(100), | ||
| }, | ||
| }, | ||
| }) | ||
| got := fetchFolderChildrenTree(rt, "fld_root", "big", "om_123") | ||
| want := `<folder name="big" key="fld_root" child_count="100" has_more="true"><file name="a.pdf" key="f1"/></folder>` | ||
| if got != want { | ||
| t.Fatalf("fetchFolderChildrenTree() = %q, want %q", got, want) | ||
| } | ||
| } | ||
|
|
||
| // C5:API 失败(error/nil)→ 返回空串(调用方降级旧输出) | ||
| func TestFetchFolderChildrenTree_APIFailure(t *testing.T) { | ||
| rt, reg := folderTestRuntime(t) | ||
| // 不注册 stub → httpmock 返回错误 | ||
| got := fetchFolderChildrenTree(rt, "fld_root", "x", "om_123") | ||
| if got != "" { | ||
| t.Fatalf("fetchFolderChildrenTree() on API failure = %q, want empty (caller downgrades)", got) | ||
| } | ||
| _ = reg | ||
| } | ||
|
|
||
| // C6:items 空 → 返回空串(降级) | ||
| func TestFetchFolderChildrenTree_EmptyItems(t *testing.T) { | ||
| rt, reg := folderTestRuntime(t) | ||
| reg.Register(&httpmock.Stub{ | ||
| Method: "GET", | ||
| URL: "/open-apis/im/v1/files/fld_root/folder", | ||
| Body: map[string]interface{}{ | ||
| "code": 0, | ||
| "data": map[string]interface{}{ | ||
| "items": []interface{}{}, | ||
| "all_count": float64(0), | ||
| }, | ||
| }, | ||
| }) | ||
| got := fetchFolderChildrenTree(rt, "fld_root", "x", "om_123") | ||
| if got != "" { | ||
| t.Fatalf("fetchFolderChildrenTree() empty items = %q, want empty", got) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Assert the request query parameters.
These stubs specify only the HTTP method and path. They do not assert
srctype=message,srcid=om_123, orrecursive=false. A regression in the one-level request contract could still return the same fixture and pass the XML assertions. Match the query or assert the recorded request in both tests.As per coding guidelines, every behavior change requires a nearby regression test that fails when the implementation is reverted, and tests must assert requests directly.
Also applies to: 53-55
🤖 Prompt for AI Agents
Source: Coding guidelines