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
25 changes: 25 additions & 0 deletions packages/social/spotify/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,31 @@ describe('social-spotify playlist publishing', () => {
});
});

it('normalizes custom API base URLs before composing Spotify paths', async () => {
const fetchMock = vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce({
ok: true,
status: 201,
text: async () => JSON.stringify({
id: 'playlist_base_url',
external_urls: { spotify: 'https://open.spotify.com/playlist/playlist_base_url' },
}),
} as Response);

const ctx = {
...fakeConnectContext({ SPOTIFY_ACCESS_TOKEN: 'spotify-token' }),
dryRun: false,
};

await adapter.post(ctx as any, {
title: 'Base URL',
body: 'Check custom base URL handling',
}, {
baseUrl: 'https://api.spotify.example/v1/',
});

expect(fetchMock.mock.calls[0]?.[0]).toBe('https://api.spotify.example/v1/me/playlists');
});

it('updates an existing playlist and replaces its items', async () => {
const fetchMock = vi.spyOn(globalThis, 'fetch')
.mockResolvedValueOnce({
Expand Down
3 changes: 2 additions & 1 deletion packages/social/spotify/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ async function spotifyFetch<T>(
options: SpotifyFetchOptions = {},
): Promise<T> {
const { allowEmpty, ...init } = options;
const res = await fetch(`${config.baseUrl ?? 'https://api.spotify.com/v1'}${path}`, {
const baseUrl = (config.baseUrl ?? 'https://api.spotify.com/v1').replace(/\/+$/, '');
const res = await fetch(`${baseUrl}${path}`, {
...init,
headers: {
authorization: `Bearer ${token}`,
Expand Down
Loading