Skip to content

Commit ded70c8

Browse files
fix: update tests to mock simple-git snake_case output separately from camelCase expected results
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 09002ca commit ded70c8

File tree

1 file changed

+54
-9
lines changed

1 file changed

+54
-9
lines changed

packages/web/src/features/git/listCommitsApi.test.ts

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,28 @@ describe('searchCommits', () => {
314314

315315
describe('successful responses', () => {
316316
it('should return commits and totalCount from git log', async () => {
317-
const mockCommits = [
317+
const gitLogOutput = [
318+
{
319+
hash: 'abc123',
320+
date: '2024-06-15',
321+
message: 'feat: add feature',
322+
refs: 'HEAD -> main',
323+
body: '',
324+
author_name: 'John Doe',
325+
author_email: 'john@example.com',
326+
},
327+
{
328+
hash: 'def456',
329+
date: '2024-06-14',
330+
message: 'fix: bug fix',
331+
refs: '',
332+
body: '',
333+
author_name: 'Jane Smith',
334+
author_email: 'jane@example.com',
335+
},
336+
];
337+
338+
const expectedCommits = [
318339
{
319340
hash: 'abc123',
320341
date: '2024-06-15',
@@ -335,14 +356,14 @@ describe('searchCommits', () => {
335356
},
336357
];
337358

338-
mockGitLog.mockResolvedValue({ all: mockCommits });
359+
mockGitLog.mockResolvedValue({ all: gitLogOutput });
339360
mockGitRaw.mockResolvedValue('2');
340361

341362
const result = await listCommits({
342363
repo: 'github.com/test/repo',
343364
});
344365

345-
expect(result).toEqual({ commits: mockCommits, totalCount: 2 });
366+
expect(result).toEqual({ commits: expectedCommits, totalCount: 2 });
346367
});
347368

348369
it('should return empty commits array when no commits match', async () => {
@@ -451,7 +472,19 @@ describe('searchCommits', () => {
451472

452473
describe('integration scenarios', () => {
453474
it('should handle a typical commit search with filters', async () => {
454-
const mockCommits = [
475+
const gitLogOutput = [
476+
{
477+
hash: 'abc123',
478+
date: '2024-06-10T14:30:00Z',
479+
message: 'fix: resolve authentication bug',
480+
refs: 'HEAD -> main',
481+
body: 'Fixed issue with JWT token validation',
482+
author_name: 'Security Team',
483+
author_email: 'security@example.com',
484+
},
485+
];
486+
487+
const expectedCommits = [
455488
{
456489
hash: 'abc123',
457490
date: '2024-06-10T14:30:00Z',
@@ -465,7 +498,7 @@ describe('searchCommits', () => {
465498

466499
vi.spyOn(dateUtils, 'validateDateRange').mockReturnValue(null);
467500
vi.spyOn(dateUtils, 'toGitDate').mockImplementation((date) => date);
468-
mockGitLog.mockResolvedValue({ all: mockCommits });
501+
mockGitLog.mockResolvedValue({ all: gitLogOutput });
469502
mockGitRaw.mockResolvedValue('1');
470503

471504
const result = await listCommits({
@@ -477,7 +510,7 @@ describe('searchCommits', () => {
477510
maxCount: 20,
478511
});
479512

480-
expect(result).toEqual({ commits: mockCommits, totalCount: 1 });
513+
expect(result).toEqual({ commits: expectedCommits, totalCount: 1 });
481514
expect(mockGitLog).toHaveBeenCalledWith([
482515
'--max-count=20',
483516
'--since=30 days ago',
@@ -555,7 +588,19 @@ describe('searchCommits', () => {
555588
});
556589

557590
it('should work end-to-end with repository lookup', async () => {
558-
const mockCommits = [
591+
const gitLogOutput = [
592+
{
593+
hash: 'xyz789',
594+
date: '2024-06-20T10:00:00Z',
595+
message: 'feat: new feature',
596+
refs: 'main',
597+
body: 'Added new functionality',
598+
author_name: 'Developer',
599+
author_email: 'dev@example.com',
600+
},
601+
];
602+
603+
const expectedCommits = [
559604
{
560605
hash: 'xyz789',
561606
date: '2024-06-20T10:00:00Z',
@@ -570,7 +615,7 @@ describe('searchCommits', () => {
570615
mockFindFirst.mockResolvedValue({ id: 555, name: 'github.com/test/repository' });
571616
vi.spyOn(dateUtils, 'validateDateRange').mockReturnValue(null);
572617
vi.spyOn(dateUtils, 'toGitDate').mockImplementation((date) => date);
573-
mockGitLog.mockResolvedValue({ all: mockCommits });
618+
mockGitLog.mockResolvedValue({ all: gitLogOutput });
574619
mockGitRaw.mockResolvedValue('1');
575620

576621
const result = await listCommits({
@@ -580,7 +625,7 @@ describe('searchCommits', () => {
580625
author: 'Developer',
581626
});
582627

583-
expect(result).toEqual({ commits: mockCommits, totalCount: 1 });
628+
expect(result).toEqual({ commits: expectedCommits, totalCount: 1 });
584629
expect(mockCwd).toHaveBeenCalledWith('/mock/cache/dir/555');
585630
});
586631
});

0 commit comments

Comments
 (0)