<commit_before>use strict;
use warnings;
use Test::More;

BEGIN { use_ok 'Catalyst::Test', 'Maximus' }
BEGIN { use_ok 'Maximus::Controller::Module::Upload' }
BEGIN { use_ok 'Test::WWW::Mechanize::Catalyst' => 'Maximus' }
BEGIN { use_ok 'Archive::Zip', qw(:ERROR_CODES) }
BEGIN { use_ok 'Path::Class' }
BEGIN { use_ok 'File::Temp' }

my $req = request('/module/upload');
ok( $req->is_redirect, 'Request should redirect' );

# Authenticate
my $ua1 = Test::WWW::Mechanize::Catalyst->new;
$ua1->get_ok('/account/login', 'Request login page');
$ua1->submit_form(
	fields => {
		username => 'demo_user',
		password => '<PASSWORD>',
	}
);
$ua1->content_contains('Welcome demo_user!', 'Login successful');

# Test valid file upload
my $modpath = Path::Class::Dir->new('t', 'data', 'test.mod1');
my $zip = Archive::Zip->new();
$zip->addTree($modpath->stringify, 'test.mod1');
my $fh = File::Temp->new();
ok( $zip->writeToFileHandle($fh) == AZ_OK , 'Created temporary zipfile');
$fh->seek(0,0);

$ua1->get_ok('/module/upload', 'Request module upload page');
$ua1->content_contains('Upload Module', 'Title match');
$ua1->submit_form(
	fields => {
		scope => 'test',
		name => 'mod1',
		desc => 'my test module',
		file => $fh->filename,
	}
);
$ua1->content_contains('Your module has been uploaded', 'Upload succesful');

# Test invalid file upload
TODO: {
	local $TODO = 'Upload invalid module';
	ok( 1 == 2, 'still todo');
};

done_testing();<commit_msg>Added test for uploading a invalid archive<commit_after>use strict;
use warnings;
use Test::More;

BEGIN { use_ok 'Catalyst::Test', 'Maximus' }
BEGIN { use_ok 'Maximus::Controller::Module::Upload' }
BEGIN { use_ok 'Test::WWW::Mechanize::Catalyst' => 'Maximus' }
BEGIN { use_ok 'Archive::Zip', qw(:ERROR_CODES) }
BEGIN { use_ok 'Path::Class' }
BEGIN { use_ok 'File::Temp' }

my $req = request('/module/upload');
ok( $req->is_redirect, 'Request should redirect' );

# Authenticate
my $ua1 = Test::WWW::Mechanize::Catalyst->new;
$ua1->get_ok('/account/login', 'Request login page');
$ua1->submit_form(
	fields => {
		username => 'demo_user',
		password => '<PASSWORD>',
	}
);
$ua1->content_contains('Welcome demo_user!', 'Login successful');

# Test valid file upload
my $modpath = Path::Class::Dir->new('t', 'data', 'test.mod1');
my $zip = Archive::Zip->new();
$zip->addTree($modpath->stringify, 'test.mod1');
my $fh = File::Temp->new();
ok( $zip->writeToFileHandle($fh) == AZ_OK , 'Created temporary zipfile');
$fh->seek(0,0);

$ua1->get_ok('/module/upload', 'Request module upload page');
$ua1->content_contains('Upload Module', 'Title match');
$ua1->submit_form(
	fields => {
		scope => 'test',
		name => 'mod1',
		desc => 'my test module',
		file => $fh->filename,
	}
);
$ua1->content_contains('Your module has been uploaded', 'Upload succesful');

# Test invalid file upload
$ua1->get_ok('/module/upload', 'Request module upload page');
$ua1->content_contains('Upload Module', 'Title match');
$ua1->submit_form(
	fields => {
		scope => 'test',
		name => 'mod1',
		desc => 'my test module',
		file => Path::Class::File->new('t', 'data', 'test.mod1', 'dummy.exe'),
	}
);
$ua1->content_contains('Your archive appears to be faulty', 'Upload failed');

done_testing();
{'fraction_non_alphanumeric': 0.20778816199376948, 'fraction_numerical': 0.01059190031152648, 'mean_word_length': 5.788583509513742, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7043367', 'n_tokens_mistral': 1192, 'n_tokens_neox': 1127, 'n_words': 268}