beeeeg update
Some checks failed
Test and deploy staging / staging (push) Has been cancelled

This commit is contained in:
2026-09-23 04:15:10 +00:00
parent 487eff5bb2
commit d0c7b6548b
135 changed files with 9531 additions and 1777 deletions

View File

@@ -0,0 +1,37 @@
import { expect, it, vi } from 'vitest';
vi.mock('$env/dynamic/private', () => ({ env: { OSU_CLIENT_ID: '1', OSU_CLIENT_SECRET: 'test' } }));
import { getOsuMaps } from './osu';
it('falls back deliberately, merges IDs, reuses OAuth and caches matching results', async () => {
const fetchFn = vi.fn(async (url: string | URL | Request) => {
if (String(url).includes('/oauth/token'))
return Response.json({ access_token: 'token', expires_in: 3600 });
const query = new URL(String(url)).searchParams.get('q');
return Response.json({
beatmapsets: [
{
id: 1,
title: 'Unique Song',
artist: query === 'unique song' ? 'Artist' : 'Wrong Performer'
}
]
});
});
const track = {
id: '6PUzxtIHkv346yP89NzP9X',
name: 'Unique Song',
artists: [{ name: 'Artist' }],
album: { name: '', images: [] }
};
const results = await Promise.all([
getOsuMaps(fetchFn as typeof fetch, track),
getOsuMaps(fetchFn as typeof fetch, track)
]);
expect(results[0]).toHaveLength(1);
expect(results[0][0].score).toBe(100);
expect(results[1]).toEqual(results[0]);
await getOsuMaps(fetchFn as typeof fetch, track);
expect(fetchFn).toHaveBeenCalledTimes(3);
expect(fetchFn.mock.calls.filter(([url]) => String(url).includes('/oauth/token'))).toHaveLength(
1
);
});