Issues (15)

tests/album.spec.js (6 issues)

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('Album', () => {
11
  let spotify;
12
  let stubedFetch;
13
14
  beforeEach( () => {
15
    spotify = new SpotifyWrapper({
16
      token: 'foo',
17
    });
18
19
    stubedFetch = sinon.stub(global, 'fetch');
20
    stubedFetch.resolves({ json: () => ({ album: 'name' }) });
21
  });
22
23
  afterEach( () => {
24
    stubedFetch.restore();
25
  });
26
27
  describe('smoke tests', () => {
28
    it('should have getAlbum method', () => {
29
      expect(spotify.album.getAlbum).to.exist;
0 ignored issues
show
The result of the property access to expect(spotify.album.getAlbum).to.exist is not used.
Loading history...
30
    });
31
32
    it('should have getAlbums method', () => {
33
      expect(spotify.album.getAlbums).to.exist;
0 ignored issues
show
The result of the property access to expect(spotify.album.getAlbums).to.exist is not used.
Loading history...
34
    });
35
36
    it('should have getAlbumTracks method', () => {
37
      expect(spotify.album.getTracks).to.exist;
0 ignored issues
show
The result of the property access to expect(spotify.album.getTracks).to.exist is not used.
Loading history...
38
    });
39
  });
40
41
  describe('getAlbum', () => {
42
    it('should call fetch method', () => {
43
      spotify.album.getAlbum();
44
      expect(stubedFetch).to.have.been.calledOnce;
0 ignored issues
show
The result of the property access to expect(stubedFetch).to.have.been.calledOnce is not used.
Loading history...
45
    });
46
47
    it('should call fetch with the correct URL', () => {
48
      spotify.album.getAlbum('4aawyAB9vmqN3uQ7FjRGTy');
49
      expect(stubedFetch).to.have.been
50
        .calledWith('https://api.spotify.com/v1/albums/4aawyAB9vmqN3uQ7FjRGTy');
51
52
      spotify.album.getAlbum('4aawyAB9vmqN3uQ7FjRGTk')
53
      expect(stubedFetch).to.have.been
54
        .calledWith('https://api.spotify.com/v1/albums/4aawyAB9vmqN3uQ7FjRGTk');
55
    });
56
57
    it('should return the correct data from Promise', () => {
58
      const album = spotify.album.getAlbum('4aawyAB9vmqN3uQ7FjRGTy');
59
      album.then((data) => {
60
        expect(data).to.be.eql({ album: 'name' });
61
      })
62
    });
63
  });
64
65
  describe('getAlbums', () => {
66
    it('should call fetch method', () => {
67
      spotify.album.getAlbums();
68
      expect(stubedFetch).to.have.been.calledOnce;
0 ignored issues
show
The result of the property access to expect(stubedFetch).to.have.been.calledOnce is not used.
Loading history...
69
    });
70
71
    it('should call fetch with the correct URL', () => {
72
      spotify.album.getAlbums(['4aawyAB9vmqN3uQ7FjRGTy', '4aawyAB9vmqN3uQ7FjRGTk']);
73
      expect(stubedFetch).to.have.been
74
        .calledWith('https://api.spotify.com/v1/albums/?ids=4aawyAB9vmqN3uQ7FjRGTy,4aawyAB9vmqN3uQ7FjRGTk');
75
    });
76
77
    it('should return the correct data from Promise', () => {
78
      const albums = spotify.album.getAlbums(['4aawyAB9vmqN3uQ7FjRGTy', '4aawyAB9vmqN3uQ7FjRGTk']);
79
      albums.then((data) => {
80
        expect(data).to.be.eql({ album: 'name' });
81
      });
82
    });
83
  });
84
85
  describe('getAlbumsTracks', () => {
86
    it('should call fetch method', () => {
87
      spotify.album.getTracks();
88
      expect(stubedFetch).to.have.been.calledOnce;
0 ignored issues
show
The result of the property access to expect(stubedFetch).to.have.been.calledOnce is not used.
Loading history...
89
    });
90
91
    it('should call fetch with the correct URL', () => {
92
      spotify.album.getTracks('4aawyAB9vmqN3uQ7FjRGTy');
93
      expect(stubedFetch).to.have.been
94
        .calledWith('https://api.spotify.com/v1/albums/4aawyAB9vmqN3uQ7FjRGTy/tracks');
95
    });
96
97
    it('should return the correct data from Promise', () => {
98
      const tracks = spotify.album.getTracks('4aawyAB9vmqN3uQ7FjRGTy');
99
      tracks.then((data) => {
100
        expect(data).to.be.eql({ album: 'name' });
101
      });
102
    });
103
  });
104
});
105