1 | import chai, { expect } from 'chai'; |
||
2 | import sinon from 'sinon'; |
||
3 | import sinonChai from 'sinon-chai'; |
||
4 | chai.use(sinonChai); |
||
5 | |||
6 | global.fetch = require('node-fetch'); |
||
7 | |||
8 | import SpotifyWrapper from '../src/index'; |
||
9 | |||
10 | describe('Search', () => { |
||
11 | let spotify; |
||
12 | let fetchedStub; |
||
13 | |||
14 | beforeEach( () => { |
||
15 | spotify = new SpotifyWrapper({ |
||
16 | token: 'foo' |
||
17 | }); |
||
18 | |||
19 | fetchedStub = sinon.stub(global, 'fetch'); |
||
20 | fetchedStub.resolves({ json: () => {} }); |
||
21 | }); |
||
22 | |||
23 | afterEach( () => { |
||
24 | fetchedStub.restore(); |
||
25 | }); |
||
26 | |||
27 | describe('smoke tests', () => { |
||
28 | it('should exist the spotify.search.albums method', () => { |
||
29 | expect(spotify.search.albums).to.exist; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
30 | }); |
||
31 | |||
32 | it('should exist the spotify.search.artists method', () => { |
||
33 | expect(spotify.search.artists).to.exist; |
||
0 ignored issues
–
show
|
|||
34 | }); |
||
35 | |||
36 | it('should exist the spotify.search.tracks method', () => { |
||
37 | expect(spotify.search.tracks).to.exist; |
||
0 ignored issues
–
show
|
|||
38 | }); |
||
39 | |||
40 | it('should exist the spotify.search.playlists method', () => { |
||
41 | expect(spotify.search.playlists).to.exist; |
||
0 ignored issues
–
show
|
|||
42 | }); |
||
43 | }); |
||
44 | |||
45 | describe('spotify.search.artists', () => { |
||
46 | it('should call fetch function', () => { |
||
47 | spotify.search.artists('Incubus'); |
||
48 | expect(fetchedStub).to.have.been.calledOnce; |
||
0 ignored issues
–
show
|
|||
49 | }); |
||
50 | |||
51 | it('should call fetch with the correct URL', () => { |
||
52 | spotify.search.artists('Incubus'); |
||
53 | expect(fetchedStub).to.have.been.calledWith('https://api.spotify.com/v1/search?q=Incubus&type=artist') |
||
54 | |||
55 | spotify.search.artists('Muse'); |
||
56 | expect(fetchedStub).to.have.been.calledWith('https://api.spotify.com/v1/search?q=Muse&type=artist') |
||
57 | }); |
||
58 | }); |
||
59 | |||
60 | describe('spotify.search.albums', () => { |
||
61 | it('should call fetch function', () => { |
||
62 | spotify.search.albums('Incubus'); |
||
63 | expect(fetchedStub).to.have.been.calledOnce; |
||
0 ignored issues
–
show
|
|||
64 | }); |
||
65 | |||
66 | it('should call fetch with the correct URL', () => { |
||
67 | spotify.search.albums('Incubus'); |
||
68 | expect(fetchedStub).to.have.been.calledWith('https://api.spotify.com/v1/search?q=Incubus&type=album') |
||
69 | |||
70 | spotify.search.albums('Muse'); |
||
71 | expect(fetchedStub).to.have.been.calledWith('https://api.spotify.com/v1/search?q=Muse&type=album') |
||
72 | }); |
||
73 | }); |
||
74 | |||
75 | describe('spotify.search.tracks', () => { |
||
76 | it('should call fetch function', () => { |
||
77 | spotify.search.tracks('Incubus'); |
||
78 | expect(fetchedStub).to.have.been.calledOnce; |
||
0 ignored issues
–
show
|
|||
79 | }); |
||
80 | |||
81 | it('should call fetch with the correct URL', () => { |
||
82 | spotify.search.tracks('Incubus'); |
||
83 | expect(fetchedStub).to.have.been.calledWith('https://api.spotify.com/v1/search?q=Incubus&type=track') |
||
84 | |||
85 | spotify.search.tracks('Muse'); |
||
86 | expect(fetchedStub).to.have.been.calledWith('https://api.spotify.com/v1/search?q=Muse&type=track') |
||
87 | }); |
||
88 | }); |
||
89 | |||
90 | describe('spotify.search.playlists', () => { |
||
91 | it('should call fetch function', () => { |
||
92 | spotify.search.playlists('Incubus'); |
||
93 | expect(fetchedStub).to.have.been.calledOnce; |
||
0 ignored issues
–
show
|
|||
94 | }); |
||
95 | |||
96 | it('should call fetch with the correct URL', () => { |
||
97 | spotify.search.playlists('Incubus'); |
||
98 | expect(fetchedStub).to.have.been.calledWith('https://api.spotify.com/v1/search?q=Incubus&type=playlist') |
||
99 | |||
100 | spotify.search.playlists('Muse'); |
||
101 | expect(fetchedStub).to.have.been.calledWith('https://api.spotify.com/v1/search?q=Muse&type=playlist') |
||
102 | }); |
||
103 | }); |
||
104 | }); |
||
105 |