Add unit and integration test suites
- Shared: link building, feed ordering, input schemas, API client - API unit: track matching, private-address blocking, token crypto, plan expiry, provider response parsing - API integration against Postgres and Redis: auth, follows and pins, now-playing state, webhooks, OAuth return URLs, realtime, rate limits - Tests use a dedicated *_test database and Redis DB, and refuse to wipe anything else; fetch is stubbed so they never hit the network - Pin Node to 22.13+ (.nvmrc), which Vite's native bindings require Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MzFywujuH9TiuXbr9vjoX8
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { STREAMING_SERVICES, openUrl, searchUrl } from './services';
|
||||
|
||||
const track = { title: 'Midnight City', artist: 'M83', links: { spotify: 'https://open.spotify.com/track/abc' } };
|
||||
|
||||
describe('openUrl', () => {
|
||||
it('uses the direct link when the service has one', () => {
|
||||
expect(openUrl(track, 'spotify')).toEqual({ url: 'https://open.spotify.com/track/abc', exact: true });
|
||||
});
|
||||
|
||||
it('falls back to a search on that service', () => {
|
||||
const result = openUrl(track, 'apple_music');
|
||||
expect(result.exact).toBe(false);
|
||||
expect(result.url).toBe('https://music.apple.com/search?term=M83%20Midnight%20City');
|
||||
});
|
||||
});
|
||||
|
||||
describe('searchUrl', () => {
|
||||
it.each(STREAMING_SERVICES)('builds an https URL for %s with the query encoded', (service) => {
|
||||
const url = new URL(searchUrl(service, 'Café & Co', 'Ünïcode'));
|
||||
expect(url.protocol).toBe('https:');
|
||||
expect(decodeURIComponent(url.href)).toContain('Ünïcode Café & Co');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user