Don't import files if they don't have the supportted format extension,
[catagits/App-IdiotBox.git] / t / importer / video_files_from_dir.t
diff --git a/t/importer/video_files_from_dir.t b/t/importer/video_files_from_dir.t
new file mode 100644 (file)
index 0000000..45e0f80
--- /dev/null
@@ -0,0 +1,54 @@
+use strict;
+use warnings FATAL => 'all';
+use autodie;
+
+use Test::More;
+
+use Cwd qw(getcwd);
+use File::Temp qw(tempdir);
+
+# Chdir to test directory for laziness
+my $original_dir = getcwd;
+END {
+       chdir $original_dir;
+}
+
+my $temp_dir = tempdir(CLEANUP => 1);
+chdir($temp_dir);
+
+use App::IdiotBox::Importer;
+
+my $method = 'video_files_from_dir';
+
+# No videos
+my $videos = App::IdiotBox::Importer->$method($temp_dir);
+is_deeply($videos, {}, 'No files reported from empty directory');
+
+# Unknown extensions
+open(undef, '>', 'fake.mp3');
+open(undef, '>', 'fake2.aac');
+
+$videos = App::IdiotBox::Importer->$method($temp_dir);
+is_deeply($videos, {}, 'No files reported from empty directory');
+
+# Known file types
+open(undef, '>', 'good.m4v');
+open(undef, '>', 'good2.flv');
+
+my $expect = {
+       'good'  => [ 'm4v' ],
+       'good2' => [ 'flv' ],
+};
+
+$videos = App::IdiotBox::Importer->$method($temp_dir);
+is_deeply($videos, $expect, 'Known filetypes detected');
+
+# Grouping by file name without extension
+open(undef, '>', 'good.flv');
+
+unshift @{ $expect->{good} }, 'flv';
+
+$videos = App::IdiotBox::Importer->$method($temp_dir);
+is_deeply($videos, $expect, 'Known filetypes detected');
+
+done_testing;