diff --git a/package.json b/package.json index 1e299af..f6e4ef2 100644 --- a/package.json +++ b/package.json @@ -29,13 +29,18 @@ "babel-eslint": "^7.0.0", "babel-preset-es2015-node4": "^2.1.0", "babel-preset-stage-2": "^6.5.0", + "babel-register": "^6.24.1", "eslint": "^3.1.1", "eslint-config-airbnb-base": "^11.0.0", - "eslint-plugin-import": "^2.0.1" + "eslint-plugin-import": "^2.0.1", + "nock": "^9.0.2", + "tape": "^4.6.3" }, "scripts": { "prepublish": "npm run build", - "test": "eslint src", + "test": "npm run tape && npm run lint", + "lint": "eslint src", + "tape": "tape -r ./test/init.js ./test/test.js", "build": "babel --out-file index.js src/index.js" } } diff --git a/test/init.js b/test/init.js new file mode 100644 index 0000000..dbad677 --- /dev/null +++ b/test/init.js @@ -0,0 +1,37 @@ +const Test = require('tape/lib/test'); +require('babel-register'); + +/** + * Monkeypatch support for returning Promises from Tape tests. Mostly just + * copied some code from Tape. + */ + +Test.prototype.run = function run() { + if (this._skip) { + this.comment(`SKIP ${this.name}`); + } + if (!this._cb || this._skip) { + return this._end(); + } + if (this._timeout != null) { + this.timeoutAfter(this._timeout); + } + this.emit('prerun'); + + // Start custom code + const result = this._cb(this); + if (result && result.then) { + result.catch( + (err) => { + if (err) { + this.error(err); + } else { + this.fail(err); + } + } + ); + } + // End custom code + + this.emit('run'); +}; diff --git a/test/responses/beyonceVideos.json b/test/responses/beyonceVideos.json new file mode 100644 index 0000000..00372ce --- /dev/null +++ b/test/responses/beyonceVideos.json @@ -0,0 +1,1144 @@ +{ + "items": [ + { + "id": "PeonBmeFR8o", + "snippet": { + "title": "Beyoncé - Hold Up", + "thumbnails": { + "default": { + "url": "https://i.ytimg.com/vi/PeonBmeFR8o/default.jpg", + "width": 120, + "height": 90 + }, + "medium": { + "url": "https://i.ytimg.com/vi/PeonBmeFR8o/mqdefault.jpg", + "width": 320, + "height": 180 + }, + "high": { + "url": "https://i.ytimg.com/vi/PeonBmeFR8o/hqdefault.jpg", + "width": 480, + "height": 360 + }, + "standard": { + "url": "https://i.ytimg.com/vi/PeonBmeFR8o/sddefault.jpg", + "width": 640, + "height": 480 + }, + "maxres": { + "url": "https://i.ytimg.com/vi/PeonBmeFR8o/maxresdefault.jpg", + "width": 1280, + "height": 720 + } + }, + "channelTitle": "beyonceVEVO" + }, + "contentDetails": { + "duration": "PT5M17S", + "regionRestriction": { + "allowed": [ + "BB", + "BA", + "BG", + "BF", + "BE", + "BD", + "BJ", + "BI", + "JP", + "BO", + "BN", + "BM", + "BL", + "BS", + "BR", + "BW", + "BV", + "JM", + "BT", + "BZ", + "BY", + "JE", + "ST", + "SV", + "WF", + "SR", + "SZ", + "SE", + "SG", + "SB", + "SC", + "SL", + "SM", + "SN", + "SO", + "SH", + "SI", + "SJ", + "SK", + "CD", + "CF", + "CG", + "CA", + "KZ", + "CC", + "CL", + "CM", + "CN", + "CO", + "CH", + "CI", + "KR", + "CK", + "CU", + "KN", + "KH", + "KI", + "CR", + "KE", + "KG", + "CX", + "CY", + "CZ", + "PY", + "HK", + "PR", + "HM", + "PT", + "PW", + "HN", + "PH", + "PK", + "HR", + "PM", + "PL", + "PN", + "PA", + "PE", + "PG", + "PF", + "UG", + "UA", + "UM", + "GA", + "DZ", + "DE", + "US", + "DM", + "DO", + "UZ", + "DK", + "UY", + "MN", + "MO", + "ML", + "MM", + "MK", + "MH", + "MF", + "MG", + "MD", + "ME", + "GB", + "MC", + "MA", + "MZ", + "MX", + "MY", + "MV", + "MW", + "MT", + "MU", + "MR", + "MS", + "MP", + "MQ", + "ET", + "ER", + "ES", + "ZM", + "ZA", + "EE", + "EC", + "ZW", + "RS", + "RW", + "RU", + "HT", + "RE", + "RO", + "FO", + "FM", + "FK", + "FJ", + "FI", + "WS", + "FR", + "GP", + "TD", + "TG", + "GS", + "GT", + "GU", + "TC", + "GW", + "TM", + "GY", + "TO", + "TN", + "HU", + "TH", + "TK", + "TJ", + "TT", + "TW", + "TV", + "GD", + "GE", + "GF", + "GG", + "GH", + "GI", + "GL", + "GM", + "GN", + "TZ", + "LI", + "LK", + "LA", + "LC", + "LU", + "LT", + "LV", + "LS", + "LR", + "YT", + "GQ", + "GR", + "TF", + "KY", + "TR", + "ID", + "IE", + "IN", + "IO", + "IL", + "IM", + "IS", + "IT", + "TL", + "DJ", + "AI", + "AO", + "AL", + "AM", + "KP", + "AG", + "AD", + "AZ", + "AX", + "AR", + "AS", + "AQ", + "AW", + "AT", + "AU", + "NG", + "NF", + "NE", + "NC", + "NA", + "KM", + "NO", + "VU", + "NL", + "CV", + "NI", + "VN", + "NU", + "NR", + "VI", + "NP", + "VG", + "VE", + "VC", + "NZ", + "VA" + ] + } + } + }, + { + "id": "gM89Q5Eng_M", + "snippet": { + "title": "Beyoncé - All Night", + "thumbnails": { + "default": { + "url": "https://i.ytimg.com/vi/gM89Q5Eng_M/default.jpg", + "width": 120, + "height": 90 + }, + "medium": { + "url": "https://i.ytimg.com/vi/gM89Q5Eng_M/mqdefault.jpg", + "width": 320, + "height": 180 + }, + "high": { + "url": "https://i.ytimg.com/vi/gM89Q5Eng_M/hqdefault.jpg", + "width": 480, + "height": 360 + }, + "standard": { + "url": "https://i.ytimg.com/vi/gM89Q5Eng_M/sddefault.jpg", + "width": 640, + "height": 480 + }, + "maxres": { + "url": "https://i.ytimg.com/vi/gM89Q5Eng_M/maxresdefault.jpg", + "width": 1280, + "height": 720 + } + }, + "channelTitle": "beyonceVEVO" + }, + "contentDetails": { + "duration": "PT6M22S", + "regionRestriction": { + "allowed": [ + "BB", + "BA", + "BG", + "BF", + "BE", + "BD", + "BJ", + "BI", + "BH", + "BO", + "BN", + "BM", + "BL", + "BS", + "BR", + "BW", + "BV", + "JM", + "BT", + "BZ", + "BY", + "JE", + "ST", + "SV", + "FI", + "SR", + "SY", + "SZ", + "SD", + "SE", + "SG", + "SA", + "SB", + "SC", + "SL", + "SM", + "SN", + "SO", + "SH", + "SI", + "SJ", + "SK", + "CD", + "CF", + "CG", + "KY", + "KZ", + "CC", + "CL", + "CM", + "CN", + "KW", + "CH", + "CI", + "KR", + "CK", + "KM", + "KN", + "KH", + "KI", + "CR", + "KE", + "KG", + "CX", + "CY", + "CZ", + "PY", + "HK", + "PR", + "HM", + "PT", + "PW", + "HN", + "PH", + "PK", + "HR", + "HU", + "HT", + "PN", + "PA", + "JO", + "PE", + "PS", + "PG", + "PF", + "UG", + "UA", + "UM", + "GA", + "DZ", + "DE", + "US", + "DM", + "DO", + "UZ", + "DK", + "UY", + "MN", + "MO", + "ML", + "MM", + "MK", + "MH", + "MF", + "MG", + "MD", + "ME", + "GB", + "MC", + "MA", + "MZ", + "MX", + "MY", + "MV", + "MW", + "MT", + "MU", + "MR", + "MS", + "MP", + "MQ", + "PM", + "ET", + "ER", + "ES", + "ZM", + "ZA", + "EG", + "EE", + "EC", + "ZW", + "EH", + "PL", + "RS", + "RW", + "RU", + "JP", + "RE", + "RO", + "FO", + "FM", + "FK", + "FJ", + "WF", + "WS", + "FR", + "OM", + "DJ", + "GP", + "GQ", + "GR", + "GS", + "GT", + "GU", + "TC", + "GW", + "TM", + "GY", + "TO", + "TN", + "TH", + "TK", + "TJ", + "TT", + "TW", + "TV", + "GD", + "GE", + "GF", + "GG", + "GH", + "GI", + "GL", + "GM", + "GN", + "TZ", + "LI", + "LK", + "LA", + "LC", + "LB", + "LY", + "LU", + "LT", + "LV", + "LS", + "LR", + "YT", + "TD", + "TG", + "CO", + "TF", + "YE", + "CA", + "TR", + "ID", + "IE", + "IN", + "IO", + "IL", + "IM", + "IR", + "IS", + "IQ", + "IT", + "TL", + "QA", + "AI", + "AO", + "AL", + "AM", + "KP", + "AF", + "AG", + "AD", + "AE", + "AZ", + "AX", + "AR", + "AS", + "AQ", + "AW", + "AT", + "AU", + "NG", + "NF", + "NE", + "NC", + "NA", + "CU", + "NO", + "VU", + "NL", + "CV", + "NI", + "VN", + "NU", + "NR", + "VI", + "NP", + "VG", + "VE", + "VC", + "NZ", + "VA" + ] + } + } + }, + { + "id": "QxsmWxxouIM", + "snippet": { + "title": "Beyoncé - Sorry", + "thumbnails": { + "default": { + "url": "https://i.ytimg.com/vi/QxsmWxxouIM/default.jpg", + "width": 120, + "height": 90 + }, + "medium": { + "url": "https://i.ytimg.com/vi/QxsmWxxouIM/mqdefault.jpg", + "width": 320, + "height": 180 + }, + "high": { + "url": "https://i.ytimg.com/vi/QxsmWxxouIM/hqdefault.jpg", + "width": 480, + "height": 360 + }, + "standard": { + "url": "https://i.ytimg.com/vi/QxsmWxxouIM/sddefault.jpg", + "width": 640, + "height": 480 + }, + "maxres": { + "url": "https://i.ytimg.com/vi/QxsmWxxouIM/maxresdefault.jpg", + "width": 1280, + "height": 720 + } + }, + "channelTitle": "beyonceVEVO" + }, + "contentDetails": { + "duration": "PT4M26S", + "regionRestriction": { + "allowed": [ + "BB", + "BA", + "BG", + "BF", + "BE", + "BD", + "BJ", + "BI", + "JP", + "BO", + "BN", + "BM", + "BL", + "BS", + "BR", + "BW", + "BV", + "JM", + "BT", + "BZ", + "BY", + "JE", + "ST", + "SV", + "WF", + "SR", + "SZ", + "SE", + "SG", + "SB", + "SC", + "SL", + "SM", + "SN", + "SO", + "SH", + "SI", + "SJ", + "SK", + "CD", + "CF", + "CG", + "KY", + "KZ", + "CC", + "CL", + "CM", + "CN", + "CO", + "KP", + "CI", + "KR", + "CK", + "KM", + "CV", + "KH", + "KI", + "CR", + "KE", + "KG", + "CX", + "CY", + "CZ", + "PY", + "HK", + "PR", + "HM", + "PT", + "PW", + "HN", + "PH", + "PK", + "HR", + "HU", + "PL", + "PN", + "PA", + "PE", + "PG", + "PF", + "UG", + "UA", + "UM", + "GA", + "DZ", + "DE", + "US", + "DM", + "DO", + "UZ", + "DK", + "UY", + "MN", + "MO", + "ML", + "MM", + "MK", + "MH", + "MF", + "MG", + "MD", + "ME", + "MC", + "MA", + "MZ", + "MX", + "MY", + "MV", + "MW", + "MT", + "MU", + "MR", + "MS", + "MP", + "MQ", + "PM", + "ET", + "ER", + "ES", + "ZM", + "ZA", + "EE", + "EC", + "ZW", + "RS", + "RW", + "RU", + "HT", + "RE", + "RO", + "FO", + "FM", + "FK", + "FJ", + "FI", + "TW", + "WS", + "FR", + "GP", + "GQ", + "TG", + "GS", + "GT", + "GU", + "TC", + "GW", + "TM", + "GY", + "TO", + "TN", + "TH", + "TK", + "TJ", + "TT", + "GB", + "TV", + "GD", + "GE", + "GF", + "GG", + "GH", + "GI", + "GL", + "GM", + "GN", + "TZ", + "LI", + "LK", + "LA", + "LC", + "LU", + "LT", + "LV", + "LS", + "LR", + "YT", + "TD", + "GR", + "TF", + "CA", + "TR", + "ID", + "IE", + "IN", + "IO", + "IL", + "IM", + "IS", + "IT", + "TL", + "DJ", + "AI", + "AO", + "AL", + "AM", + "CH", + "AG", + "AD", + "AZ", + "AX", + "AR", + "AS", + "AQ", + "AW", + "AT", + "AU", + "NG", + "NF", + "NE", + "NC", + "NA", + "CU", + "NO", + "VU", + "NL", + "KN", + "NI", + "VN", + "NU", + "NR", + "VI", + "NP", + "VG", + "VE", + "VC", + "NZ", + "VA" + ] + } + } + }, + { + "id": "WDZJPJV__bQ", + "snippet": { + "title": "Beyoncé - Formation", + "thumbnails": { + "default": { + "url": "https://i.ytimg.com/vi/WDZJPJV__bQ/default.jpg", + "width": 120, + "height": 90 + }, + "medium": { + "url": "https://i.ytimg.com/vi/WDZJPJV__bQ/mqdefault.jpg", + "width": 320, + "height": 180 + }, + "high": { + "url": "https://i.ytimg.com/vi/WDZJPJV__bQ/hqdefault.jpg", + "width": 480, + "height": 360 + }, + "standard": { + "url": "https://i.ytimg.com/vi/WDZJPJV__bQ/sddefault.jpg", + "width": 640, + "height": 480 + }, + "maxres": { + "url": "https://i.ytimg.com/vi/WDZJPJV__bQ/maxresdefault.jpg", + "width": 1280, + "height": 720 + } + }, + "channelTitle": "beyonceVEVO" + }, + "contentDetails": { + "duration": "PT4M48S", + "regionRestriction": { + "allowed": [ + "BB", + "BA", + "BG", + "BF", + "BE", + "BD", + "BJ", + "BI", + "BH", + "BO", + "BN", + "BM", + "BL", + "BS", + "BR", + "JO", + "BV", + "JM", + "BT", + "BZ", + "BY", + "JE", + "ST", + "SV", + "WF", + "SR", + "SY", + "SZ", + "SD", + "SE", + "SG", + "SA", + "SB", + "SC", + "SL", + "SM", + "SN", + "SO", + "SH", + "SI", + "SJ", + "SK", + "CD", + "CF", + "CG", + "KY", + "KZ", + "CC", + "CL", + "CM", + "CN", + "KW", + "KP", + "CI", + "KR", + "CK", + "KM", + "KN", + "KH", + "KI", + "CR", + "KE", + "KG", + "CX", + "CY", + "CZ", + "PY", + "CV", + "HK", + "PR", + "HM", + "PT", + "PW", + "HN", + "PH", + "PK", + "HR", + "PM", + "PL", + "PN", + "PA", + "BW", + "PE", + "PS", + "PG", + "PF", + "UG", + "UA", + "UM", + "DZ", + "DE", + "AI", + "US", + "DM", + "DO", + "UZ", + "DK", + "DJ", + "MN", + "MO", + "ML", + "MM", + "MK", + "MH", + "MF", + "MG", + "MD", + "ME", + "MC", + "MA", + "MZ", + "MX", + "MY", + "MV", + "MW", + "MT", + "MU", + "MR", + "MS", + "MP", + "MQ", + "ET", + "ER", + "ES", + "ZM", + "ZA", + "EG", + "EE", + "EC", + "ZW", + "EH", + "RS", + "RW", + "RU", + "JP", + "HT", + "RE", + "RO", + "FO", + "FM", + "FK", + "FJ", + "FI", + "WS", + "FR", + "OM", + "GP", + "GQ", + "GR", + "GS", + "GT", + "GU", + "TC", + "GW", + "TM", + "GY", + "TO", + "TN", + "HU", + "TH", + "TK", + "TJ", + "GA", + "GB", + "TV", + "GD", + "GE", + "GF", + "GG", + "GH", + "GI", + "GL", + "GM", + "GN", + "TZ", + "LI", + "LK", + "LA", + "LC", + "LB", + "LY", + "LU", + "LT", + "LV", + "CU", + "LS", + "LR", + "YT", + "TD", + "TG", + "TF", + "YE", + "CA", + "TR", + "ID", + "IE", + "IN", + "IO", + "IL", + "IM", + "IR", + "IS", + "IQ", + "IT", + "TL", + "QA", + "CO", + "AO", + "AL", + "AM", + "CH", + "AF", + "AG", + "AD", + "AE", + "AZ", + "AX", + "AR", + "AS", + "AQ", + "AW", + "AT", + "AU", + "NG", + "NF", + "NE", + "NC", + "NA", + "TT", + "NO", + "VU", + "NL", + "UY", + "TW", + "NI", + "VN", + "NU", + "NR", + "VI", + "NP", + "VG", + "VE", + "VC", + "NZ", + "VA" + ] + } + } + }, + { + "id": "k4YRWT_Aldo", + "snippet": { + "title": "Beyoncé - 7/11", + "thumbnails": { + "default": { + "url": "https://i.ytimg.com/vi/k4YRWT_Aldo/default.jpg", + "width": 120, + "height": 90 + }, + "medium": { + "url": "https://i.ytimg.com/vi/k4YRWT_Aldo/mqdefault.jpg", + "width": 320, + "height": 180 + }, + "high": { + "url": "https://i.ytimg.com/vi/k4YRWT_Aldo/hqdefault.jpg", + "width": 480, + "height": 360 + }, + "standard": { + "url": "https://i.ytimg.com/vi/k4YRWT_Aldo/sddefault.jpg", + "width": 640, + "height": 480 + } + }, + "channelTitle": "Beyoncé" + }, + "contentDetails": { + "duration": "PT3M37S" + } + } + ] +} diff --git a/test/responses/getVideos.json b/test/responses/getVideos.json new file mode 100644 index 0000000..8eb3d08 --- /dev/null +++ b/test/responses/getVideos.json @@ -0,0 +1,79 @@ + +{ + "items": [ + { + "id": "n0gAo8z859U", + "snippet": { + "title": "LAYBACKSOUND - 4hours (feat. Leebada) official M/V", + "thumbnails": { + "default": { + "url": "https://i.ytimg.com/vi/n0gAo8z859U/default.jpg", + "width": 120, + "height": 90 + }, + "medium": { + "url": "https://i.ytimg.com/vi/n0gAo8z859U/mqdefault.jpg", + "width": 320, + "height": 180 + }, + "high": { + "url": "https://i.ytimg.com/vi/n0gAo8z859U/hqdefault.jpg", + "width": 480, + "height": 360 + }, + "standard": { + "url": "https://i.ytimg.com/vi/n0gAo8z859U/sddefault.jpg", + "width": 640, + "height": 480 + }, + "maxres": { + "url": "https://i.ytimg.com/vi/n0gAo8z859U/maxresdefault.jpg", + "width": 1280, + "height": 720 + } + }, + "channelTitle": "LAYBACKSOUND" + }, + "contentDetails": { + "duration": "PT3M52S" + } + }, + { + "id": "XO4xNQ-pWPQ", + "snippet": { + "title": "KIRARA - ct16072", + "thumbnails": { + "default": { + "url": "https://i.ytimg.com/vi/XO4xNQ-pWPQ/default.jpg", + "width": 120, + "height": 90 + }, + "medium": { + "url": "https://i.ytimg.com/vi/XO4xNQ-pWPQ/mqdefault.jpg", + "width": 320, + "height": 180 + }, + "high": { + "url": "https://i.ytimg.com/vi/XO4xNQ-pWPQ/hqdefault.jpg", + "width": 480, + "height": 360 + }, + "standard": { + "url": "https://i.ytimg.com/vi/XO4xNQ-pWPQ/sddefault.jpg", + "width": 640, + "height": 480 + }, + "maxres": { + "url": "https://i.ytimg.com/vi/XO4xNQ-pWPQ/maxresdefault.jpg", + "width": 1280, + "height": 720 + } + }, + "channelTitle": "kirarararararararara" + }, + "contentDetails": { + "duration": "PT3M18S" + } + } + ] +} diff --git a/test/responses/search.json b/test/responses/search.json new file mode 100644 index 0000000..c6a979f --- /dev/null +++ b/test/responses/search.json @@ -0,0 +1,52 @@ +{ + "kind": "youtube#searchListResponse", + "etag": "\"gMxXHe-zinKdE9lTnzKu8vjcmDI/bRgEpUWXlAaVvqSnPj3HgYtq25s\"", + "nextPageToken": "CAUQAA", + "regionCode": "NL", + "pageInfo": { + "totalResults": 1000000, + "resultsPerPage": 5 + }, + "items": [ + { + "kind": "youtube#searchResult", + "etag": "\"gMxXHe-zinKdE9lTnzKu8vjcmDI/3uc-H13gVHg2ViGsA8rV1Q_Bx2o\"", + "id": { + "kind": "youtube#video", + "videoId": "PeonBmeFR8o" + } + }, + { + "kind": "youtube#searchResult", + "etag": "\"gMxXHe-zinKdE9lTnzKu8vjcmDI/R_EIM6YM2qFbmyD1niiaMCpbI44\"", + "id": { + "kind": "youtube#video", + "videoId": "gM89Q5Eng_M" + } + }, + { + "kind": "youtube#searchResult", + "etag": "\"gMxXHe-zinKdE9lTnzKu8vjcmDI/NkHDY8Xx-2xT4fDkna7KeswstQI\"", + "id": { + "kind": "youtube#video", + "videoId": "QxsmWxxouIM" + } + }, + { + "kind": "youtube#searchResult", + "etag": "\"gMxXHe-zinKdE9lTnzKu8vjcmDI/fMtk_SXtAfK_9kwE4vLCyrNVDsQ\"", + "id": { + "kind": "youtube#video", + "videoId": "WDZJPJV__bQ" + } + }, + { + "kind": "youtube#searchResult", + "etag": "\"gMxXHe-zinKdE9lTnzKu8vjcmDI/iKLQcTjvcyzEWTOfd-kRf1eMXvw\"", + "id": { + "kind": "youtube#video", + "videoId": "k4YRWT_Aldo" + } + } + ] +} diff --git a/test/responses/useChannelName.json b/test/responses/useChannelName.json new file mode 100644 index 0000000..01feab2 --- /dev/null +++ b/test/responses/useChannelName.json @@ -0,0 +1,36 @@ +{ + "items": [ + { + "id": "t6gDp9IsBgw", + "snippet": { + "title": "신의 놀이 (Playing God) (Official Video)", + "thumbnails": { + "default": { + "url": "https://i.ytimg.com/vi/t6gDp9IsBgw/default.jpg", + "width": 120, + "height": 90 + }, + "medium": { + "url": "https://i.ytimg.com/vi/t6gDp9IsBgw/mqdefault.jpg", + "width": 320, + "height": 180 + }, + "high": { + "url": "https://i.ytimg.com/vi/t6gDp9IsBgw/hqdefault.jpg", + "width": 480, + "height": 360 + }, + "standard": { + "url": "https://i.ytimg.com/vi/t6gDp9IsBgw/sddefault.jpg", + "width": 640, + "height": 480 + } + }, + "channelTitle": "lang lee" + }, + "contentDetails": { + "duration": "PT3M38S" + } + } + ] +} diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..84eed13 --- /dev/null +++ b/test/test.js @@ -0,0 +1,79 @@ +const test = require('tape'); +const nock = require('nock'); +const path = require('path'); +const youTubeSource = require('../').default; + +const FAKE_KEY = 'AIzaSyVBDlZqp3o65v9zFWv0Qxij1rt3axCWqs9'; + +const createSource = () => + youTubeSource({}, { key: FAKE_KEY }); + +const API_HOST = 'https://www.googleapis.com'; + +const fixture = name => path.join(__dirname, 'responses', `${name}.json`); + +test('providing a key is required', (t) => { + t.throws( + () => youTubeSource({}), + /Expected a YouTube API key/ + ); + + t.end(); +}); + +test('searching for videos', async (t) => { + const src = createSource(); + + nock(API_HOST).get('/youtube/v3/search') + .query(true) + .replyWithFile(200, fixture('search')); + nock(API_HOST).get('/youtube/v3/videos') + .query(true) + .replyWithFile(200, fixture('beyonceVideos')); + + const results = await src.search('Beyoncé'); + + // Our mocked search only returns 5 items. Actual search would return 50. 🙈 + t.is(results.length, 5); + + results.forEach((item) => { + t.true('artist' in item); + t.true('title' in item); + }); + + t.end(); +}); + +test('get videos by id', async (t) => { + const src = createSource(); + + nock(API_HOST).get('/youtube/v3/videos') + .query(true) + .replyWithFile(200, fixture('getVideos')); + + const items = await src.get(['n0gAo8z859U', 'XO4xNQ-pWPQ']); + + t.is(items.length, 2); + + t.is(items[0].artist, 'LAYBACKSOUND'); + t.is(items[1].artist, 'KIRARA'); + + t.end(); +}); + +test('defaults to using the channel name as the artist name', async (t) => { + const src = createSource(); + + nock(API_HOST).get('/youtube/v3/videos') + .query(true) + // The fixture is edited to remove the artist name from the song title. + .replyWithFile(200, fixture('useChannelName')); + + const items = await src.get(['t6gDp9IsBgw']); + + t.is(items.length, 1); + t.is(items[0].artist, 'lang lee'); + t.is(items[0].title, '신의 놀이 (Playing God)'); + + t.end(); +});