import { expect, test } from 'vitest';
import { fetchRepos, timeSince, checkImage } from '$lib/api/git';

test('Fetch Repos', async () => {
    let repos = await fetchRepos();
    expect(repos.length).toEqual(12);
});

test.each([
    [new Date((Date.now() - 1000 * 60 * 60 * 24)), 'Yesterday'],
    [new Date((Date.now() - 1000 * 60 * 60 * 24 * 2)), '2 days ago'],
    [new Date((Date.now() - 1000 * 60 * 60 * 24 * 7)), '1 week ago'],
    [new Date((Date.now() - 1000 * 60 * 60 * 24 * 7 * 2)), '2 weeks ago'],
    [new Date((Date.now() - 1000 * 60 * 60 * 24 * 30)), '1 month ago'],
    [new Date((Date.now() - 1000 * 60 * 60 * 24 * 365)), '1 year ago'],
  ])('', (time, expected) => {
    expect(timeSince(time)).toBe(expected)
  })


test('Check Image', async () => {
    let repos = await fetchRepos();

    for (let repo of repos) {
        let image = await checkImage(repo);
        expect(image).toBeDefined();
    }
});