test(msteams): add comprehensive tests for graph-upload module#8964
test(msteams): add comprehensive tests for graph-upload module#8964RajdeepKushwaha5 wants to merge 5 commits intoopenclaw:mainfrom
Conversation
| await expect( | ||
| uploadToSharePoint({ | ||
| buffer: Buffer.from("test"), | ||
| filename: "test.txt", | ||
| tokenProvider, | ||
| siteId: "site-123", | ||
| fetchFn: mockFetch, | ||
| }), | ||
| ).rejects.toThrow("SharePoint upload failed: 500 Internal Server Error"); |
There was a problem hiding this comment.
Incorrect error expectation
uploadToSharePoint includes the response body in its error message (... - ${body}), but this test asserts the message without the trailing - SharePoint is unavailable. With the current implementation in extensions/msteams/src/graph-upload.ts:197-200, this assertion should fail.
| await expect( | |
| uploadToSharePoint({ | |
| buffer: Buffer.from("test"), | |
| filename: "test.txt", | |
| tokenProvider, | |
| siteId: "site-123", | |
| fetchFn: mockFetch, | |
| }), | |
| ).rejects.toThrow("SharePoint upload failed: 500 Internal Server Error"); | |
| ).rejects.toThrow("SharePoint upload failed: 500 Internal Server Error - SharePoint is unavailable"); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/msteams/src/graph-upload.test.ts
Line: 336:344
Comment:
**Incorrect error expectation**
`uploadToSharePoint` includes the response body in its error message (`... - ${body}`), but this test asserts the message without the trailing ` - SharePoint is unavailable`. With the current implementation in `extensions/msteams/src/graph-upload.ts:197-200`, this assertion should fail.
```suggestion
).rejects.toThrow("SharePoint upload failed: 500 Internal Server Error - SharePoint is unavailable");
```
How can I resolve this? If you propose a fix, please make it concise.| await expect( | ||
| getDriveItemProperties({ | ||
| siteId: "site-id", | ||
| itemId: "item-id", | ||
| tokenProvider, | ||
| fetchFn: mockFetch, | ||
| }), | ||
| ).rejects.toThrow("DriveItem response missing required properties"); |
There was a problem hiding this comment.
Mismatched error message
getDriveItemProperties throws "DriveItem response missing required properties (eTag, webDavUrl, or name)" when required fields are absent (extensions/msteams/src/graph-upload.ts:269-271), but this test expects "DriveItem response missing required properties". As written, the assertion won’t match the actual thrown error.
| await expect( | |
| getDriveItemProperties({ | |
| siteId: "site-id", | |
| itemId: "item-id", | |
| tokenProvider, | |
| fetchFn: mockFetch, | |
| }), | |
| ).rejects.toThrow("DriveItem response missing required properties"); | |
| ).rejects.toThrow( | |
| "DriveItem response missing required properties (eTag, webDavUrl, or name)", | |
| ); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/msteams/src/graph-upload.test.ts
Line: 385:392
Comment:
**Mismatched error message**
`getDriveItemProperties` throws `"DriveItem response missing required properties (eTag, webDavUrl, or name)"` when required fields are absent (`extensions/msteams/src/graph-upload.ts:269-271`), but this test expects `"DriveItem response missing required properties"`. As written, the assertion won’t match the actual thrown error.
```suggestion
).rejects.toThrow(
"DriveItem response missing required properties (eTag, webDavUrl, or name)",
);
```
How can I resolve this? If you propose a fix, please make it concise.| await expect( | ||
| getChatMembers({ | ||
| chatId: "chat-123", | ||
| tokenProvider, | ||
| fetchFn: mockFetch, | ||
| }), | ||
| ).rejects.toThrow("Get chat members failed: 403 Forbidden"); | ||
| }); |
There was a problem hiding this comment.
Missing response body in assertion
getChatMembers includes the response body in its thrown error (... - ${body} at extensions/msteams/src/graph-upload.ts:296-299), but this test expects only "Get chat members failed: 403 Forbidden". With text() mocked to return "Missing Chat.Read.All permission", the error message should include that suffix.
| await expect( | |
| getChatMembers({ | |
| chatId: "chat-123", | |
| tokenProvider, | |
| fetchFn: mockFetch, | |
| }), | |
| ).rejects.toThrow("Get chat members failed: 403 Forbidden"); | |
| }); | |
| ).rejects.toThrow( | |
| "Get chat members failed: 403 Forbidden - Missing Chat.Read.All permission", | |
| ); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/msteams/src/graph-upload.test.ts
Line: 451:458
Comment:
**Missing response body in assertion**
`getChatMembers` includes the response body in its thrown error (`... - ${body}` at `extensions/msteams/src/graph-upload.ts:296-299`), but this test expects only `"Get chat members failed: 403 Forbidden"`. With `text()` mocked to return `"Missing Chat.Read.All permission"`, the error message should include that suffix.
```suggestion
).rejects.toThrow(
"Get chat members failed: 403 Forbidden - Missing Chat.Read.All permission",
);
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Pull request overview
Adds unit test coverage for the MS Teams graph-upload module to validate Graph upload/sharing behaviors and error handling via mocked token provider + fetch.
Changes:
- Introduces
graph-upload.test.tswith 23 Vitest cases spanning all exported functions ingraph-upload.ts - Covers key success paths plus several validation/error scenarios (upload failures, missing response fields, per-user vs org sharing)
- Uses injected
fetchFn/token provider mocks to avoid network calls
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| describe("uploadToSharePoint", () => { | ||
| it("uploads a file to SharePoint site", async () => { | ||
| const tokenProvider = createMockTokenProvider(); | ||
| const mockFetch = createMockFetch({ | ||
| ok: true, |
There was a problem hiding this comment.
The uploadToSharePoint implementation also validates that the successful JSON response includes id, webUrl, and name and throws SharePoint upload response missing required fields if any are missing (see graph-upload.ts). There isn't a unit test in this block covering that missing-fields error path; adding one (similar to the OneDrive missing-fields test) would improve coverage.
| describe("getDriveItemProperties", () => { | ||
| it("fetches driveItem properties for file card attachments", async () => { | ||
| const tokenProvider = createMockTokenProvider(); | ||
| const mockFetch = createMockFetch({ | ||
| ok: true, |
There was a problem hiding this comment.
getDriveItemProperties has a !res.ok failure branch that throws Get driveItem properties failed: <status> <statusText> - <body> (see graph-upload.ts). The tests here cover success + missing properties but not the non-2xx response path; consider adding a test for a 4xx/5xx response to exercise that error handling.
| describe("createSharePointSharingLink", () => { | ||
| it("creates organization-scoped link using v1.0 API by default", async () => { | ||
| const tokenProvider = createMockTokenProvider(); | ||
| const mockFetch = createMockFetch({ | ||
| ok: true, |
There was a problem hiding this comment.
createSharePointSharingLink throws Create SharePoint sharing link response missing webUrl when the response JSON lacks link.webUrl (see graph-upload.ts). There isn't a test case in this section covering that validation error yet; adding one would complete coverage of this function’s main error branches (analogous to the OneDrive createSharingLink missing-webUrl test).
7abaaed to
3beed57
Compare
Addresses openclaw#8947. The '(default)' label was confusing because it didn't clearly indicate that this agent handles incoming channel messages. Changed to '(channel default)' for clarity in both 'agents list' and 'openclaw status' output.
…sions When listing sessions in status/sessions commands, prefer the current model catalog's contextTokens over the stale cached value in sessions.json. Fixes openclaw#8937
SummaryFixes #8937 When listing sessions in status/sessions commands, prefer the current model catalog's ProblemThe SolutionWhen displaying session info, use Files Changed
Testing
|
bfc1ccb to
f92900f
Compare
|
This pull request has been automatically marked as stale due to inactivity. |
This comment was marked as spam.
This comment was marked as spam.
|
This pull request has been automatically marked as stale due to inactivity. |
|
Hi @RajdeepKushwaha5 — thanks for the submission. I’m the new Microsoft Teams maintainer for OpenClaw. Please give me a day or two to work through the open Teams backlog. Also, join the Twitter community for daily MS Teams feedback + updates: https://x.com/i/communities/2031170403607974228 |
1 similar comment
|
Hi @RajdeepKushwaha5 — thanks for the submission. I’m the new Microsoft Teams maintainer for OpenClaw. Please give me a day or two to work through the open Teams backlog. Also, join the Twitter community for daily MS Teams feedback + updates: https://x.com/i/communities/2031170403607974228 |
|
Thanks. The idea may still be valid, but this PR no longer maps cleanly to current main during the refactor. If the regression still reproduces on latest main, please open a fresh PR with current failing evidence. |
Summary
Adds unit tests for the MS Teams graph-upload module which previously had no test coverage.
Changes
graph-upload.tsTesting
npx vitest run extensions/msteams/src/graph-upload.test.ts)Checklist
Greptile Overview
Greptile Summary
This PR adds a new Vitest test suite for the MS Teams
graph-uploadmodule, covering OneDrive/SharePoint upload helpers, sharing-link creation, drive-item property lookups, and chat member retrieval via injectedfetchFnand a mocked access token provider.The approach mirrors the module’s dependency-injection pattern (passing
fetchFn+ token provider) and exercises both success and error paths for the exported functions inextensions/msteams/src/graph-upload.ts.Confidence Score: 3/5
(2/5) Greptile learns from your feedback when you react with thumbs up/down!