Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
lacymorrow committed Nov 29, 2022
1 parent 94edeca commit 9c1f4a1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 54 deletions.
27 changes: 26 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
.fuse*
.DS*
*.lock

# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Deployed apps should consider commenting this line out:
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules
28 changes: 19 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,25 @@
"type": "git",
"url": "git://github.com/lacymorrow/movie-trailer"
},
"bin": {
"movie-trailer": "cli.js"
},
"author": {
"name": "Lacy Morrow",
"email": "me@lacymorrow.com",
"url": "http://lacymorrow.com"
},
"funding": [
{
"type": "patreon",
"url": "https://patreon.com/lacymorrow"
},
{
"type": "individual",
"url": "http://lacymorrow.com/donate"
},
"https://www.buymeacoffee.com/lm"
],
"bin": {
"movie-trailer": "cli.js"
},
"engines": {
"node": ">=7.6.0"
},
Expand All @@ -39,19 +50,18 @@
"uri",
"path"
],
"devDependencies": {
"ava": "^0.25.0"
},
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/lacymorrow/movie-trailer/issues"
},
"homepage": "https://github.com/lacymorrow/movie-trailer",
"devDependencies": {
"ava": "^5.1.0"
},
"dependencies": {
"isomorphic-fetch": "^2.2.1",
"isomorphic-fetch": "^3.0.0",
"meow": "^4.0.0",
"node-fetch": "^2.1.2",
"np": "^7.2.0",
"np": "^7.6.2",
"xo": "^0.37.1"
},
"np": {
Expand Down
57 changes: 13 additions & 44 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'
import test from 'ava'
import movieTrailer from './index.js'
const test = require( 'ava' )
const movieTrailer = require( './index' )

test( 'fetch movie trailer', async t => {

Expand All @@ -15,11 +15,8 @@ test( 'fetch movie trailer', async t => {

test( 'dont fetch empty search', async t => {

// Testing no search quety, should error
const error = await t.throws( movieTrailer( null )
.catch( error_ => Promise.reject( error_ ) )
)

// 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)' )

} )
Expand Down Expand Up @@ -62,7 +59,7 @@ test( 'fetch movie trailer with language', async t => {
t.plan( 1 )

const trailer = await movieTrailer( 'up' )
const trailerDE = await movieTrailer( 'up', { language: 'de_DE' } )
const trailerDE = await movieTrailer( 'up', { language: 'de' } )

t.not( trailer, trailerDE, 'returns a language-specific video' )

Expand Down Expand Up @@ -126,83 +123,55 @@ test( 'fetch using a custom api_key', async t => {

} )

test.cb( 'calls the callback', t => {
test( 'calls the callback', async t => {

t.plan( 2 )

movieTrailer( 'oceans eleven', ( error, result ) => {

if ( error ) {

return t.end( error )

}
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' )
t.end()

} )

} )

test.cb( 'calls the callback with a year', t => {
test( 'calls the callback with a year', async t => {

t.plan( 2 )

movieTrailer( 'oceans eleven', 1960, ( error, result ) => {

if ( error ) {

return t.end( error )

}
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' )
t.end()

} )

} )

test.cb( 'calls the callback with multiple trailers', t => {
test( 'calls the callback with multiple trailers', async t => {

t.plan( 3 )

movieTrailer( 'oceans eleven', true, ( error, result ) => {

if ( error ) {

return t.end( error )

}
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' )
t.end()

} )

} )

test.cb( 'calls the callback with a year and multiple trailers', t => {
test( 'calls the callback with a year and multiple trailers', async t => {

t.plan( 3 )

movieTrailer( 'oceans eleven', { multi: true, year: 1960 }, ( error, result ) => {

if ( error ) {

return t.end( error )

}
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' )
t.end()

} )

Expand Down

0 comments on commit 9c1f4a1

Please sign in to comment.