]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/psgi_v2.t
view: handle the topic-free case properly
[public-inbox.git] / t / psgi_v2.t
index 1163e2bf89f73c9bd400b23f5fbe2d275086ce94..c4f808695b000110d84d69605f5e6e42a2437d2e 100644 (file)
@@ -1,21 +1,17 @@
-# Copyright (C) 2018-2019 all contributors <meta@public-inbox.org>
+# Copyright (C) 2018-2020 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use warnings;
 use Test::More;
-require './t/common.perl';
+use PublicInbox::TestCommon;
 require_git(2.6);
 use PublicInbox::MIME;
 use PublicInbox::Config;
-use PublicInbox::WWW;
 use PublicInbox::MID qw(mids);
-my @mods = qw(DBD::SQLite Search::Xapian HTTP::Request::Common Plack::Test
-               URI::Escape Plack::Builder);
-foreach my $mod (@mods) {
-       eval "require $mod";
-       plan skip_all => "$mod missing for psgi_v2_dupes.t" if $@;
-}
-use_ok($_) for @mods;
+require_mods(qw(DBD::SQLite Search::Xapian HTTP::Request::Common Plack::Test
+               URI::Escape Plack::Builder));
+use_ok($_) for (qw(HTTP::Request::Common Plack::Test));
+use_ok 'PublicInbox::WWW';
 use_ok 'PublicInbox::V2Writable';
 my ($inboxdir, $for_destroy) = tmpdir();
 my $ibx = {
@@ -62,6 +58,9 @@ my $www = PublicInbox::WWW->new($config);
 my ($res, $raw, @from_);
 test_psgi(sub { $www->call(@_) }, sub {
        my ($cb) = @_;
+       $res = $cb->(GET('/v2test/description'));
+       like($res->content, qr!\$INBOX_DIR/description missing!,
+               'got v2 description missing message');
        $res = $cb->(GET('/v2test/a-mid@b/raw'));
        $raw = $res->content;
        like($raw, qr/^hello world$/m, 'got first message');
@@ -155,9 +154,19 @@ test_psgi(sub { $www->call(@_) }, sub {
        is($res->code, 200, 'success with threaded search');
        my $raw = $res->content;
        ok($raw =~ s/\A.*>Results 1-3 of 3\b//s, 'got all results');
-       my @over = ($raw =~ m/\d{4}-\d+-\d+\s+\d+:\d+ (.+)$/gm);
+       my @over = ($raw =~ m/\d{4}-\d+-\d+\s+\d+:\d+ +(?:\d+\% )?(.+)$/gm);
        is_deeply(\@over, [ '<a', '` <a', '` <a' ], 'threaded messages show up');
 
+       $res = $cb->(GET('/v2test/?q=m:a-mid@b&x=A'));
+       is($res->code, 200, 'success with Atom search');
+       SKIP: {
+               require_mods(qw(XML::TreePP), 2);
+               my $t = XML::TreePP->new->parse($res->content);
+               like($t->{feed}->{-xmlns}, qr/\bAtom\b/,
+                       'looks like an an Atom feed');
+               is(scalar @{$t->{feed}->{entry}}, 3, 'parsed three entries');
+       };
+
        local $SIG{__WARN__} = 'DEFAULT';
        $res = $cb->(GET('/v2test/a-mid@b/'));
        $raw = $res->content;
@@ -241,6 +250,8 @@ test_psgi(sub { $www->call(@_) }, sub {
                is($old->content, 'old', 'got expected old content');
                is($new->content, 'new', 'got expected new content');
        }
+       $res = $cb->(GET('/v2test/?t=1970'.'01'.'01'.'000000'));
+       is($res->code, 404, '404 for out-of-range t= param');
 });
 
 done_testing();