first commit

This commit is contained in:
2025-04-09 21:43:00 +02:00
commit af5be2794d
39 changed files with 1947 additions and 0 deletions

108
xxx/app/t/01_routes.t Normal file
View File

@@ -0,0 +1,108 @@
print "Test: $0\n";
use Mojo::Base -strict;
use Mojo::JSON qw(decode_json);
use Modern::Perl;
use Test::More;
use Test::Mojo;
use DBI;
use Data::Printer;
#my $dbh = DBI->connect('DBI:mysql:prod:ares', '', '') or die ('Fehler beim Verbinden mit der Datenbank');
my $t = Test::Mojo->new('XxxApp');
$t->app->log->level('info');
$t->app->ua->max_redirects(1);
subtest 'prod konfig test' => sub {
my $konf = do '../deb/prod/xxx_app.conf';
is exists $konf->{secret}, 1, 'secret = exists';
is $konf->{htlib}, "/var/local/htlib", 'htlib = /var/local/htlib';
is $konf->{hypnotoad}->{pid_file}, "/run/xxx.pid", 'hypnotoad->pid_file = /run/xxx.pid';
is $konf->{hypnotoad}->{workers}, 4, 'hypnotoad->workers = 4';
is $konf->{hypnotoad}->{proxy}, 1, 'hypnotoad->proxy = 1';
is $konf->{logging}->{enable}, 1, 'logging->enable = 1';
is $konf->{logging}->{facility}, 'local7', 'logging->facility = local7';
is $konf->{logging}->{ident}, 'xxx', 'logging->ident = xxx';
is $konf->{logging}->{level}, 'info', 'logging->level = info';
is $konf->{logging}->{only_syslog}, 1, 'logging->only_syslog = 1';
};
subtest 'Routes', sub {
note '/';
$t->get_ok('/')
->status_is(200)
->content_like(qr'<img class="mypic" src="\/images\/xxx.svg">', 'SVG is availble')
->header_isnt('Server' => 'Mojolicious');
note '/login';
$t->get_ok('/login')
->status_is(200)
->content_like(qr'placeholder="Anmeldename"', 'Anmeldename is availble')
->content_like(qr'placeholder="Passwort"', 'Passwort is availble');
note '/api/jstreedata no permission';
$t->get_ok('/api/jstreedata')
->status_is(401);
note '/api/datatablesdata no permission';
$t->get_ok('/api/datatablesdata')
->status_is(401);
# on this point we have a session
note 'with Login no AD';
$t->post_ok(
'/login' => form => { username => 'developer', password => 'wbdfgmnjke834dshf89w7rsdfsdjf' }
);
$t->status_is(302);
note '/api/jstreedata';
$t->get_ok('/api/jstreedata')
->status_is(200)
->json_is( '/msg' => 'OK', 'msg: OK' )
->json_is( '/rc' => 0, 'rc: 0' );
my $res = $t->tx->res->json;
is ref $res->{data}, 'ARRAY', 'data is ARRAY reference';
is exists $res->{data}[0]->{id}, 1, 'data has id';
is exists $res->{data}[0]->{parent}, 1, 'data has firstname';
is exists $res->{data}[0]->{text}, 1, 'data has name';
note '/api/datatablesdata';
$t->get_ok('/api/datatablesdata')
->status_is(200)
->json_is( '/msg' => 'OK', 'msg: OK' )
->json_is( '/rc' => 0, 'rc: 0' );
$res = $t->tx->res->json;
is ref $res->{data}, 'ARRAY', 'data is ARRAY reference';
is exists $res->{data}[0]->{col1}, 1, 'data has col1';
is exists $res->{data}[0]->{col2}, 1, 'data has col2';
is exists $res->{data}[0]->{col3}, 1, 'data has col3';
is exists $res->{data}[0]->{col4}, 1, 'data has col4';
is exists $res->{data}[0]->{col5}, 1, 'data has col5';
is exists $res->{data}[0]->{col6}, 1, 'data has col6';
is exists $res->{data}[0]->{col7}, 1, 'data has col7';
is exists $res->{data}[0]->{col8}, 1, 'data has col8';
is exists $res->{data}[0]->{col9}, 1, 'data has col9';
is exists $res->{data}[0]->{col10}, '', 'data has no col10';
};
subtest 'POST requestBody required must True', sub {
$t->get_ok('/api');
$t->status_is(200);
my $res = $t->tx->res->json;
for my $path ( keys %{$res->{paths}} ) {
my $pa = $res->{paths}->{$path};
if ( $pa->{post}->{requestBody} ) {
is $pa->{post}->{requestBody}->{required}, 1, $path;
}
}
};
done_testing();