Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/social/spotify/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
4 changes: 2 additions & 2 deletions packages/social/spotify/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ export default defineSocial<Config>({
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<SpotifyUserResponse>(token, '/me');
const data = await spotifyFetch<SpotifyUserResponse>(token, '/me', config);
if (!data.id) throw new Error('Spotify profile response did not include a user id');
return { accountId: data.id };
},
Expand Down
Loading