Improve unit test (#2071)

This commit is contained in:
Christophe Maudoux 2020-02-12 23:05:45 +01:00
parent a0ef149b5f
commit 04912c7854
4 changed files with 59 additions and 15 deletions

View File

@ -1,9 +1,10 @@
use Test::More;
use strict;
use IO::String;
use JSON qw(from_json);
my $res;
my $maintests = 10;
my $maintests = 17;
require 't/test-lib.pm';
my $file = tempdb();
@ -105,7 +106,8 @@ q{INSERT INTO notifications VALUES ('rtyler','testref2','2050-05-30 00:00:00',?,
notificationStorageOptions => {
dbiChain => "dbi:SQLite:dbname=$file",
},
oldNotifFormat => 0,
oldNotifFormat => 0,
notificationsExplorer => 1,
}
}
);
@ -179,7 +181,7 @@ q{INSERT INTO notifications VALUES ('rtyler','testref2','2050-05-30 00:00:00',?,
!defined( $cookies->{lemonldappdata} ),
" Make sure no pdata is returned"
);
$client->logout($id);
$id = expectCookie($res);
# Verify that notification was tagged as 'done'
my $sth =
@ -189,6 +191,32 @@ q{INSERT INTO notifications VALUES ('rtyler','testref2','2050-05-30 00:00:00',?,
while ( $sth->fetchrow_hashref ) { $i++ }
ok( $i == 2, 'Notification was deleted' );
# GET notifications explorer
ok(
$res = $client->_get(
'/mynotifications', cookie => "lemonldap=$id",
),
'Notifications explorer query'
);
my $json;
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
or print STDERR "$@\n" . Dumper($res);
ok( $json->{result} == 2, ' Result is 2' )
or explain( $json, "result => 2" );
ok( $json->{MSG} == 'myNotifications', ' MSG is myNotifications' )
or explain( $json, "result => 2" );
ok( $json->{NOTIFICATIONS}->[0]->{reference} =~ /testref2?/,
' Notification 1 found' )
or explain( $json, "Notification 1" );
ok( $json->{NOTIFICATIONS}->[0]->{reference} =~ /testref2?/,
' Notification 2 found' )
or explain( $json, "Notification 2" );
ok( $json->{NOTIFICATIONS}->[0]->{epoch} =~ /\d{10}/, ' epoch found' )
or explain( $json, "Epoch found" );
$client->logout($id);
# Try to authenticate
# -------------------
ok(

View File

@ -150,6 +150,7 @@ qq{INSERT INTO notifications VALUES ('rtyler','testref2','2050-05-30 00:00:00','
!defined( $cookies->{lemonldappdata} ),
" Make sure no pdata is returned"
);
$id = expectCookie($res);
$client->logout($id);
# Verify that notification was tagged as 'done'

View File

@ -29,9 +29,10 @@ my $client = LLNG::Manager::Test->new( {
notification => 1,
notificationStorage => 'File',
notificationStorageOptions => { dirName => $main::tmpDir },
portalMainLogo => 'common/logos/logo_llng_old.png',
oldNotifFormat => 0,
notificationsExplorer => 1,
portalMainLogo => 'common/logos/logo_llng_old.png', }
}
}
);
@ -82,8 +83,7 @@ expectForm( $res, undef, '/notifback', 'reference1x1' );
# Verify that cookie is ciphered (session unvalid)
ok(
$res = $client->_get(
'/',
cookie => "lemonldap=$id",
'/', cookie => "lemonldap=$id",
),
'Test cookie received'
);

View File

@ -7,7 +7,7 @@ require 't/test-lib.pm';
my $res;
my $file = "$main::tmpDir/20160530_dwho_dGVzdHJlZg==.xml";
my $maintests = 34;
my $maintests = 36;
SKIP: {
eval { require XML::LibXML; require XML::LibXSLT; };
@ -23,6 +23,12 @@ SKIP: {
<text>This is a test text</text>
<check>Accept test</check>
<check>Accept test2</check>
</notification><notification uid="dwho" date="2016-05-30" reference="testref2">
<title>Test title</title>
<subtitle>Test subtitle</subtitle>
<text>This is a test text</text>
<check>Accept test</check>
<check>Accept test2</check>
</notification></root>';
close F;
@ -33,9 +39,9 @@ SKIP: {
notification => 1,
notificationStorage => 'File',
notificationStorageOptions => { dirName => $main::tmpDir },
portalMainLogo => 'common/logos/logo_llng_old.png',
oldNotifFormat => 1,
notificationsExplorer => 1,
portalMainLogo => 'common/logos/logo_llng_old.png',
}
}
);
@ -81,13 +87,12 @@ SKIP: {
count(1);
expectOK($res);
$id = expectCookie($res);
expectForm( $res, undef, '/notifback', 'reference1x1' );
expectForm( $res, undef, '/notifback', 'reference1x1', 'reference1x2' );
# Verify that cookie is ciphered (session unvalid)
ok(
$res = $client->_get(
'/',
cookie => "lemonldap=$id",
'/', cookie => "lemonldap=$id",
),
'Test cookie received'
);
@ -95,7 +100,8 @@ SKIP: {
expectReject($res);
# Try to validate notification with accepting all checkboxes
my $str = 'reference1x1=testref&check1x1x1=accepted&check1x1x2=accepted';
my $str =
'reference1x1=testref&check1x1x1=accepted&check1x1x2=accepted&reference1x2=testref2&check1x2x1=accepted&check1x2x2=accepted';
ok(
$res = $client->_post(
'/notifback',
@ -140,9 +146,10 @@ SKIP: {
ok( $res->[2]->[0] =~ m%<span id="languages"></span>%,
' Language icons found' )
or print STDERR Dumper( $res->[2]->[0] );
ok( $res->[2]->[0] =~ m%<span id="msg" trspan=\'myNotification\'></span>%,
' trspan="myNotification" found' )
or print STDERR Dumper( $res->[2]->[0] );
ok(
$res->[2]->[0] =~ m%<span id="msg" trspan=\'myNotifications\'></span>%,
' trspan="myNotifications" found'
) or print STDERR Dumper( $res->[2]->[0] );
ok( $res->[2]->[0] =~ m%<th><span trspan="date">Date</span></th>%,
' trspan="date" found' )
or print STDERR Dumper( $res->[2]->[0] );
@ -159,8 +166,16 @@ SKIP: {
ok( $res->[2]->[0] =~ m%<td class="align-middle">testref</td>%,
' testref found' )
or print STDERR Dumper( $res->[2]->[0] );
ok( $res->[2]->[0] =~ m%<td class="align-middle">testref2</td>%,
' testref2 found' )
or print STDERR Dumper( $res->[2]->[0] );
ok( $res->[2]->[0] =~ m%class="fa fa-eye"></span>%, ' fa-eye found' )
or print STDERR Dumper( $res->[2]->[0] );
ok(
$res->[2]->[0] =~
m%<span id=\'icon-testref2-\d{10}\' class="fa fa-eye"></span>%,
' fa-eye 2 found'
) or print STDERR Dumper( $res->[2]->[0] );
ok( $res->[2]->[0] =~ m%<span id=\'displayNotif\'></span>%,
' Notififcation container found' )
or print STDERR Dumper( $res->[2]->[0] );