-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathtest.js
85 lines (75 loc) · 2.16 KB
/
test.js
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
import test from 'ava';
import m from './';
const url = 'https://www.youtube.com/playlist?list=PLWKjhJtqVAbnZtkAI3BqcYxKnfWn_C704';
const urlWithPrivateVideos = 'https://www.youtube.com/playlist?list=PLtKALR6MChByCrbKkdxWwPOOMqM2ECPDv';
const base = 'https://youtube.com/watch?v=';
const mock = {
playlistName: 'Design Patterns - Beau teaches JavaScript',
ids: [
'bgU7FeiWKzc',
'3PUVr8jFMGg',
'3pXVHRT-amw',
'KOVc5o5kURE'
],
names: [
`Singleton Design Pattern - Beau teaches JavaScript`,
`Observer Design Pattern - Beau teaches JavaScript`,
`Module Design Pattern - Beau teaches JavaScript`,
`Mediator Design Pattern - Beau teaches JavaScript`
],
durations: [
(4 * 60) + 51,
(3 * 60) + 57,
(2 * 60) + 44,
(5 * 60) + 9
]
};
test('getId', async t => {
const ids = await m(url, 'id');
ids.data.playlist.forEach((id, i) => {
t.is(id, mock.ids[i]);
});
});
test('getUrl', async t => {
const urls = await m(url, 'url');
urls.data.playlist.forEach((uurl, i) => {
t.is(uurl, `${base}${mock.ids[i]}`);
});
});
test('getNames', async t => {
const names = await m(url, 'name');
names.data.playlist.forEach((name, i) => {
t.is(name, mock.names[i]);
});
});
test('getDurations', async t => {
const durations = await m(url, 'duration');
durations.data.playlist.forEach((duration, i) => {
t.is(duration, mock.durations[i]);
});
});
test('getAllDetails', async t => {
const videos = await m(url, ['name', 'id', 'url', 'duration']);
videos.data.playlist.forEach((video, i) => {
t.is(video.name, mock.names[i]);
t.is(video.id, mock.ids[i]);
t.is(video.url, `${base}${mock.ids[i]}`);
t.is(video.duration, mock.durations[i]);
});
});
test('getAllDetailsByDefault', async t => {
const videos = await m(url);
videos.data.playlist.forEach((video, i) => {
t.is(video.name, mock.names[i]);
t.is(video.id, mock.ids[i]);
t.is(video.url, `${base}${mock.ids[i]}`);
});
});
test('return isPrivate', async t => {
const videos = await m(urlWithPrivateVideos);
t.deepEqual(videos.data.playlist.map(video => video.isPrivate), [true, false, true]);
});
test('playlist name', async t => {
const videos = await m(url);
t.is(videos.data.name, mock.playlistName);
});