mirror of
https://github.com/jackwener/OpenCLI.git
synced 2026-09-14 18:25:42 +08:00
d2974a9ff6
* refactor(adapters): convert adapter layer from TypeScript to JavaScript Core framework stays TypeScript; adapter layer moves to JS-first. Adapters are essentially "executable config + browser scripts" that barely use TS features — this simplifies the build/distribution pipeline by removing the dist/clis/ intermediate compilation step. Changes: - Convert all 753 adapter files in clis/ from .ts to .js - Update tsconfig to exclude clis/ from compilation - Simplify build-manifest to scan clis/*.js directly (no dist/clis/) - Update discovery, main, fetch-adapters to load JS adapters from clis/ - Update generate-verified to output .js artifacts - Update package.json files field: dist/clis/ → clis/ - Fix all test files for the .ts → .js transition * fix(main): use findPackageRoot for BUILTIN_CLIS path The previous relative path (../../clis from __dirname) only worked for dist/src/main.js but broke dev mode (tsx src/main.ts) where __dirname is <repo>/src — resolving to /clis instead of <repo>/clis. Use findPackageRoot() which works for both dev and prod paths.
68 lines
2.6 KiB
JavaScript
68 lines
2.6 KiB
JavaScript
import { describe, expect, it } from 'vitest';
|
|
import { assertSpotifyCredentialsConfigured, getFirstSpotifyTrack, hasConfiguredSpotifyCredentials, mapSpotifyTrackResults, parseDotEnv, resolveSpotifyCredentials, } from './utils.js';
|
|
describe('spotify utils', () => {
|
|
it('parses dotenv-style credential files', () => {
|
|
const env = parseDotEnv(`
|
|
# Spotify credentials
|
|
SPOTIFY_CLIENT_ID=abc123
|
|
SPOTIFY_CLIENT_SECRET=def456
|
|
`);
|
|
expect(env).toEqual({
|
|
SPOTIFY_CLIENT_ID: 'abc123',
|
|
SPOTIFY_CLIENT_SECRET: 'def456',
|
|
});
|
|
});
|
|
it('prefers explicit process env over file values', () => {
|
|
const credentials = resolveSpotifyCredentials({
|
|
SPOTIFY_CLIENT_ID: 'file-id',
|
|
SPOTIFY_CLIENT_SECRET: 'file-secret',
|
|
}, {
|
|
SPOTIFY_CLIENT_ID: 'env-id',
|
|
SPOTIFY_CLIENT_SECRET: 'env-secret',
|
|
});
|
|
expect(credentials).toEqual({
|
|
clientId: 'env-id',
|
|
clientSecret: 'env-secret',
|
|
});
|
|
});
|
|
it('treats placeholder values as unconfigured credentials', () => {
|
|
expect(hasConfiguredSpotifyCredentials({
|
|
clientId: 'your_spotify_client_id_here',
|
|
clientSecret: 'your_spotify_client_secret_here',
|
|
})).toBe(false);
|
|
});
|
|
it('throws a helpful CONFIG error for empty or placeholder credentials', () => {
|
|
expect(() => assertSpotifyCredentialsConfigured({
|
|
clientId: '',
|
|
clientSecret: '',
|
|
}, '/tmp/spotify.env')).toThrow(/Missing Spotify credentials/);
|
|
expect(() => assertSpotifyCredentialsConfigured({
|
|
clientId: 'your_spotify_client_id_here',
|
|
clientSecret: 'real-secret',
|
|
}, '/tmp/spotify.env')).toThrow(/Fill in SPOTIFY_CLIENT_ID and SPOTIFY_CLIENT_SECRET/);
|
|
});
|
|
it('maps search payloads into stable track summaries', () => {
|
|
const results = mapSpotifyTrackResults({
|
|
tracks: {
|
|
items: [
|
|
{
|
|
name: 'Numb',
|
|
artists: [{ name: 'Linkin Park' }, { name: 'Jay-Z' }],
|
|
album: { name: 'Encore' },
|
|
uri: 'spotify:track:123',
|
|
},
|
|
],
|
|
},
|
|
});
|
|
expect(results).toEqual([
|
|
{
|
|
track: 'Numb',
|
|
artist: 'Linkin Park, Jay-Z',
|
|
album: 'Encore',
|
|
uri: 'spotify:track:123',
|
|
},
|
|
]);
|
|
expect(getFirstSpotifyTrack({ tracks: { items: [] } })).toBeNull();
|
|
});
|
|
});
|