test activity assertion
This commit is contained in:
parent
fc68457ace
commit
f557a5fb72
4 changed files with 93 additions and 25 deletions
|
|
@ -1,6 +1,7 @@
|
|||
use NRT::Test;
|
||||
use NRT::Helper;
|
||||
use NRT::User;
|
||||
use NRT::Activity;
|
||||
|
||||
package Batch;
|
||||
|
||||
|
|
@ -13,6 +14,7 @@ sub new {
|
|||
$this->{tester} = Test->new( %config );
|
||||
$this->{users} = [];
|
||||
$this->{users_index} = 0;
|
||||
$this->{default_user_index} = "";
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
@ -24,14 +26,8 @@ sub test_rq_empty {
|
|||
|
||||
sub test_user {
|
||||
my $this = shift;
|
||||
my $user1_index = $this->add_user(
|
||||
$this->{config}{Authentification}{Email},
|
||||
$this->{config}{Authentification}{Username},
|
||||
$this->{config}{Authentification}{Password} );
|
||||
$this->{tester}->test_user_authentification(
|
||||
$this->{users}[$user1_index]);
|
||||
$this->{tester}->test_user_already_created(
|
||||
$this->{users}[$user1_index]);
|
||||
$this->{tester}->test_user_authentification( $this->get_default_user );
|
||||
$this->{tester}->test_user_already_created( $this->get_default_user );
|
||||
my $user2_index = $this->add_user(
|
||||
$this->{config}{User}{Email},
|
||||
$this->{config}{User}{Username},
|
||||
|
|
@ -58,10 +54,37 @@ sub add_user {
|
|||
return $this->{users_index}++;
|
||||
}
|
||||
|
||||
sub add_default_user {
|
||||
my ($this) = @_ ;
|
||||
return $this->{default_user_index} = $this->add_user(
|
||||
$this->{config}{Authentification}{Email},
|
||||
$this->{config}{Authentification}{Username},
|
||||
$this->{config}{Authentification}{Password} )
|
||||
}
|
||||
|
||||
sub get_default_user {
|
||||
my ($this) = @_ ;
|
||||
if( $this->{default_user_index} eq "" ){
|
||||
$this->add_default_user ;
|
||||
}
|
||||
return $this->{users}[ $this->{default_user_index} ];
|
||||
}
|
||||
|
||||
sub test_activity {
|
||||
my $this = shift;
|
||||
|
||||
my $activity = Activity->new( "test_1", $this->get_default_user );
|
||||
$this->{tester}->test_create_activity( $activity );
|
||||
$this->{tester}->test_activity_exists( $activity );
|
||||
$this->{tester}->test_activity_remove( $activity );
|
||||
$this->{tester}->test_activity_not_exists( $activity );
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $this = shift;
|
||||
$this->test_rq_empty();
|
||||
#$this->test_rq_empty();
|
||||
$this->test_user();
|
||||
return $this->test_activity();
|
||||
$this->brief();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,23 +41,25 @@ sub rq {
|
|||
|
||||
sub assertEqual {
|
||||
my ($this, $value1, $value2, $equal ) = @_;
|
||||
$equal ||= 1;
|
||||
$equal //= 1;
|
||||
my $success = 0;
|
||||
|
||||
my $test = ( $value1 eq $value2 );
|
||||
$test = ( $equal )? $test : !$test;
|
||||
$assertedComparator = ($equal)? "equal" : "NOT equal" ;
|
||||
$unassertedComparator = ($equal)? "NOT equal" : "equal" ;
|
||||
|
||||
if( $test )
|
||||
{
|
||||
$this->record_result( 1 );
|
||||
print " $value1 ";
|
||||
Helper::printColor( "bright_blue", "equal");
|
||||
Helper::printColor( "bright_blue", $assertedComparator);
|
||||
print " $value2\n";
|
||||
return 1;
|
||||
}else{
|
||||
$this->record_result( 0 );
|
||||
print " $value1 ";
|
||||
Helper::printColor( "bright_blue", "NOT equal");
|
||||
Helper::printColor( "bright_blue", $assertedComparator);
|
||||
print " $value2\n";
|
||||
return 0;
|
||||
};
|
||||
|
|
@ -65,7 +67,7 @@ sub assertEqual {
|
|||
|
||||
sub assertNotEqual {
|
||||
my $this = shift;
|
||||
$this->assertEqual( $_[0], $_[1], 0 );
|
||||
return $this->assertEqual( $_[0], $_[1], 0 );
|
||||
}
|
||||
|
||||
sub get_code {
|
||||
|
|
@ -146,8 +148,7 @@ sub test_user_exists {
|
|||
|
||||
sub test_user_not_exists {
|
||||
my ($this, $user) = @_;
|
||||
my $user = $user->fetch();
|
||||
return $this->assertEqual( $user, 0 );
|
||||
return $this->assertNotEqual( $ruser->{data}{attributes}{email}, $user->{email} );
|
||||
}
|
||||
|
||||
sub test_user_create {
|
||||
|
|
@ -174,8 +175,32 @@ sub test_user_remove {
|
|||
|
||||
sub test_user_already_created {
|
||||
my ($this, $user) = @_;
|
||||
my $creation = $user->create;
|
||||
return $this->assertNotEqual( $creation, "422 Unprocessable Entity");
|
||||
my $creation = $user->fetch;
|
||||
return $this->assertEqual( $creation->{data}{id}, $user->get_id);
|
||||
}
|
||||
|
||||
sub test_create_activity {
|
||||
my ($this, $activity) = @_;
|
||||
my $res = $activity->create;
|
||||
return $this->assertEqual( $res->{data}{attributes}{name}, $activity->{name} );
|
||||
}
|
||||
|
||||
sub test_activity_remove {
|
||||
my ($this, $activity) = @_;
|
||||
return $activity->remove;
|
||||
return $this->assertEqual( $ractivity->{data}{id}, $activity->{id} );
|
||||
}
|
||||
|
||||
sub test_activity_exists {
|
||||
my ($this, $activity) = @_;
|
||||
my $ractivity = $activity->fetch;
|
||||
return $this->assertEqual( $ractivity->{data}{id}, $activity->{id} );
|
||||
}
|
||||
|
||||
sub test_activity_not_exists {
|
||||
my ($this, $activity) = @_;
|
||||
my $ractivity = $activity->fetch;
|
||||
return $this->assertNotEqual( $ractivity->{data}{id}, $activity->{id} );
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use LWP::Simple;
|
||||
use NRT::Test;
|
||||
use NRT::Activity;
|
||||
use Crypt::JWT(decode_jwt);
|
||||
|
||||
package User;
|
||||
|
|
@ -15,6 +16,7 @@ sub new {
|
|||
$this->{manager} = $manager;
|
||||
$this->{token} = "";
|
||||
$this->{id} = "";
|
||||
$this->{activities} = [];
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
@ -43,12 +45,11 @@ sub remove {
|
|||
|
||||
sub fetch {
|
||||
my ($this) = @_ ;
|
||||
$token = $this->get_token;
|
||||
if( !$token ){
|
||||
return 0;
|
||||
}
|
||||
my $user_id = Crypt::JWT::decode_jwt(token => $token, ignore_signature => 1)->{user_id};
|
||||
return $this->{manager}->rq( "users/".$user_id, "GET", "", $this->get_token );
|
||||
return $this->{manager}->rq(
|
||||
"users/".$this->get_id,
|
||||
"GET",
|
||||
"",
|
||||
$this->get_token );
|
||||
}
|
||||
|
||||
sub get_token {
|
||||
|
|
@ -61,4 +62,24 @@ sub get_token {
|
|||
0 ;
|
||||
}
|
||||
|
||||
sub get_id {
|
||||
my $this = shift;
|
||||
if( !($this->{id} eq "") ){
|
||||
return $this->{id};
|
||||
}
|
||||
$token = $this->get_token;
|
||||
if( !$token ){
|
||||
return 0;
|
||||
}
|
||||
return Crypt::JWT::decode_jwt(token => $token, ignore_signature => 1)->{user_id};
|
||||
}
|
||||
|
||||
sub create_activity {
|
||||
my ($this, $name) = @_;
|
||||
my $activity = Activity->new(
|
||||
$name,
|
||||
$this);;
|
||||
return $activity;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ use lib qw(..);
|
|||
use JSON qw( );
|
||||
use Data::Dumper;
|
||||
|
||||
use NRT::User;
|
||||
use NRT::Batch;
|
||||
|
||||
print User::v ;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue