feat(ext/sw): GitHost.lastCommit() for vault-presence metadata
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { GiteaHost } from '../gitea';
|
||||
import { GitHubHost } from '../github';
|
||||
|
||||
describe('lastCommit (Gitea)', () => {
|
||||
let fetchSpy: ReturnType<typeof vi.spyOn>;
|
||||
|
||||
beforeEach(() => {
|
||||
fetchSpy = vi.spyOn(globalThis, 'fetch');
|
||||
});
|
||||
|
||||
it('returns commit metadata when API succeeds', async () => {
|
||||
fetchSpy.mockResolvedValueOnce(new Response(JSON.stringify([
|
||||
{ sha: 'abc1234567', commit: { author: { name: 'Alice', date: '2026-04-20T12:00:00Z' } } },
|
||||
]), { status: 200 }));
|
||||
const host = new GiteaHost('https://git.example.com', 'user/vault', 'tok');
|
||||
const result = await host.lastCommit('manifest.enc');
|
||||
expect(result).toEqual({ sha: 'abc1234', author: 'Alice', date: '2026-04-20T12:00:00Z' });
|
||||
});
|
||||
|
||||
it('returns null on 404', async () => {
|
||||
fetchSpy.mockResolvedValueOnce(new Response('', { status: 404 }));
|
||||
const host = new GiteaHost('https://git.example.com', 'user/vault', 'tok');
|
||||
expect(await host.lastCommit('manifest.enc')).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null on network error', async () => {
|
||||
fetchSpy.mockRejectedValueOnce(new Error('network'));
|
||||
const host = new GiteaHost('https://git.example.com', 'user/vault', 'tok');
|
||||
expect(await host.lastCommit('manifest.enc')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('lastCommit (GitHub)', () => {
|
||||
let fetchSpy: ReturnType<typeof vi.spyOn>;
|
||||
|
||||
beforeEach(() => {
|
||||
fetchSpy = vi.spyOn(globalThis, 'fetch');
|
||||
});
|
||||
|
||||
it('returns commit metadata when API succeeds', async () => {
|
||||
fetchSpy.mockResolvedValueOnce(new Response(JSON.stringify([
|
||||
{ sha: 'def4567890', commit: { author: { name: 'Bob', date: '2026-04-22T15:00:00Z' } } },
|
||||
]), { status: 200 }));
|
||||
const host = new GitHubHost('user/vault', 'tok');
|
||||
const result = await host.lastCommit('manifest.enc');
|
||||
expect(result).toEqual({ sha: 'def4567', author: 'Bob', date: '2026-04-22T15:00:00Z' });
|
||||
});
|
||||
|
||||
it('returns null when commits list is empty', async () => {
|
||||
fetchSpy.mockResolvedValueOnce(new Response(JSON.stringify([]), { status: 200 }));
|
||||
const host = new GitHubHost('user/vault', 'tok');
|
||||
expect(await host.lastCommit('manifest.enc')).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user