Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lgaticaq committed Mar 19, 2016
1 parent 0d3237a commit 27f5dfe
Show file tree
Hide file tree
Showing 5 changed files with 353 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/chapter.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<div class="vervideo" style="background-image: url(http://cdn.jkanime.net/assets/images/video_title.png); width:299px; font-size:13px; letter-spacing:0px; margin: 0 0 0 15px;">One Piece - 100</div>
<iframe class="player_conte" src="https://jkanime.net/jk.php?u=stream/jkmedia/5b90b1cddd69bab5ebf007b1742fb9fd/4f501d26373b56e0fe0351c1a6154bd4/1/1de4451f8844a9c171830d25ff1cebbb/" width="565" height="318" scrolling="no" frameborder="0" allowfullscreen="true"></iframe>
76 changes: 76 additions & 0 deletions test/chapters.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<div class="listnavi">
<a class="listpag list22" href="#pag1">1 - 10</a>
<a class="listpag list22" href="#pag2">11 - 20</a>
<a class="listpag list22" href="#pag3">21 - 30</a>
<a class="listpag list22" href="#pag4">31 - 40</a>
<a class="listpag list22" href="#pag5">41 - 50</a>
<a class="listpag list22" href="#pag6">51 - 60</a>
<a class="listpag list22" href="#pag7">61 - 70</a>
<a class="listpag list22" href="#pag8">71 - 80</a>
<a class="listpag list22" href="#pag9">81 - 90</a>
<a class="listpag list22" href="#pag10">91 - 100</a>
<a class="listpag list22" href="#pag11">101 - 110</a>
<a class="listpag list22" href="#pag12">111 - 120</a>
<a class="listpag list22" href="#pag13">121 - 130</a>
<a class="listpag list22" href="#pag14">131 - 140</a>
<a class="listpag list22" href="#pag15">141 - 150</a>
<a class="listpag list22" href="#pag16">151 - 160</a>
<a class="listpag list22" href="#pag17">161 - 170</a>
<a class="listpag list22" href="#pag18">171 - 180</a>
<a class="listpag list22" href="#pag19">181 - 190</a>
<a class="listpag list22" href="#pag20">191 - 200</a>
<a class="listpag list22" href="#pag21">201 - 210</a>
<a class="listpag list22" href="#pag22">211 - 220</a>
<a class="listpag list22" href="#pag23">221 - 230</a>
<a class="listpag list22" href="#pag24">231 - 240</a>
<a class="listpag list22" href="#pag25">241 - 250</a>
<a class="listpag list22" href="#pag26">251 - 260</a>
<a class="listpag list22" href="#pag27">261 - 270</a>
<a class="listpag list22" href="#pag28">271 - 280</a>
<a class="listpag list22" href="#pag29">281 - 290</a>
<a class="listpag list22" href="#pag30">291 - 300</a>
<a class="listpag list22" href="#pag31">301 - 310</a>
<a class="listpag list22" href="#pag32">311 - 320</a>
<a class="listpag list22" href="#pag33">321 - 330</a>
<a class="listpag list22" href="#pag34">331 - 340</a>
<a class="listpag list22" href="#pag35">341 - 350</a>
<a class="listpag list22" href="#pag36">351 - 360</a>
<a class="listpag list22" href="#pag37">361 - 370</a>
<a class="listpag list22" href="#pag38">371 - 380</a>
<a class="listpag list22" href="#pag39">381 - 390</a>
<a class="listpag list22" href="#pag40">391 - 400</a>
<a class="listpag list22" href="#pag41">401 - 410</a>
<a class="listpag list22" href="#pag42">411 - 420</a>
<a class="listpag list22" href="#pag43">421 - 430</a>
<a class="listpag list22" href="#pag44">431 - 440</a>
<a class="listpag list22" href="#pag45">441 - 450</a>
<a class="listpag list22" href="#pag46">451 - 460</a>
<a class="listpag list22" href="#pag47">461 - 470</a>
<a class="listpag list22" href="#pag48">471 - 480</a>
<a class="listpag list22" href="#pag49">481 - 490</a>
<a class="listpag list22" href="#pag50">491 - 500</a>
<a class="listpag list22" href="#pag51">501 - 510</a>
<a class="listpag list22" href="#pag52">511 - 520</a>
<a class="listpag list22" href="#pag53">521 - 530</a>
<a class="listpag list22" href="#pag54">531 - 540</a>
<a class="listpag list22" href="#pag55">541 - 550</a>
<a class="listpag list22" href="#pag56">551 - 560</a>
<a class="listpag list22" href="#pag57">561 - 570</a>
<a class="listpag list22" href="#pag58">571 - 580</a>
<a class="listpag list22" href="#pag59">581 - 590</a>
<a class="listpag list22" href="#pag60">591 - 600</a>
<a class="listpag list22" href="#pag61">601 - 610</a>
<a class="listpag list22" href="#pag62">611 - 620</a>
<a class="listpag list22" href="#pag63">621 - 630</a>
<a class="listpag list22" href="#pag64">631 - 640</a>
<a class="listpag list22" href="#pag65">641 - 650</a>
<a class="listpag list22" href="#pag66">651 - 660</a>
<a class="listpag list22" href="#pag67">661 - 670</a>
<a class="listpag list22" href="#pag68">671 - 680</a>
<a class="listpag list22" href="#pag69">681 - 690</a>
<a class="listpag list22" href="#pag70">691 - 700</a>
<a class="listpag list22" href="#pag71">701 - 710</a>
<a class="listpag list22" href="#pag72">711 - 720</a>
<a class="listpag list22" href="#pag73">721 - 730</a>
<a class="listpag list22" href="#pag74">731 - 732</a>
</div>
175 changes: 175 additions & 0 deletions test/found.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<div class="listpage">
<table class="search">
<tbody>
<tr>
<td rowspan="2">
<a href="http://jkanime.net/one-piece/"><img src="http://cdn.jkanime.net/assets/images/animes/thumbnail/one-piece.jpg" width="50"></a>
</td>
<td><a class="titl" href="http://jkanime.net/one-piece/">One Piece</a></td>
<td rowspan="2" style="width:50px; text-align:center;">Serie</td>
<td rowspan="2" style="width:50px; text-align:center;">Desc Eps</td>
</tr>
<tr>
<td>
<p>Una historia épica de piratas, donde narra la historia de "Monkey D. Luffy" quien cuando tenia 7 años, comió accidentalmente una "Akuma no mi"(Fruta del diablo) la cual le convirtió en un hombre de goma. Por otra parte… <a class="next" href="http://jkanime.net/one-piece/">seguir leyendo</a></p>
</td>
</tr>
</tbody>
</table>
<table class="search">
<tbody>
<tr>
<td rowspan="2">
<a href="http://jkanime.net/one-piece-taose-kaizoku-ganzack/"><img src="http://cdn.jkanime.net/assets/images/animes/thumbnail/one-piece-taose-kaizoku-ganzack.jpg" width="50"></a>
</td>
<td><a class="titl" href="http://jkanime.net/one-piece-taose-kaizoku-ganzack/">One Piece: Taose! Kaizoku Ganzack</a></td>
<td rowspan="2" style="width:50px; text-align:center;">OVA</td>
<td rowspan="2" style="width:50px; text-align:center;">1 Eps</td>
</tr>
<tr>
<td>
<p>Esta OVA data de 1998, por lo que los personajes que aparecen son Luffy, Zoro y Nami. La trama ocurre cronológicamente después de la batalla con Buggy, comenzando con Luffy y los demás en el bote siendo atacados por un… <a class="next" href="http://jkanime.net/one-piece-taose-kaizoku-ganzack/">seguir leyendo</a></p>
</td>
</tr>
</tbody>
</table>
<table class="search">
<tbody>
<tr>
<td rowspan="2">
<a href="http://jkanime.net/one-piece-romance-dawn/"><img src="http://cdn.jkanime.net/assets/images/animes/thumbnail/one-piece-romance-dawn.jpg" width="50"></a>
</td>
<td><a class="titl" href="http://jkanime.net/one-piece-romance-dawn/">One Piece: Romance Dawn</a></td>
<td rowspan="2" style="width:50px; text-align:center;">OVA</td>
<td rowspan="2" style="width:50px; text-align:center;">1 Eps</td>
</tr>
<tr>
<td>
<p>Basada en la primera versión de Romance Dawn, el prototipo de la historia de One Piece, pero incluye a los miembros de la tripulación hasta la incorporación de Brook, así como la aparición del segundo barco, el Thousand… <a class="next" href="http://jkanime.net/one-piece-romance-dawn/">seguir leyendo</a></p>
</td>
</tr>
</tbody>
</table>
<table class="search">
<tbody>
<tr>
<td rowspan="2">
<a href="http://jkanime.net/one-piece-strong-world-episode-0/"><img src="http://cdn.jkanime.net/assets/images/animes/thumbnail/one-piece-strong-world-episode-0.jpg" width="50"></a>
</td>
<td><a class="titl" href="http://jkanime.net/one-piece-strong-world-episode-0/">One Piece: Strong World Episode 0</a></td>
<td rowspan="2" style="width:50px; text-align:center;">OVA</td>
<td rowspan="2" style="width:50px; text-align:center;">1 Eps</td>
</tr>
<tr>
<td>
<p>El Capítulo 0, llamado "Strong World", trata de un capítulo especial publicado junto al Capítulo 565 del manga y mas tarde en version anime con el nombre de Strong World Episode 0. Lo conforman una serie de breves escenas… <a class="next" href="http://jkanime.net/one-piece-strong-world-episode-0/">seguir leyendo</a></p>
</td>
</tr>
</tbody>
</table>
<table class="search">
<tbody>
<tr>
<td rowspan="2">
<a href="http://jkanime.net/one-piece-recap/"><img src="http://cdn.jkanime.net/assets/images/animes/thumbnail/one-piece-recap.jpg" width="50"></a>
</td>
<td><a class="titl" href="http://jkanime.net/one-piece-recap/">One Piece Recap</a></td>
<td rowspan="2" style="width:50px; text-align:center;">OVA</td>
<td rowspan="2" style="width:50px; text-align:center;">1 Eps</td>
</tr>
<tr>
<td>
<p>Esta OVA es un resumen en conmemoracion de 10 años de One Piece desde el principio hasta la lucha entre Megallan y Luffy (aprox. 445 capitulos en menos de 30 min.) <a class="next" href="http://jkanime.net/one-piece-recap/">seguir leyendo</a></p>
</td>
</tr>
</tbody>
</table>
<table class="search">
<tbody>
<tr>
<td rowspan="2">
<a href="http://jkanime.net/one-piece-episode-of-nami/"><img src="http://cdn.jkanime.net/assets/images/animes/thumbnail/one-piece-episode-of-nami.jpg" width="50"></a>
</td>
<td><a class="titl" href="http://jkanime.net/one-piece-episode-of-nami/">One Piece: Episode of Nami</a></td>
<td rowspan="2" style="width:50px; text-align:center;">Especial</td>
<td rowspan="2" style="width:50px; text-align:center;">1 Eps</td>
</tr>
<tr>
<td>
<p>Episodio especial que está basado en el arco de Nami (uno de los primeros de la serie), y estará realizado completamente desde cero. <a class="next" href="http://jkanime.net/one-piece-episode-of-nami/">seguir leyendo</a></p>
</td>
</tr>
</tbody>
</table>
<table class="search">
<tbody>
<tr>
<td rowspan="2">
<a href="http://jkanime.net/one-piece-episode-of-luffy-hand-island-no-bouken/"><img src="http://cdn.jkanime.net/assets/images/animes/thumbnail/one-piece-episode-of-luffy-hand-island-no-bouken.jpg" width="50"></a>
</td>
<td><a class="titl" href="http://jkanime.net/one-piece-episode-of-luffy-hand-island-no-bouken/">One Piece: Episode of Luffy - Hand Island no Bouken</a></td>
<td rowspan="2" style="width:50px; text-align:center;">Especial</td>
<td rowspan="2" style="width:50px; text-align:center;">1 Eps</td>
</tr>
<tr>
<td>
<p>Este especial va aparte de los cuatro especiales de televisión consecutivos que se empezaron a emitir el 2 de diciembre y que estarán enlazados al argumento de la película One Piece Film Z. La historia se situará poco… <a class="next" href="http://jkanime.net/one-piece-episode-of-luffy-hand-island-no-bouken/">seguir leyendo</a></p>
</td>
</tr>
</tbody>
</table>
<table class="search">
<tbody>
<tr>
<td rowspan="2">
<a href="http://jkanime.net/dream-9-toriko-one-piece-dragon-ball-z-super-collaboration-special/"><img src="http://cdn.jkanime.net/assets/images/animes/thumbnail/dream-9-toriko-one-piece-dragon-ball-z-super-collaboration-special.jpg" width="50"></a>
</td>
<td><a class="titl" href="http://jkanime.net/dream-9-toriko-one-piece-dragon-ball-z-super-collaboration-special/">Toriko &amp; One Piece &amp; Dragon Ball Z Super Collaboration</a></td>
<td rowspan="2" style="width:50px; text-align:center;">Especial</td>
<td rowspan="2" style="width:50px; text-align:center;">2 Eps</td>
</tr>
<tr>
<td>
<p>Crossover Toriko &amp; One Piece &amp; Dragon Ball Z
Parte 1 : Valido como episodio 99 de Toriko
Parte 2 : Valido como episodio 590 de One Piece <a class="next" href="http://jkanime.net/dream-9-toriko-one-piece-dragon-ball-z-super-collaboration-special/">seguir leyendo</a>
</p>
</td>
</tr>
</tbody>
</table>
<table class="search">
<tbody>
<tr>
<td rowspan="2">
<a href="http://jkanime.net/one-piece-film-z/"><img src="http://cdn.jkanime.net/assets/images/animes/thumbnail/one-piece-film-z.jpg" width="50"></a>
</td>
<td><a class="titl" href="http://jkanime.net/one-piece-film-z/">One Piece Film Z</a></td>
<td rowspan="2" style="width:50px; text-align:center;">Pelicula</td>
<td rowspan="2" style="width:50px; text-align:center;">1 Eps</td>
</tr>
<tr>
<td>
<p>La película se situará ya en el New World, Luffy y la tripulación pirata de la serie tendrán que enfrentarse a “Z”, el mayor enemigo al que se haya tenido que enfrentar jamás. El núcleo de la película será la… <a class="next" href="http://jkanime.net/one-piece-film-z/">seguir leyendo</a></p>
</td>
</tr>
</tbody>
</table>
<table class="search">
<tbody>
<tr>
<td rowspan="2">
<a href="http://jkanime.net/one-piece-special-glorious-island/"><img src="http://cdn.jkanime.net/assets/images/animes/thumbnail/one-piece-special-glorious-island.jpg" width="50"></a>
</td>
<td><a class="titl" href="http://jkanime.net/one-piece-special-glorious-island/">One Piece Special: Glorious Island</a></td>
<td rowspan="2" style="width:50px; text-align:center;">Especial</td>
<td rowspan="2" style="width:50px; text-align:center;">1 Eps</td>
</tr>
<tr>
<td>
<p>Corto especial prologo a la película One Piece Film Z. <a class="next" href="http://jkanime.net/one-piece-special-glorious-island/">seguir leyendo</a></p>
</td>
</tr>
</tbody>
</table>
</div>
11 changes: 11 additions & 0 deletions test/not_found.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="listpage">
<table class="search">
<tbody>
<tr>
<td style="width:570px">
<p>No se encontraron resultados</p>
</td>
</tr>
</tbody>
</table>
</div>
89 changes: 89 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
'use strict';

