From 303299707986669b803262592e5b9f2dea7c0d1b Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Sat, 21 May 2022 20:25:35 +0100 Subject: [PATCH] Add Tdarr_Plugin_a9he_New_file_size_check test --- .../Tdarr_Plugin_a9he_New_file_size_check.js | 1 - .../Tdarr_Plugin_a9he_New_file_size_check.js | 67 +++++++++++++++++++ tests/helpers/run.js | 34 +++++++--- 3 files changed, 93 insertions(+), 9 deletions(-) create mode 100644 tests/Community/Tdarr_Plugin_a9he_New_file_size_check.js diff --git a/Community/Tdarr_Plugin_a9he_New_file_size_check.js b/Community/Tdarr_Plugin_a9he_New_file_size_check.js index e96caec..32e99d6 100644 --- a/Community/Tdarr_Plugin_a9he_New_file_size_check.js +++ b/Community/Tdarr_Plugin_a9he_New_file_size_check.js @@ -1,4 +1,3 @@ -// tdarrSkipTest const details = () => ({ id: 'Tdarr_Plugin_a9he_New_file_size_check', Stage: 'Pre-processing', diff --git a/tests/Community/Tdarr_Plugin_a9he_New_file_size_check.js b/tests/Community/Tdarr_Plugin_a9he_New_file_size_check.js new file mode 100644 index 0000000..e8db045 --- /dev/null +++ b/tests/Community/Tdarr_Plugin_a9he_New_file_size_check.js @@ -0,0 +1,67 @@ +/* eslint max-len: 0 */ +const run = require('../helpers/run'); + +const tests = [ + { + input: { + file: require('../sampleData/media/sampleH264_1.json'), + librarySettings: {}, + inputs: {}, + otherArguments: { + originalLibraryFile: require('../sampleData/media/sampleH264_1.json'), + }, + }, + output: { + processFile: false, + preset: '', + handBrakeMode: false, + FFmpegMode: true, + reQueueAfter: true, + infoLog: 'New file has size 1.008 MB which is 100% of original file size: 1.008 MB', + }, + }, + { + input: { + file: require('../sampleData/media/sampleH264_1.json'), + librarySettings: {}, + inputs: { + upperBound: '110', + lowerBound: '35', + }, + otherArguments: { + originalLibraryFile: (() => { + const file = JSON.parse(JSON.stringify(require('../sampleData/media/sampleH264_1.json'))); + file.file_size = 3; + return file; + })(), + }, + }, + output: 'New file size not within limits. New file has size 1.008 MB which is 33% of original file size: 3.000 MB. lowerBound is 35%', + error: { + shouldThrow: true, + }, + }, + { + input: { + file: require('../sampleData/media/sampleH264_1.json'), + librarySettings: {}, + inputs: { + upperBound: '120', + lowerBound: '35', + }, + otherArguments: { + originalLibraryFile: (() => { + const file = JSON.parse(JSON.stringify(require('../sampleData/media/sampleH264_1.json'))); + file.file_size = 0.1; + return file; + })(), + }, + }, + output: 'New file size not within limits. New file has size 1.008 MB which is 1007% of original file size: 0.100 MB. upperBound is 120%', + error: { + shouldThrow: true, + }, + }, +]; + +run(tests); diff --git a/tests/helpers/run.js b/tests/helpers/run.js index de35a75..e91112e 100644 --- a/tests/helpers/run.js +++ b/tests/helpers/run.js @@ -15,14 +15,32 @@ const run = async (tests) => { if (typeof test.input.file === 'function') { file = test.input.file(); } - // eslint-disable-next-line no-await-in-loop - const testOutput = await plugin( - file, - test.input.librarySettings, - test.input.inputs, - test.input.otherArguments, - ); - chai.assert.deepEqual(testOutput, test.output); + + let testOutput; + let errorEncountered = false; + try { + // eslint-disable-next-line no-await-in-loop + testOutput = await plugin( + file, + test.input.librarySettings, + test.input.inputs, + test.input.otherArguments, + ); + } catch (err1) { + // eslint-disable-next-line no-console + console.error(err1); + errorEncountered = err1; + } + + if (test.error && test.error.shouldThrow) { + if (errorEncountered !== false) { + chai.assert.deepEqual(errorEncountered.message, test.output); + } else { + throw new Error('Expected plugin error but none was thrown!'); + } + } else { + chai.assert.deepEqual(testOutput, test.output); + } } } catch (err) { // eslint-disable-next-line no-console