Select Git revision
-
Andrej Ramašeuski authoredAndrej Ramašeuski authored
events.t 1.99 KiB
use Mojo::Base -strict;
use Test::More;
use Test::Mojo;
use constant SECRET => 'TEST';
use constant USERS => {
nobody => {
"sub" => "00000000-0000-0000-0000-nobody",
"roles" => [],
"name" => "Testováci Nikdo",
"groups" => [],
"preferred_username" => "test.nobody",
},
organizer => {
"sub" => "00000000-0000-0000-0000-organizer",
"roles" => [ "organizer" ],
"name" => "Testováci Pořadatel",
"groups" => [ "cen:f", ],
"preferred_username" => "test.organizer",
},
};
my $t = Test::Mojo->new('CF', {
test => 1,
test_auth_jwt_secret => SECRET,
});
# pokus najit uzivatele
$t->get_ok('/api/sso/subjects?search=andrej.ramaseuski')->status_is(200)
->json_is('/0/value' => 'andrej.ramaseuski')
;
# seznam udalosti pro neuautorizovaneho
$t->get_ok('/api/events')->status_is(200);
# Pokus pridat event neautorizovanym uzivatelem
$t->post_ok('/api/events')->status_is(401);
# Pokus pridat event neopravnenym uzivatelem
$t->post_ok('/api/events', {
Authorization => auth_header(USERS->{nobody})
})->status_is(401);
# Pokus pridat event bez dat
$t->post_ok('/api/events' => {
Authorization => auth_header(USERS->{organizer})
})->status_is(400);
# pokus pridat event bez validnich dat
$t->post_ok('/api/events' => {
Authorization => auth_header(USERS->{organizer})
},
json => {
})->status_is(400);
# pokus pridat event
$t->post_ok('/api/events' => {
Authorization => auth_header(USERS->{organizer})
},
json => {
"type" => 1,
"is_opened" => 1,
"start" => "2021-07-18 10:00",
"finish" => "2021-07-18 18:00",
"name" => "Schůze KS Pardubický kraj",
"description" => "TEST 8968714465",
"organizer" => "PKS Pardubický kraj"
})->status_is(201);