diff --git a/packages/social/spotify/src/index.test.ts b/packages/social/spotify/src/index.test.ts index 94347122..c8865922 100644 --- a/packages/social/spotify/src/index.test.ts +++ b/packages/social/spotify/src/index.test.ts @@ -30,6 +30,21 @@ describe('social-spotify playlist publishing', () => { }); }); + it('uses the configured API base URL when connecting', async () => { + const fetchMock = vi.spyOn(globalThis, 'fetch').mockResolvedValue({ + ok: true, + status: 200, + text: async () => JSON.stringify({ id: 'spotify_user_123' }), + } as Response); + + await adapter.connect( + fakeConnectContext({ SPOTIFY_ACCESS_TOKEN: 'spotify-token' }), + { baseUrl: 'https://spotify-proxy.example/v1/' }, + ); + + expect(fetchMock.mock.calls[0]?.[0]).toBe('https://spotify-proxy.example/v1/me'); + }); + it('creates a public playlist and appends normalized Spotify items', async () => { const fetchMock = vi.spyOn(globalThis, 'fetch') .mockResolvedValueOnce({ diff --git a/packages/social/spotify/src/index.ts b/packages/social/spotify/src/index.ts index a9ec29b1..8d4698c5 100644 --- a/packages/social/spotify/src/index.ts +++ b/packages/social/spotify/src/index.ts @@ -36,10 +36,10 @@ export default defineSocial({ label: 'Spotify', requires: { maxBodyChars: 300, maxHashtags: 0, hashtagsInBody: true }, - async connect(ctx) { + async connect(ctx, config) { const token = ctx.secret('SPOTIFY_ACCESS_TOKEN'); if (!token) throw new Error('SPOTIFY_ACCESS_TOKEN not in vault'); - const data = await spotifyFetch(token, '/me'); + const data = await spotifyFetch(token, '/me', config); if (!data.id) throw new Error('Spotify profile response did not include a user id'); return { accountId: data.id }; },