Skip to content

Commit

Permalink
feat(libraryapi.ts): add 'saveAlbum', 'saveShow', and 'saveTrack'
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgrieger committed Jun 14, 2020
1 parent d7f51d5 commit 2f75a5c
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/apis/LibraryApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,20 @@ describe('LibraryApi', () => {
});
});

describe('saveAlbum', () => {
it('should save an album for the current user', async () => {
const { httpMock, library } = setup();

await library.saveAlbum('foo');

expect(httpMock.put).toBeCalledWith('/me/albums', {
data: {
ids: ['foo'],
},
});
});
});

describe('saveAlbums', () => {
it('should save albums for the current user', async () => {
const { httpMock, library } = setup();
Expand All @@ -344,6 +358,20 @@ describe('LibraryApi', () => {
});
});

describe('saveShow', () => {
it('should save a show for the current user', async () => {
const { httpMock, library } = setup();

await library.saveShow('foo');

expect(httpMock.put).toBeCalledWith('/me/shows', {
params: {
ids: ['foo'],
},
});
});
});

describe('saveShows', () => {
it('should save shows for the current user', async () => {
const { httpMock, library } = setup();
Expand All @@ -358,6 +386,20 @@ describe('LibraryApi', () => {
});
});

describe('saveTrack', () => {
it('should save a track for the current user', async () => {
const { httpMock, library } = setup();

await library.saveTrack('foo');

expect(httpMock.put).toBeCalledWith('/me/tracks', {
data: {
ids: ['foo'],
},
});
});
});

describe('saveTracks', () => {
it('should save tracks for the current user', async () => {
const { httpMock, library } = setup();
Expand Down
35 changes: 34 additions & 1 deletion src/apis/LibraryApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,17 @@ export class LibraryApi {
});
}

/**
* Save Album for the Current User
*
* Save an album to the current user's library.
*
* @param albumId The Spotify ID of the album.
*/
saveAlbum(albumId: string): Promise<void> {
return this.saveAlbums([albumId]);
}

/**
* Save Albums for the Current User
*
Expand All @@ -249,10 +260,21 @@ export class LibraryApi {
});
}

/**
* Save Show for the Current User
*
* Save a show to the current user's library.
*
* @param showId The Spotify ID of the show.
*/
saveShow(showId: string): Promise<void> {
return this.saveShows([showId]);
}

/**
* Save Shows for the Current User
*
* Save one or more albums to the current user's library.
* Save one or more shows to the current user's library.
*
* @param showIds The Spotify IDs of the shows.
*/
Expand All @@ -264,6 +286,17 @@ export class LibraryApi {
});
}

/**
* Save Track for the Current User
*
* Save a track to the current user's library.
*
* @param trackId The Spotify ID of the track.
*/
saveTrack(trackId: string): Promise<void> {
return this.saveTracks([trackId]);
}

/**
* Save Tracks for the Current User
*
Expand Down

0 comments on commit 2f75a5c

Please sign in to comment.