From 851391e187b54f3853131e74905af34a8f6ffe32 Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Sun, 2 Sep 2018 05:19:43 +0300 Subject: [PATCH] fix(tests): rutor test --- src/background/strategies/rutor.js | 4 +++- tests/strategies/rutor.test.js | 24 ++++++++++++++++++++++++ tests/strategies/rutor/rutor.1.json | 5 +++++ tests/strategies/rutor/rutor.7.json | 6 ++++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tests/strategies/rutor.test.js create mode 100644 tests/strategies/rutor/rutor.1.json create mode 100644 tests/strategies/rutor/rutor.7.json diff --git a/src/background/strategies/rutor.js b/src/background/strategies/rutor.js index a45c315..91bbe08 100644 --- a/src/background/strategies/rutor.js +++ b/src/background/strategies/rutor.js @@ -13,7 +13,8 @@ module.exports = class Rutor { this.p2p = props.p2p this.dataDirectory = props.dataDirectory - setTimeout(() => this.recheck(), 30000) + let t = setTimeout(() => this.recheck(), 30000) + t.unref() } name() { return 'rutor' } @@ -61,6 +62,7 @@ module.exports = class Rutor { let data = JSON.parse(fs.readFileSync(this.dataDirectory + '/rutor/rutor.x.json')) this.rutorMap = data.hashes + logT('rutor', 'add records to', Object.keys(this.rutorMap).length) } else this.rutorMap = {} diff --git a/tests/strategies/rutor.test.js b/tests/strategies/rutor.test.js new file mode 100644 index 0000000..dc2a079 --- /dev/null +++ b/tests/strategies/rutor.test.js @@ -0,0 +1,24 @@ +const { assert } = require('chai') +const Rutor = require('../../src/background/strategies/rutor.js') + +describe("rutor", () => { + let rutor = new Rutor({dataDirectory: 'tests/strategies'}); + + it("findHash", async function() { + const data = await rutor.findHash('7ea9e38a48a8d8f4e1a6807e02dda204bd90c94a') + assert.equal(data.name, 'DJ Farta - Пацанская сборка в тачку. Vol 8 (2015) MP3') + assert.equal(data.poster, 'http://s016.radikal.ru/i337/1509/72/f76a929da813.jpg') + assert(data.description.includes('Tracklist'), 'description must contrain equal string') + }) + + it("findHash second", async function() { + const data = await rutor.findHash('158448f6afbedb079aaf3c4695fb43e7dfa54515') + assert.equal(data.name, 'Наруто: Ураганные Хроники / Naruto Shippuuden Movie [4 фильм] (2007) DVDRip') + assert.equal(data.rutorThreadId, 5850) + }) + + it("notFound", async function() { + assert(!await rutor.findHash('90296af2742232ba80e4a1f335fc2e159011d0da')) + }) + +}); diff --git a/tests/strategies/rutor/rutor.1.json b/tests/strategies/rutor/rutor.1.json new file mode 100644 index 0000000..84db108 --- /dev/null +++ b/tests/strategies/rutor/rutor.1.json @@ -0,0 +1,5 @@ +{ + "hashes": { + "158448f6afbedb079aaf3c4695fb43e7dfa54515": 5850 + } +} \ No newline at end of file diff --git a/tests/strategies/rutor/rutor.7.json b/tests/strategies/rutor/rutor.7.json new file mode 100644 index 0000000..5a76a9d --- /dev/null +++ b/tests/strategies/rutor/rutor.7.json @@ -0,0 +1,6 @@ +{ + "hashes": { + "158448f6afbedb079aaf3c4695fb43e7dfa54515": 5850, + "7ea9e38a48a8d8f4e1a6807e02dda204bd90c94a": 457419 + } +} \ No newline at end of file