-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
test.js
189 lines (107 loc) · 4.49 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
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
'use strict'
const test = require( 'ava' )
const movieTrailer = require( './index' )
test( 'fetch movie trailer', async t => {
t.plan( 2 )
const trailer = await movieTrailer( 'oceans eleven' )
t.is( trailer.indexOf( 'http' ), 0, 'returns a url' )
t.not( trailer.indexOf( 'youtube' ), -1, 'returns a youtube url' )
} )
test( 'fetch tv trailer', async t => {
t.plan( 2 )
const trailer = await movieTrailer( 'shameless', { videoType: 'tv' } )
t.is( trailer.indexOf( 'http' ), 0, 'returns a url' )
t.not( trailer.indexOf( 'youtube' ), -1, 'returns a youtube url' )
} )
test( 'dont fetch empty search', async t => {
// Testing no search query, should error
const error = await movieTrailer( null ).catch( error_ => error_ )
t.is( error.message, 'Expected first parameter to be a movie or TMDB ID (string)' )
} )
test( 'fetch movie trailer by TMDB ID', async t => {
t.plan( 2 )
const trailer = await movieTrailer( null, { tmdbId: '161' } )
t.is( trailer.indexOf( 'http' ), 0, 'returns a url' )
t.not( trailer.indexOf( 'youtube' ), -1, 'returns a youtube url' )
} )
test( 'fetch movie trailer with year', async t => {
t.plan( 2 )
const trailer = await movieTrailer( 'oceans eleven', 1960 )
t.is( trailer.indexOf( 'http' ), 0, 'returns a url' )
t.not( trailer.indexOf( 'youtube' ), -1, 'returns a youtube url' )
} )
test( 'fetch movie trailer as video ID', async t => {
t.plan( 2 )
const trailer = await movieTrailer( 'oceans eleven', { id: true } )
t.is( trailer.indexOf( 'http' ), -1, 'does not return a url' )
t.is( trailer.indexOf( 'youtube' ), -1, 'is not a youtube url' )
} )
test( 'fetch movie trailer with language', async t => {
t.plan( 1 )
const trailer = await movieTrailer( 'up' )
const trailerDE = await movieTrailer( 'up', { language: 'de' } )
t.not( trailer, trailerDE, 'returns a language-specific video' )
} )
test( 'fetch movie trailer with year in object form', async t => {
t.plan( 2 )
const trailer = await movieTrailer( 'oceans eleven', { year: 1960 } )
t.is( trailer.indexOf( 'http' ), 0, 'returns a url' )
t.not( trailer.indexOf( 'youtube' ), -1, 'returns a youtube url' )
} )
test( 'fetch multiple trailers', async t => {
t.plan( 3 )
const trailer = await movieTrailer( 'oceans eleven', true )
t.is( typeof trailer, 'object' )
t.is( trailer[0].indexOf( 'http' ), 0, 'returns a url' )
t.not( trailer[0].indexOf( 'youtube' ), -1, 'returns a youtube url' )
} )
test( 'fetch multiple trailers in object form', async t => {
t.plan( 3 )
const trailer = await movieTrailer( 'oceans eleven', { multi: true } )
t.is( typeof trailer, 'object' )
t.is( trailer[0].indexOf( 'http' ), 0, 'returns a url' )
t.not( trailer[0].indexOf( 'youtube' ), -1, 'returns a youtube url' )
} )
test( 'fetch multiple trailers with year', async t => {
t.plan( 3 )
const trailer = await movieTrailer( 'oceans eleven', { multi: true, year: 1960 } )
t.is( typeof trailer, 'object' )
t.is( trailer[0].indexOf( 'http' ), 0, 'returns a url' )
t.not( trailer[0].indexOf( 'youtube' ), -1, 'returns a youtube url' )
} )
test( 'fetch using a custom api_key', async t => {
t.plan( 2 )
const trailer = await movieTrailer( 'oceans eleven', { apiKey: '9d2bff12ed955c7f1f74b83187f188ae' } )
t.is( trailer.indexOf( 'http' ), 0, 'returns a url' )
t.not( trailer.indexOf( 'youtube' ), -1, 'returns a youtube url' )
} )
test( 'calls the callback', async t => {
t.plan( 2 )
await movieTrailer( 'oceans eleven', ( _error, result ) => {
t.is( result.indexOf( 'http' ), 0, 'returns a url' )
t.not( result.indexOf( 'youtube' ), -1, 'returns a youtube url' )
} )
} )
test( 'calls the callback with a year', async t => {
t.plan( 2 )
await movieTrailer( 'oceans eleven', 1960, ( _error, result ) => {
t.is( result.indexOf( 'http' ), 0, 'returns a url' )
t.not( result.indexOf( 'youtube' ), -1, 'returns a youtube url' )
} )
} )
test( 'calls the callback with multiple trailers', async t => {
t.plan( 3 )
await movieTrailer( 'oceans eleven', true, ( _error, result ) => {
t.is( typeof result, 'object' )
t.is( result[0].indexOf( 'http' ), 0, 'returns a url' )
t.not( result[0].indexOf( 'youtube' ), -1, 'returns a youtube url' )
} )
} )
test( 'calls the callback with a year and multiple trailers', async t => {
t.plan( 3 )
await movieTrailer( 'oceans eleven', { multi: true, year: 1960 }, ( _error, result ) => {
t.is( typeof result, 'object' )
t.is( result[0].indexOf( 'http' ), 0, 'returns a url' )
t.not( result[0].indexOf( 'youtube' ), -1, 'returns a youtube url' )
} )
} )