index.spec.js (1504B)
1 const searchYoutube = require('../src'); 2 const assert = require('assert'); 3 4 require('dotenv').config(); 5 6 describe('Search The Youtube Api',function(){ 7 //key , options , cb 8 const options = { 9 q:'nodejs', 10 part:'snippet', 11 type:'video' 12 } 13 it('should return a Response object using a callback',function(done){ 14 searchYoutube(process.env.YOUTUBE_KEY,options,function(err, result){ 15 //result.kind: 'youtube#searchListResponse' 16 if(err) done(err); 17 assert.deepEqual(result.kind,'youtube#searchListResponse'); 18 done(); 19 }); 20 }); 21 22 it('should return a Response object using a Promise',function(done){ 23 24 searchYoutube(process.env.YOUTUBE_KEY,options) 25 .then(result => { 26 assert.deepEqual(result.kind,'youtube#searchListResponse'); 27 done(); 28 }) 29 .catch(err => {done(err)}); 30 }); 31 32 it('should Throw API Key is required! using callback',function(done){ 33 searchYoutube(null,null,(err,res)=>{ 34 assert.equal(err.message, 'API Key is required','did not throw API Key is required message') 35 done(); 36 }); 37 }); 38 39 40 it('should Throw API Key is required! using Promise',function(done){ 41 assert.throws(searchYoutube,/API Key is required/,'did not throw API Key is required message'); 42 done(); 43 }); 44 45 it('should return a response #Async' , async () => { 46 let result = await searchYoutube(process.env.YOUTUBE_KEY,options); 47 assert.deepEqual(result.kind,'youtube#searchListResponse'); 48 }) 49 });