diff options
author | Jannis M. Hoffmann <jannis@fehcom.de> | 2023-02-26 21:36:27 +0100 |
---|---|---|
committer | Jannis M. Hoffmann <jannis@fehcom.de> | 2023-02-26 21:36:27 +0100 |
commit | 2abf462ca10c4ac8c4f815e608cad31851e966e3 (patch) | |
tree | ed18c4a4039a5972edc0b81ed79c9d57480f8e70 /t | |
parent | d0ffe11bd365b68d4da252b39d06d99f75d8cacb (diff) |
Specified the interface for qmauth
Changes to configuration
Added qmauth version written in Python
Slight changes to pagination
Diffstat (limited to 't')
-rw-r--r-- | t/Extract.t | 49 | ||||
-rw-r--r-- | t/Helper.t | 64 | ||||
-rw-r--r-- | t/Webmail.t | 8 |
3 files changed, 63 insertions, 58 deletions
diff --git a/t/Extract.t b/t/Extract.t index 7b1ddbf..3a18395 100644 --- a/t/Extract.t +++ b/t/Extract.t @@ -6,13 +6,13 @@ use Test::More; use JSON::PP 'decode_json'; use List::Util 'min'; -no warnings 'experimental::smartmatch'; my $EXTRACT = { - perl_mail_box => 'perl script/qmauth.pl ', - rust_maildir => 'extract/target/debug/jwebmail-extract', -}->{perl_mail_box}; + perl_mail_box => 'perl script/qmauth.pl', + python_mailbox => 'python script/qmauth.py', + rust_maildir => 'extract/target/debug/jwebmail-extract', +}->{python_mailbox}; my $MAILDIR = 't/'; my $SYS_USER = $ENV{USER}; my $MAIL_USER = 'maildir'; @@ -29,13 +29,15 @@ my $MAIL_COUNT = do { }; subtest start => sub { - my @res = `$PROG invalid`; + my @res = `$PROG invalid 2>/dev/null`; - is($? >> 8, 3); - is @res, 1; - my $result = decode_json $res[0]; + isnt $? >> 8, 0; - ok($result->{error}) + if ($? >> 8 == 3) { + is scalar(@res), 1; + my $result = decode_json @res; + ok exists $result->{error}; + } }; subtest folders => sub { @@ -55,43 +57,44 @@ subtest count => sub { is @res, 1; my $result = decode_json $res[0]; - is($result->{count}, $MAIL_COUNT); - #is($result->{new}, 0); + is($result->{total_mails}, $MAIL_COUNT); }; subtest list => sub { - my $s = "$PROG list 0 4 date ''"; + my $s = "$PROG list '' 0 4 date"; my @res = `$s`; is($? >> 8, 0); is @res, 1; my $result = decode_json $res[0]; - is(@$result, min($MAIL_COUNT, 5)); - ok($result->[0]{mid}); + is(@$result, min($MAIL_COUNT, 4)); + ok($result->[0]{message_handle}); ok($result->[0]{head}{from}) or diag $s; ok($result->[0]{head}{to}); }; subtest read => sub { - my @pre_res = `$PROG list 0 10 date ''`; + my $folder = ''; + my @pre_res = `$PROG list '$folder' 0 10 ''`; is($? >> 8, 0); is @pre_res, 1; my $pre_result = decode_json $pre_res[0]; - ok(my $mid = $pre_result->[0]{mid}); + ok(my $mid = $pre_result->[0]{message_handle}); - my $s = "$PROG read-mail '$mid'"; - my @res = `$s`; + my @res = `$PROG read '$folder' '$mid'`; - is($? >> 8, 0) or (diag $s, return); + is($? >> 8, 0, "read exit code") or (diag @res, return); is @res, 1; my $result = decode_json $res[0]; - is_deeply($result->{head}{from}, [{address => 'shipment-tracking@amazon.de', name => 'Amazon.de'}]); - ok($result->{date_received}); - ok(index($result->{date_received}, '2019-02-22T10:06:54') != -1); - like($result->{date_received}, qr'2019-02-22T10:06:54'); + is_deeply( + $result->{head}{from}, + [{address => 'xy@example.com', display_name => 'Moderator-Address'}], + ); + ok(exists $result->{head}{date}); + is($result->{head}{date}, '1994-03-22T13:34:51+00:00'); }; done_testing; @@ -85,73 +85,73 @@ subtest 'pagination' => sub { %res = JWebmail::Plugin::Helper::_paginate(first_item => 0, page_size => 10, total_items => 55); - is $res{first_item}, 1; - is $res{last_item}, 10; + is $res{first_item}, 0; + is $res{last_item}, 9; is $res{total_items}, 55; is $res{page_size}, 10; is $res{total_pages}, 6; - is $res{current_page}, 1; + is $res{current_page}, 0; - is_deeply $res{first_page}, [1, 10], 'first'; - is_deeply $res{prev_page}, [1, 10], 'prev'; - is_deeply $res{next_page}, [11, 20], 'next'; - is_deeply $res{last_page}, [51, 55], 'last'; + is_deeply $res{first_page}, [0, 10], 'first'; + is_deeply $res{prev_page}, [0, 10], 'prev'; + is_deeply $res{next_page}, [10, 20], 'next'; + is_deeply $res{last_page}, [50, 55], 'last'; %res = JWebmail::Plugin::Helper::_paginate(first_item => 10, page_size => 10, total_items => 55); - is $res{first_item}, 11; - is $res{last_item}, 20; + is $res{first_item}, 10; + is $res{last_item}, 19; is $res{total_items}, 55; is $res{page_size}, 10; is $res{total_pages}, 6; - is $res{current_page}, 2; + is $res{current_page}, 1; - is_deeply $res{first_page}, [1, 10], 'first'; - is_deeply $res{prev_page}, [1, 10], 'prev'; - is_deeply $res{next_page}, [21, 30], 'next'; - is_deeply $res{last_page}, [51, 55], 'last'; + is_deeply $res{first_page}, [0, 10], 'first'; + is_deeply $res{prev_page}, [0, 10], 'prev'; + is_deeply $res{next_page}, [20, 30], 'next'; + is_deeply $res{last_page}, [50, 55], 'last'; %res = JWebmail::Plugin::Helper::_paginate(first_item => 20, page_size => 10, total_items => 55); - is $res{first_item}, 21; - is $res{last_item}, 30; + is $res{first_item}, 20; + is $res{last_item}, 29; is $res{total_items}, 55; is $res{page_size}, 10; is $res{total_pages}, 6; - is $res{current_page}, 3; + is $res{current_page}, 2; - is_deeply $res{first_page}, [1, 10], 'first'; - is_deeply $res{prev_page}, [11, 20], 'prev'; - is_deeply $res{next_page}, [31, 40], 'next'; - is_deeply $res{last_page}, [51, 55], 'last'; + is_deeply $res{first_page}, [0, 10], 'first'; + is_deeply $res{prev_page}, [10, 20], 'prev'; + is_deeply $res{next_page}, [30, 40], 'next'; + is_deeply $res{last_page}, [50, 55], 'last'; %res = JWebmail::Plugin::Helper::_paginate(first_item => 50, page_size => 10, total_items => 55); - is $res{first_item}, 51; - is $res{last_item}, 55; + is $res{first_item}, 50; + is $res{last_item}, 54; is $res{total_items}, 55; is $res{page_size}, 10; is $res{total_pages}, 6; - is $res{current_page}, 6; + is $res{current_page}, 5; - is_deeply $res{first_page}, [1, 10], 'first'; - is_deeply $res{prev_page}, [41, 50], 'prev'; - is_deeply $res{next_page}, [51, 55], 'next'; - is_deeply $res{last_page}, [51, 55], 'last'; + is_deeply $res{first_page}, [0, 10], 'first'; + is_deeply $res{prev_page}, [40, 50], 'prev'; + is_deeply $res{next_page}, [50, 55], 'next'; + is_deeply $res{last_page}, [50, 55], 'last'; %res = JWebmail::Plugin::Helper::_paginate(first_item => 0, page_size => 10, total_items => 0); - is $res{first_item}, 0; - is $res{last_item}, 0; + ok !defined $res{first_item}; + ok !defined $res{last_item}; is $res{total_items}, 0; is $res{page_size}, 10; is $res{total_pages}, 0; - is $res{current_page}, 1; + is $res{current_page}, 0; is_deeply $res{first_page}, [0, 0], 'first'; is_deeply $res{prev_page}, [0, 0], 'prev'; @@ -181,4 +181,4 @@ subtest 'pagination' => sub { }; -done_testing;
\ No newline at end of file +done_testing; diff --git a/t/Webmail.t b/t/Webmail.t index 9218fb1..3deb547 100644 --- a/t/Webmail.t +++ b/t/Webmail.t @@ -14,9 +14,11 @@ my $pw = JWebmail::Model::ReadMails::MockJSON::VALID_PW; my $t = Test::Mojo->new('JWebmail', { - development => { read_mock => 'JWebmail::Model::ReadMails::MockJSON', block_writes => 1 }, - i18n => { default_language => DEFAULT_LANGUAGE }, - session => { secure => 'none' }, + model => { read => { devel => { driver => 'JWebmail::Model::ReadMails::MockJSON' }}, + write => { devel => { block_writes => 1 }}}, + i18n => { default_language => DEFAULT_LANGUAGE, directory => 'lib/JWebmail/I18N' }, + session => { secure => 'none' }, + defaults => { scriptadmin => 'test@example.org' }, }); $t->get_ok('/')->status_is(200); |