-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwhitelabel.spec.js
More file actions
221 lines (186 loc) · 7.74 KB
/
whitelabel.spec.js
File metadata and controls
221 lines (186 loc) · 7.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
var expect = chai.expect;
var COLLECTION = 'weekly';
var MIXTAPE = 'noon-186';
var TRACK = 'gallant-episode';
var notNull = function(obj) {
expect(obj).to.not.be.null;
expect(obj).to.not.be.undefined;
};
var verifyObject = function(obj) {
notNull(obj);
expect(obj.slug).to.not.be.empty;
expect(obj.id).to.not.be.empty;
expect(obj.title).to.not.be.empty;
}
var randomArrIndex = function(arr) {
return Math.floor(Math.random() * (arr.length - 0 + 1));
};
describe('White Label JS', function() {
this.timeout(40000);
it('should error with invalid token', function() {
try {
var wl = new WhiteLabel();
fail('Creating a new WhiteLabel object without client id should throw an error');
} catch (e) {
expect(e).to.not.be.null;
}
});
it('should not error with valid token', function() {
var wl = new WhiteLabel(CLIENT_ID);
notNull(wl);
});
describe('White Label APIs', function() {
beforeEach(function() {
this.wl = new WhiteLabel(CLIENT_ID);
});
it('should fetch collections', function() {
return this.wl.getAllCollections().then(function(collections) {
notNull(collections);
});
});
it('should fetch all result collections', function() {
return this.wl.getAllCollections({results: true, all: true}).then(function(collections) {
notNull(collections);
expect(collections).to.not.be.length(0);
collections.forEach(function(coll) {
verifyObject(coll);
});
});
});
it('should fetch single collection', function() {
return this.wl.getCollection(COLLECTION).then(function(collection) {
verifyObject(collection);
});
});
it('should fetch all mixtapes', function() {
return this.wl.getAllMixtapes().then(function(mixtapes) {
notNull(mixtapes);
});
});
it('should fetch collection mixtapes', function() {
return this.wl.getCollectionMixtapes(COLLECTION).then(function(mixtapes) {
notNull(mixtapes);
});
});
it('should fetch all collection mixtapes', function() {
return this.wl.getCollectionMixtapes(COLLECTION, {results: true, all: true}).then(function(mixtapes) {
expect(mixtapes.length > 20).to.be.true;
});
});
it('should fetch single mixtape', function() {
return this.wl.getMixtape(MIXTAPE).then(function(mixtape) {
verifyObject(mixtape);
});
});
it('should fetch latest mixtape', function() {
return this.wl.getLatestMixtape().then(function(mixtape) {
verifyObject(mixtape);
});
})
it('should fetch all tracks', function() {
return this.wl.getAllTracks({results: true}).then(function(tracks) {
notNull(tracks);
expect(tracks).to.not.be.length(0);
});
});
it('should fetch mixtape tracks', function() {
return this.wl.getMixtapeTracks(MIXTAPE, {results: true}).then(function(tracks) {
notNull(tracks);
expect(tracks).to.not.be.length(0);
});
});
it('should fetch single track', function() {
return this.wl.getTrack(TRACK).then(function(track) {
verifyObject(track);
});
});
it('should return an array of tracks', function() {
return this.wl.getTrack(TRACK, {all: true}).then(function(track) {
notNull(track);
expect(track).to.be.length(1);
});
});
it('should record play', function() {
return this.wl.recordPlay(TRACK);
});
});
describe('White Label Filtering', function() {
beforeEach(function() {
this.wl = new WhiteLabel(CLIENT_ID);
});
it('should filter collections by ordering', function() {
return P.join(
this.wl.getAllCollections({results: true, filters: {ordering: '-created'}}),
this.wl.getAllCollections({results: true, filters: {ordering: 'created'}}),
function(collections1, collections2) {
notNull(collections1);
notNull(collections2);
expect(collections1.length).to.be.equal(collections2.length);
expect(collections1[0].slug).to.not.be.equal(collections2[0].slug);
}
);
});
it('should search for single collection', function() {
return this.wl.getAllCollections({results: true, filters: {search: 'weekly'}}).then(function(collections) {
notNull(collections);
expect(collections).to.be.length(1);
expect(collections[0].slug).to.be.equal('weekly');
});
});
it('should filter mixtapes by collection', function() {
return P.join(
this.wl.getAllMixtapes({all: true, results: true}),
this.wl.getCollectionMixtapes(COLLECTION, {all: true, results: true}),
function(mixtapes1, mixtapes2) {
notNull(mixtapes1);
notNull(mixtapes2);
expect(mixtapes1.length).to.not.be.equal(mixtapes2.length);
}
);
});
it('should filter mixtapes with method', function() {
return P.join(
this.wl.getAllMixtapes({all: true, results: true, filters: {collection: COLLECTION}}),
this.wl.getCollectionMixtapes(COLLECTION, {all: true, results: true}),
function(collections1, collections2) {
notNull(collections1);
notNull(collections2);
expect(collections1.length).to.be.equal(collections2.length);
expect(collections1[0].slug).to.be.equal(collections2[0].slug);
expect(collections1[collections1.length-1].slug).to.be.equal(collections2[collections2.length-1].slug);
}
);
});
it('should search for single mixtape', function() {
return this.wl.getAllTracks({all: true, results: true, filters: {search: 'Get Mine Ft. Shakka'}}).then(function(tracks){
notNull(tracks);
expect(tracks).to.be.length(1);
expect(tracks[0].title).to.be.equal('Get Mine Ft. Shakka');
verifyObject(tracks[0]);
});
});
it('should filter tracks by mixtape', function() {
return P.join(
this.wl.getAllTracks({all: true, results: true}),
this.wl.getMixtapeTracks(MIXTAPE, {all: true, results: true}),
function(tracks1, tracks2) {
notNull(tracks1);
notNull(tracks2);
expect(tracks1.length).to.not.be.equal(tracks2.length);
}
);
});
it('should filter tracks by ordering', function() {
return P.join(
this.wl.getMixtapeTracks(MIXTAPE, {all: true, results: true, filters: {ordering: 'artist'}}),
this.wl.getMixtapeTracks(MIXTAPE, {all: true, results: true}),
function(tracks1, tracks2) {
notNull(tracks1);
notNull(tracks2);
expect(tracks1.length).to.be.equal(tracks2.length);
expect(tracks1[0].slug).to.not.be.equal(tracks2[0].slug);
}
);
});
});
});