Created
July 31, 2020 14:24
-
-
Save j1n3l0/27145725a0e8a455dc7c50e3f8b9b7e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package PwC; | |
use 5.032; | |
use Moo; | |
use SOAP::Data::Builder::Simple qw< data >; | |
use Type::Params qw< Invocant compile >; | |
use Type::Utils qw< class_type >; | |
use Types::Standard qw< ArrayRef >; | |
sub update_or_create_request_criteria_node { | |
state $check = compile( Invocant, ArrayRef->of( class_type('SOAP::Data') ) ); | |
my ( $self, $soap_data ) = $check->(@_); | |
my %soap_data_for = map { $_->name => $_ } @{$soap_data}; | |
( $soap_data_for{Request_Criteria} ) | |
= data( 'wd:Request_Criteria' => [ 'wd:Exclude_Inactive_Workers' => '0' ] ); | |
return [ | |
grep defined($_), | |
map $soap_data_for{$_}, | |
qw< Request_References Request_Criteria Response_Filter Response_Group > | |
]; | |
} | |
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Test2::V0 -target => 'PwC'; | |
use Data::Dumper::Concise qw< Dumper >; | |
use DateTime; | |
use SOAP::Data::Builder::Simple qw< data >; | |
subtest 'Update or Create a "Request_Criteria" node' => sub { | |
my $absent = [ | |
data( 'wd:Response_Filter' => [ 'wd:Count' => 1 ] ), | |
data( 'wd:Response_Group' => [ 'wd:Include_User_Account' => 1 ] ), | |
]; | |
my $present = [ | |
data( | |
'wd:Request_References' => [ 'wd:Worker_Reference' => [ 'wd:ID' => 12345 ] ], | |
), | |
data( 'wd:Request_Criteria' => [ 'wd:Exclude_Inactive_Workers' => 1 ] ), | |
data( | |
'wd:Response_Filter' => [ | |
'wd:As_Of_Entry_DateTime' => DateTime->now->datetime, | |
'wd:Page' => 1, | |
'wd:Count' => 100, | |
], | |
), | |
data( | |
'wd:Response_Group' => [ | |
'wd:Include_Reference' => 1, | |
'wd:Include_Personal_Information' => 1 | |
], | |
), | |
]; | |
my $object = $CLASS->new(); | |
is( $object->update_or_create_request_criteria_node($present), | |
array { | |
item object { call name => 'Request_References' }; | |
item object { call name => 'Request_Criteria' }; | |
item object { call name => 'Response_Filter' }; | |
item object { call name => 'Response_Group' }; | |
}, | |
'should update the "Request_Criteria" node if present', | |
); | |
is( $object->update_or_create_request_criteria_node($absent), | |
array { | |
item object { call name => 'Request_Criteria' }; | |
item object { call name => 'Response_Filter' }; | |
item object { call name => 'Response_Group' }; | |
}, | |
'should create the "Request_Criteria" node if absent', | |
); | |
# TODO: dig in to getting the value at [ Request_Criteria > Exclude_Inactive_Workers ] | |
}; | |
done_testing(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment