40-Notifications-JSON-Server.t 1.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
use Test::More;
use strict;
use IO::String;

BEGIN {
    require 't/test-lib.pm';
}

eval { unlink 't/20160530_dwho_dGVzdHJlZg==.json' };

my $json = '{
"date": "2016-05-30",
"reference": "testref",
"uid": "dwho",
"title": "Test title",
"text": "This is a test text"
}';

my $client = LLNG::Manager::Test->new(
    {
        ini => {
            logLevel                   => 'error',
            useSafeJail                => 1,
            notification               => 1,
            notificationServer         => 1,
            templatesDir               => 'site/templates/',
            notificationStorage        => 'File',
            notificationStorageOptions => {
                dirName => 't'
            },
        }
    }
);

my $res;
ok(
    $res = $client->_post(
        '/notifications', IO::String->new($json),
        type   => 'application/json',
        length => length($json)
    ),
    'Create notification'
);
count(1);

# Try yo authenticate
# -------------------
ok(
    $res = $client->_post(
        '/',
        IO::String->new(
Xavier Guimard's avatar
Xavier Guimard committed
52
            'user=dwho&password=dwho&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw=='),
53 54 55 56 57 58 59 60 61 62 63 64 65 66
        accept => 'text/html',
        length => 64,
    ),
    'Auth query'
);
count(1);
expectOK($res);
my $id = expectCookie($res);
expectForm( $res, undef, '/notifback', 'reference1x1', 'url' );

eval { unlink 't/20160530_dwho_dGVzdHJlZg==.json' };

clean_sessions();
done_testing( count() );