Skip to content

Commit

Permalink
Add show URLs support
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Mar 28, 2021
1 parent 5a69ea9 commit cbaa66e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Artist from './artist';
import Album from './album';
import Track from './track';
import Episode from './episode';
import Show from './show';
import User from './user';
import SpotifyUri from './spotify-uri';
import { decode } from './util';
Expand Down Expand Up @@ -86,5 +87,8 @@ function parseParts(uri: string, parts: string[]): ParsedSpotifyUri {
if (parts[1] === 'episode') {
return new Episode(uri, parts[2]);
}
if (parts[1] === 'show') {
return new Show(uri, parts[2]);
}
throw new TypeError(`Could not determine type for: ${uri}`);
}
19 changes: 19 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ describe('parse()', function() {
assert.equal('episode', obj.type);
assert.equal('64TORH3xleuD1wcnFsrH1E', obj.id);
});
it('should parse "show" URLs', function () {
let url = 'https://open.spotify.com/show/6uxKcBftLv1aOWoNL7UzTl'
let obj = parse(url)
assert.equal('show', obj.type)
assert.equal('6uxKcBftLv1aOWoNL7UzTl', obj.id)
});
it('should parse user "playlist" URLs', function() {
let url =
'http://open.spotify.com/user/tootallnate/playlist/0Lt5S4hGarhtZmtz7BNTeX';
Expand Down Expand Up @@ -124,6 +130,12 @@ describe('parse()', function() {
assert.equal('episode', obj.type);
assert.equal('64TORH3xleuD1wcnFsrH1E', obj.id);
});
it('should parse "show" URIs', function () {
let uri = 'spotify:show:6uxKcBftLv1aOWoNL7UzTl'
let obj = parse(uri)
assert.equal('show', obj.type)
assert.equal('6uxKcBftLv1aOWoNL7UzTl', obj.id)
});
it('should parse user "playlist" URIs', function() {
let uri =
'spotify:user:daftpunkofficial:playlist:6jP6EcvAwqNksccDkIe6hX';
Expand Down Expand Up @@ -267,6 +279,13 @@ describe('formatOpenURL()', function() {
let actual = formatOpenURL(obj);
assert.equal(actual, expected);
});
it('should format "show" URIs', function () {
let uri = 'spotify:show:6uxKcBftLv1aOWoNL7UzTl'
let obj = parse(uri)
let expected = 'http://open.spotify.com/show/6uxKcBftLv1aOWoNL7UzTl'
let actual = formatOpenURL(obj)
assert.equal(actual, expected)
});
it('should format user "playlist" URIs', function() {
let uri =
'spotify:user:daftpunkofficial:playlist:6jP6EcvAwqNksccDkIe6hX';
Expand Down

0 comments on commit cbaa66e

Please sign in to comment.