import anime from '../src';
import {expect} from 'chai';
import path from 'path';
import nock from 'nock';

describe('anime-dl', function() {
this.timeout(20000);

describe('invalid anime', () => {
beforeEach(() => {
nock.disableNetConnect();
nock('http://jkanime.net')
.get('/buscar/asdf')
.replyWithFile(200, path.join(__dirname, 'not_found.html'));
});

it('should return a error for invalid chapter', done => {
const name = 'asdf';
const chapter = 1;
anime.getLinksByNameAndChapter(name, chapter).catch(err => {
expect(err.message).to.eql('Not found anime with keyword "asdf"');
done();
});
});
});

describe('invalid chapter', () => {
beforeEach(() => {
nock.disableNetConnect();
nock('http://jkanime.net')
.get('/buscar/one%20piece')
.replyWithFile(200, path.join(__dirname, 'found.html'));
nock('http://jkanime.net')
.get('/one-piece')
.replyWithFile(200, path.join(__dirname, 'chapters.html'));
});

it('should return a error for invalid chapter', done => {
const name = 'one piece';
const chapter = 'asdf';
anime.getLinksByNameAndChapter(name, chapter).catch(err => {
expect(err.message).to.eql('Not a valid chapter');
done();
});
});

it('should return a error for chapter outside in range', done => {
const name = 'one piece';
const chapter = 100000;
anime.getLinksByNameAndChapter(name, chapter).catch(err => {
expect(err.message).to.match(/Only\ chapters\ from\ 1\ to\ /);
done();
});
});
});

describe('valid anime and chapter', () => {
beforeEach(() => {
nock.disableNetConnect();
nock('http://jkanime.net')
.get('/buscar/one%20piece')
.replyWithFile(200, path.join(__dirname, 'found.html'));
nock('http://jkanime.net')
.get('/one-piece')
.replyWithFile(200, path.join(__dirname, 'chapters.html'));
nock('http://jkanime.net')
.get('/one-piece/100')
.replyWithFile(200, path.join(__dirname, 'chapter.html'));
});

it('should return valid data of a chapter of a anime', done => {
const name = 'one piece';
const chapter = 100;
anime.getLinksByNameAndChapter(name, chapter).then(data => {
expect(data.title).to.eql('One Piece');
expect(data.codeName).to.eql('one-piece');
expect(data.chapter).to.eql('100');
expect(data.urls[0]).to.match(/http:\/\/jkanime\.net\/stream\/jkmedia\/([0-9a-f]{32}\/[0-9a-f]{32}\/1\/[0-9a-f]{32})\//);
done();
}).catch(err => {
if (err) throw err;
expect(err).to.be.undefined;
done();
});
});
});
});

0 comments on commit 27f5dfe

Please sign in to comment.