Repository navigation
[jsweep] Clean update_work_item.cjs #66772
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import { main } from "./update_work_item.cjs"; | ||
|
|
||
| global.core = { debug: vi.fn(), info: vi.fn(), warning: vi.fn() }; | ||
|
|
@@ -9,41 +9,25 @@ describe("update_work_item", () => { | |
| global.fetch = vi.fn(); | ||
| }); | ||
|
|
||
| it("returns a handler function", async () => { | ||
| expect(typeof (await main())).toBe("function"); | ||
| afterEach(() => { | ||
| delete global.fetch; | ||
| }); | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. L15: delete: duplicate default-config handler type assertion. The preceding test already proves main() returns a handler; nothing replaces it.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the redundant default-config test; the remaining smoke test covers handler creation, and a focused assertion checks update-specific wiring. Included in |
||
| it("works with default config", async () => { | ||
| const handler = await main(undefined); | ||
| expect(typeof handler).toBe("function"); | ||
| it("returns a handler function", async () => { | ||
| expect(typeof (await main())).toBe("function"); | ||
| }); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/tdd] Good coverage of the wrapper's thin-pass-through contract, but these 6 tests duplicate behavior already exercised in 💡 SuggestionConsider either: (a) trimming this file to just the handler-creation/default-config smoke tests (2 tests) since the validation logic is already fully covered in @copilot please address this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trimmed duplicated shared-handler cases and focused wrapper coverage on its configured handler type and input immutability. Included in |
||
|
|
||
| it("rejects fields disabled by configuration", async () => { | ||
| it("uses the update work-item handler", async () => { | ||
| const handler = await main({ target: "*", title: false }); | ||
| const result = await handler({ id: 42, title: "New title" }, {}); | ||
| expect(result).toEqual({ success: false, error: "title updates are not enabled by ado_update_work_item" }); | ||
| expect(global.fetch).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("rejects area paths outside configured prefixes", async () => { | ||
| const handler = await main({ staged: true, area_path: true, allowed_area_prefixes: ["proj\\Platform"] }); | ||
| const result = await handler({ id: 42, area_path: "proj\\Other" }, {}); | ||
| expect(result.success).toBe(false); | ||
| expect(result.error).toContain("area_path"); | ||
| expect(global.fetch).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("does not call the API in staged mode", async () => { | ||
| const handler = await main({ staged: true, target: "*", title: true }); | ||
| const result = await handler({ id: 42, title: "New title" }, {}); | ||
| expect(result.success).toBe(true); | ||
| expect(global.fetch).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("does not mutate the input message", async () => { | ||
| const handler = await main({ staged: true, target: "*", title: true }); | ||
| const message = { id: 42, title: "T" }; | ||
| await handler(message, {}); | ||
| expect(message).toEqual({ id: 42, title: "T" }); | ||
| it("does not mutate the input body when applying a configured footer", async () => { | ||
| const handler = await main({ staged: true, target: "*", body: true, body_footer: "Configured footer" }); | ||
| const message = { id: 42, body: "Original body" }; | ||
| expect(await handler(message, {})).toMatchObject({ success: true, staged: true }); | ||
| expect(message).toEqual({ id: 42, body: "Original body" }); | ||
| }); | ||
| }); | ||
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.
global.fetchis installed inbeforeEachbut never restored, so this file can leak a mocked network layer into later suites and make unrelated tests pass or fail for the wrong reason.💡 Restore the global after each test
The existing shared-handler suite already deletes
global.fetchinafterEach, and this wrapper test needs the same isolation. Without that cleanup, any later test file that forgets to stub fetch will silently run against this leftover mock instead of the real environment.That keeps this file self-contained and avoids cross-suite state pollution in CI.
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.
Added
afterEachcleanup to delete the mockedglobal.fetchafter every test. Included in6fb14cf.