From 814bb9af8542ef86fae83bccae72e13f80e9a6c4 Mon Sep 17 00:00:00 2001 From: Sorra Date: Fri, 27 Mar 2026 15:41:58 -0700 Subject: [PATCH] WL-0MN81ZNXR0025TPZ: add throttler tests (unit + integration) --- tests/cli/throttler-schedule-spy.test.ts | 54 ++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/cli/throttler-schedule-spy.test.ts diff --git a/tests/cli/throttler-schedule-spy.test.ts b/tests/cli/throttler-schedule-spy.test.ts new file mode 100644 index 0000000..ee93530 --- /dev/null +++ b/tests/cli/throttler-schedule-spy.test.ts @@ -0,0 +1,54 @@ +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import throttler from '../../src/github-throttler.js'; +import * as githubSync from '../../src/github-sync.js'; +import * as githubHelpers from '../../src/github.js'; + +describe('github-sync throttler schedule usage (unit)', () => { + beforeEach(() => { + vi.restoreAllMocks(); + }); + + it('calls throttler.schedule for GitHub API helpers', async () => { + const scheduleSpy = vi.spyOn(throttler, 'schedule'); + + const items = [ + { + id: 'WI-1', + title: 'T1', + description: 'desc', + status: 'open', + priority: 'medium', + sortIndex: 0, + parentId: null, + createdAt: new Date().toISOString(), + updatedAt: new Date().toISOString(), + tags: [], + assignee: '', + }, + ]; + const comments: any[] = []; + + // Stubs should schedule through the central throttler + vi.spyOn(githubHelpers as any, 'createGithubIssueAsync').mockImplementation(() => + throttler.schedule(async () => ({ number: 1, id: 1, updatedAt: new Date().toISOString() })) + ); + vi.spyOn(githubHelpers as any, 'updateGithubIssueAsync').mockImplementation(() => + throttler.schedule(async () => ({ number: 1, id: 1, updatedAt: new Date().toISOString() })) + ); + vi.spyOn(githubHelpers as any, 'listGithubIssueCommentsAsync').mockImplementation(() => + throttler.schedule(async () => []) + ); + vi.spyOn(githubHelpers as any, 'createGithubIssueCommentAsync').mockImplementation(() => + throttler.schedule(async () => ({ id: 1, updatedAt: new Date().toISOString() })) + ); + vi.spyOn(githubHelpers as any, 'updateGithubIssueCommentAsync').mockImplementation(() => + throttler.schedule(async () => ({ id: 1, updatedAt: new Date().toISOString() })) + ); + + const config = { repo: 'owner/repo', labelPrefix: 'wl:' } as any; + + await (githubSync as any).upsertIssuesFromWorkItems(items, comments, config); + + expect(scheduleSpy).toHaveBeenCalled(); + }); +});