Skip to content

Commit

Permalink
chore(tests): Add all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lgaticaq committed Dec 18, 2016
1 parent 82a7258 commit fa299e4
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/found_invalid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="listpage">
<table class="search">
<tbody>
<tr>
<td rowspan="2">
<a href="http://jkanime.net/psycho-pass/"><img src="http://cdn.jkanime.net/assets/images/animes/thumbnail/psycho-pass.jpg" width="50"></a>
</td>
<td><a class="titl" href="http://jkanime.net/psycho-pass/"></a></td>
<td rowspan="2" style="width:50px; text-align:center;">Serie</td>
<td rowspan="2" style="width:50px; text-align:center;">22 Eps</td>
</tr>
<tr>
<td>
<p>En un futuro próximo en el que es posible medir y cuantificar de forma instantánea el estado mental de una persona y su personalidad. Esta información es grabada y procesada; “Psycho-Pass” hace referencia al nombre… <a class="next" href="http://jkanime.net/psycho-pass/">seguir leyendo</a></p>
</td>
</tr>
</tbody>
</table>
</div>
168 changes: 168 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,172 @@ describe('anime-dl', function() {
}).catch(err => done(err));
});
});

describe('server error in get link', () => {
beforeEach(() => {
nock.disableNetConnect();
nock('http://jkanime.net')
.get('/buscar/mob%20psycho%20100')
.replyWithFile(200, path.join(__dirname, 'found.html'));
nock('http://jkanime.net')
.get('/mob-psycho-100')
.replyWithFile(200, path.join(__dirname, 'chapters.html'));
nock('http://jkanime.net')
.get('/mob-psycho-100/1')
.replyWithError('Server error');
});

it('should return an error', done => {
const name = 'mob psycho 100';
const chapter = 1;
anime.getLinksByNameAndChapter(name, chapter).catch(err => {
expect(err).to.be.an('error');
done();
});
});
});

describe('bad status in get link', () => {
beforeEach(() => {
nock.disableNetConnect();
nock('http://jkanime.net')
.get('/buscar/mob%20psycho%20100')
.replyWithFile(200, path.join(__dirname, 'found.html'));
nock('http://jkanime.net')
.get('/mob-psycho-100')
.replyWithFile(200, path.join(__dirname, 'chapters.html'));
nock('http://jkanime.net')
.get('/mob-psycho-100/1')
.reply(301);
});

it('should return an error', done => {
const name = 'mob psycho 100';
const chapter = 1;
anime.getLinksByNameAndChapter(name, chapter).catch(err => {
expect(err).to.be.an('error');
done();
});
});
});

describe('server error in get last chapter', () => {
beforeEach(() => {
nock.disableNetConnect();
nock('http://jkanime.net')
.get('/buscar/mob%20psycho%20100')
.replyWithFile(200, path.join(__dirname, 'found.html'));
nock('http://jkanime.net')
.get('/mob-psycho-100')
.replyWithError('Server error');
nock('http://jkanime.net')
.get('/mob-psycho-100/1')
.replyWithError('Server error');
});

it('should return an error', done => {
const name = 'mob psycho 100';
const chapter = 1;
anime.getLinksByNameAndChapter(name, chapter).catch(err => {
expect(err).to.be.an('error');
done();
});
});
});

describe('bad status in get last chapter', () => {
beforeEach(() => {
nock.disableNetConnect();
nock('http://jkanime.net')
.get('/buscar/mob%20psycho%20100')
.replyWithFile(200, path.join(__dirname, 'found.html'));
nock('http://jkanime.net')
.get('/mob-psycho-100')
.reply(301);
nock('http://jkanime.net')
.get('/mob-psycho-100/1')
.reply(301);
});

it('should return an error', done => {
const name = 'mob psycho 100';
const chapter = 1;
anime.getLinksByNameAndChapter(name, chapter).catch(err => {
expect(err).to.be.an('error');
done();
});
});
});

describe('server error in search', () => {
beforeEach(() => {
nock.disableNetConnect();
nock('http://jkanime.net')
.get('/buscar/mob%20psycho%20100')
.replyWithError('Server error');
nock('http://jkanime.net')
.get('/mob-psycho-100')
.replyWithError('Server error');
nock('http://jkanime.net')
.get('/mob-psycho-100/1')
.replyWithError('Server error');
});

it('should return an error', done => {
const name = 'mob psycho 100';
const chapter = 1;
anime.getLinksByNameAndChapter(name, chapter).catch(err => {
expect(err).to.be.an('error');
done();
});
});
});

describe('bad status code in search', () => {
beforeEach(() => {
nock.disableNetConnect();
nock('http://jkanime.net')
.get('/buscar/mob%20psycho%20100')
.reply(301);
nock('http://jkanime.net')
.get('/mob-psycho-100')
.reply(301);
nock('http://jkanime.net')
.get('/mob-psycho-100/1')
.reply(301);
});

it('should return an error', done => {
const name = 'mob psycho 100';
const chapter = 1;
anime.getLinksByNameAndChapter(name, chapter).catch(err => {
expect(err).to.be.an('error');
done();
});
});
});

describe('error in search name', () => {
beforeEach(() => {
nock.disableNetConnect();
nock('http://jkanime.net')
.get('/buscar/mob%20psycho%20100')
.replyWithFile(200, path.join(__dirname, 'found_invalid.html'));
nock('http://jkanime.net')
.get('/mob-psycho-100')
.replyWithFile(200, path.join(__dirname, 'chapters.html'));
nock('http://jkanime.net')
.get('/mob-psycho-100/1')
.replyWithFile(200, path.join(__dirname, 'chapter2.html'));
});

it('should return an error', done => {
const name = 'mob psycho 100';
const chapter = 1;
anime.getLinksByNameAndChapter(name, chapter).catch(err => {
expect(err).to.be.an('error');
done();
});
});
});
});

0 comments on commit fa299e4

Please sign in to comment.