Skip to content
Snippets Groups Projects
Verified Commit f3880091 authored by Andrej Ramašeuski's avatar Andrej Ramašeuski
Browse files

Podpora testovaciho schematu db

parent 307ed5cc
No related branches found
No related tags found
No related merge requests found
Pipeline #4180 failed
......@@ -2,7 +2,7 @@ image: docker:19.03.12
variables:
DOCKER_TLS_CERTDIR: "/certs"
IMAGE_VER: 2.2.0
IMAGE_VER: 2.3.0
services:
- docker:19.03.12-dind
......
......@@ -26,6 +26,11 @@ sub startup {
->username($cfg->{db_username})
->password($cfg->{db_password})
;
if ($cfg->{test}) {
$pg->search_path(['test']);
$pg->db->query('drop schema if exists test cascade');
$pg->db->query('create schema test');
}
$pg->migrations->from_dir($self->home . '/sql');
$pg->migrations->migrate();
$self->helper( pg => sub { return $pg; } );
......@@ -34,8 +39,13 @@ sub startup {
my $schema = CF::Schema->connect({
dsn => $cfg->{db_dsn},
user => $cfg->{db_username},
password => $cfg->{db_password}
password => $cfg->{db_password},
});
if ( $cfg->{test} ) {
$schema->storage->dbh->do("set search_path to test") ;
}
$self->helper( schema => sub { return $schema; } );
# Redis
......
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);
$t->app->pg->db->query('drop schema if exists test cascade');
done_testing();
sub auth_header {
my $claims = shift;
return 'Bearer ' . Mojo::JWT->new(
claims => $claims, secret => SECRET
)->encode();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment