Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions tests/cli/throttler-schedule-spy.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
Loading