-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from calluswhatyouwant/v0.1.x
Upgrade to v0.1.3
- Loading branch information
Showing
14 changed files
with
2,709 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import nock from 'nock'; | ||
|
||
import { artistMock, ArtistMock } from './mocks/artist.mock'; | ||
import { severalArtistsMock } from './mocks/several-artists.mock'; | ||
import { artistAlbumsMock } from './mocks/artist-albums.mock'; | ||
import { artistRelatedArtistsMock } from './mocks/artist-related-artists.mock'; | ||
import { artistTopTracksMock, TrackMock } from './mocks/artist-top-tracks.mock'; | ||
import { | ||
checkMatchingArtistAttributes, | ||
checkMatchingPagingObjectAttributes, | ||
checkMatchingTrackAttributes, | ||
} from './common/matching-attributes.test'; | ||
|
||
import { | ||
init, | ||
getArtist, | ||
getSeveralArtists, | ||
getArtistAlbums, | ||
getArtistRelatedArtists, | ||
getArtistTopTracks, | ||
} from '../src/lib'; | ||
import Artist from '../src/lib/models/artist/artist'; | ||
import Track from '../src/lib/models/track/track'; | ||
|
||
describe('Artist requests', () => { | ||
beforeEach(() => { | ||
init('SomeToken'); | ||
}); | ||
|
||
describe('#getArtist()', () => { | ||
beforeEach(() => { | ||
nock('https://api.spotify.com/v1') | ||
.get('/artists/1WgXqy2Dd70QQOU7Ay074N') | ||
.reply(200, artistMock); | ||
}); | ||
|
||
it('response should match all artist attributes', async () => { | ||
const artistResponse = await getArtist('1WgXqy2Dd70QQOU7Ay074N'); | ||
checkMatchingArtistAttributes(artistResponse, artistMock); | ||
}); | ||
}); | ||
|
||
describe('#getSeveralArtists()', () => { | ||
beforeEach(() => { | ||
nock('https://api.spotify.com/v1') | ||
.get('/artists') | ||
.query({ | ||
ids: ['5WUlDfRSoLAfcVSX1WnrxN', '1WgXqy2Dd70QQOU7Ay074N'], | ||
}) | ||
.reply(200, severalArtistsMock); | ||
}); | ||
|
||
it('response should match all artists attributes', async () => { | ||
const severalArtistsResponse = await getSeveralArtists([ | ||
'5WUlDfRSoLAfcVSX1WnrxN', | ||
'1WgXqy2Dd70QQOU7Ay074N', | ||
]); | ||
|
||
for (let i = 0; i < severalArtistsResponse.length; i++) { | ||
const artistResponse = severalArtistsResponse[i]; | ||
const artistMock = severalArtistsMock.artists[i]; | ||
checkMatchingArtistAttributes(artistResponse, artistMock); | ||
} | ||
}); | ||
}); | ||
|
||
describe('#getArtistAlbums()', () => { | ||
beforeEach(() => { | ||
nock('https://api.spotify.com/v1') | ||
.get('/artists/1WgXqy2Dd70QQOU7Ay074N/albums') | ||
.query({ offset: 0, limit: 5 }) | ||
.reply(200, artistAlbumsMock); | ||
}); | ||
|
||
it('response should match all albums attributes', async () => { | ||
const artistAlbumsResponse = await getArtistAlbums( | ||
'1WgXqy2Dd70QQOU7Ay074N', | ||
0, | ||
5 | ||
); | ||
checkMatchingPagingObjectAttributes( | ||
artistAlbumsResponse, | ||
artistAlbumsMock | ||
); | ||
}); | ||
}); | ||
|
||
describe('#getArtistRelatedArtists()', () => { | ||
beforeEach(() => { | ||
nock('https://api.spotify.com/v1') | ||
.get('/artists/1WgXqy2Dd70QQOU7Ay074N/related-artists') | ||
.reply(200, artistRelatedArtistsMock); | ||
}); | ||
|
||
it('response should match all artists attributes', async () => { | ||
const artistRelatedArtistsResponse = await getArtistRelatedArtists( | ||
'1WgXqy2Dd70QQOU7Ay074N' | ||
); | ||
|
||
for (let i = 0; i < artistRelatedArtistsResponse.length; i++) { | ||
const artistResponse: Artist = artistRelatedArtistsResponse[i]; | ||
const artistMock: ArtistMock = | ||
artistRelatedArtistsMock.artists[i]; | ||
checkMatchingArtistAttributes(artistResponse, artistMock); | ||
} | ||
}); | ||
}); | ||
|
||
describe('#getArtistTopTracks()', () => { | ||
beforeEach(() => { | ||
nock('https://api.spotify.com/v1') | ||
.get('/artists/1WgXqy2Dd70QQOU7Ay074N/top-tracks') | ||
.query({ market: 'BR' }) | ||
.reply(200, artistTopTracksMock); | ||
}); | ||
|
||
it('response should match all tracks attributes', async () => { | ||
const artistTopTracksResponse = await getArtistTopTracks( | ||
'1WgXqy2Dd70QQOU7Ay074N', | ||
'BR' | ||
); | ||
|
||
for (let i = 0; i < artistTopTracksResponse.length; i++) { | ||
const topTrackResponse: Track = artistTopTracksResponse[i]; | ||
const topTrackMock: TrackMock = artistTopTracksMock.tracks[i]; | ||
checkMatchingTrackAttributes(topTrackResponse, topTrackMock); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { expect } from 'chai'; | ||
|
||
import Album from '../../src/lib/models/album/album'; | ||
import AlbumSimplified from '../../src/lib/models/album/album-simplified'; | ||
import Artist from '../../src/lib/models/artist/artist'; | ||
import Track from '../../src/lib/models/track/track'; | ||
import { AlbumMock } from '../mocks/album.mock'; | ||
import { ArtistMock } from '../mocks/artist.mock'; | ||
import { TrackMock } from './../mocks/artist-top-tracks.mock'; | ||
|
||
export const checkMatchingAlbumAttributes = ( | ||
response: Album, | ||
mock: AlbumMock | ||
) => { | ||
expect(response.albumType).to.be.equal(mock.album_type); | ||
expect(response.artists).to.have.lengthOf(mock.artists.length); | ||
expect(response.availableMarkets).to.be.eql(mock.available_markets); | ||
expect(response.copyrights).to.be.eql(mock.copyrights); | ||
expect(response.externalIds).to.be.eql(mock.external_ids); | ||
expect(response.externalUrls).to.be.eql(mock.external_urls); | ||
expect(response.genres).to.be.eql(mock.genres); | ||
expect(response.href).to.be.equal(mock.href); | ||
expect(response.id).to.be.equal(mock.id); | ||
expect(response.images).to.be.eql(mock.images); | ||
expect(response.label).to.be.equal(mock.label); | ||
expect(response.name).to.be.equal(mock.name); | ||
expect(response.popularity).to.be.equal(mock.popularity); | ||
expect(response.releaseDate).to.be.equal(mock.release_date); | ||
expect(response.releaseDatePrecision).to.be.equal( | ||
mock.release_date_precision | ||
); | ||
expect(response.totalTracks).to.be.equal(mock.total_tracks); | ||
expect(response.tracks.total).to.be.equal(mock.tracks.total); | ||
expect(response.type).to.be.equal(mock.type); | ||
expect(response.uri).to.be.equal(mock.uri); | ||
}; | ||
|
||
export const checkMatchingAlbumSimplifiedAttributes = ( | ||
response: AlbumSimplified, | ||
mock: any | ||
) => { | ||
expect(response.albumType).to.be.equal(mock.album_type); | ||
expect(response.artists).to.have.lengthOf(mock.artists.length); | ||
expect(response.externalUrls).to.be.eql(mock.external_urls); | ||
expect(response.href).to.be.equal(mock.href); | ||
expect(response.id).to.be.equal(mock.id); | ||
expect(response.images).to.be.eql(mock.images); | ||
expect(response.name).to.be.equal(mock.name); | ||
expect(response.releaseDate).to.be.equal(mock.release_date); | ||
expect(response.releaseDatePrecision).to.be.equal( | ||
mock.release_date_precision | ||
); | ||
expect(response.type).to.be.equal(mock.type); | ||
expect(response.uri).to.be.equal(mock.uri); | ||
}; | ||
|
||
export const checkMatchingArtistAttributes = ( | ||
response: Artist, | ||
mock: ArtistMock | ||
) => { | ||
expect(response.externalUrls).to.be.eql(mock.external_urls); | ||
expect(response.followers).to.be.eql(mock.followers); | ||
expect(response.genres).to.be.eql(mock.genres); | ||
expect(response.href).to.be.equal(mock.href); | ||
expect(response.id).to.be.equal(mock.id); | ||
expect(response.images).to.be.eql(mock.images); | ||
expect(response.name).to.be.equal(mock.name); | ||
expect(response.popularity).to.be.equal(mock.popularity); | ||
expect(response.type).to.be.equal(mock.type); | ||
expect(response.uri).to.be.equal(mock.uri); | ||
}; | ||
|
||
export const checkMatchingTrackAttributes = ( | ||
response: Track, | ||
mock: TrackMock | ||
) => { | ||
checkMatchingAlbumSimplifiedAttributes(response.album, mock.album); | ||
expect(response.artists).to.have.lengthOf(mock.artists.length); | ||
expect(response.discNumber).to.be.equal(mock.disc_number); | ||
expect(response.durationMs).to.be.equal(mock.duration_ms); | ||
expect(response.explicit).to.be.equal(mock.explicit); | ||
expect(response.externalIds).to.be.eql(mock.external_ids); | ||
expect(response.externalUrls).to.be.eql(mock.external_urls); | ||
expect(response.href).to.be.equal(mock.href); | ||
expect(response.id).to.be.equal(mock.id); | ||
expect(response.isLocal).to.be.equal(mock.is_local); | ||
expect(response.isPlayable).to.be.equal(mock.is_playable); | ||
expect(response.name).to.be.equal(mock.name); | ||
expect(response.popularity).to.be.equal(mock.popularity); | ||
expect(response.previewUrl).to.be.equal(mock.preview_url); | ||
expect(response.trackNumber).to.be.equal(mock.track_number); | ||
expect(response.type).to.be.equal(mock.type); | ||
expect(response.uri).to.be.equal(mock.uri); | ||
}; | ||
|
||
export const checkMatchingPagingObjectAttributes = ( | ||
response: any, | ||
mock: any | ||
) => { | ||
expect(response.href).to.be.equal(mock.href.split('?')[0]); | ||
expect(response.items).to.have.lengthOf(mock.items.length); | ||
expect(response.limit).to.be.equal(mock.limit); | ||
expect(response.offset).to.be.equal(mock.offset); | ||
expect(response.total).to.be.equal(mock.total); | ||
}; |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.