From bce005891534f94f595720138de0294d0ea5f866 Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Wed, 22 Apr 2015 11:13:00 +0200 Subject: [PATCH] MT#11917 test enviroment json boolean conversion Change-Id: I5b880bfdd39898a14e50949aa9858f800d4bd558 --- .../Controller/API/AutoAttendantsItem.pm | 56 ++++- lib/NGCP/Panel/Controller/API/BillingZones.pm | 8 +- .../Panel/Controller/API/BillingZonesItem.pm | 63 ++++- .../Panel/Controller/API/CallForwardsItem.pm | 1 - .../Controller/API/CustomerBalancesItem.pm | 54 ++++- lib/NGCP/Panel/Controller/API/DomainsItem.pm | 1 - .../Panel/Controller/API/SoundSetsItem.pm | 3 +- .../API/SubscriberProfileSetsItem.pm | 3 +- .../Controller/API/SubscriberProfilesItem.pm | 3 +- lib/NGCP/Panel/Controller/API/Subscribers.pm | 2 +- lib/NGCP/Panel/Controller/Peering.pm | 2 +- lib/NGCP/Panel/Role/API/AutoAttendants.pm | 1 + lib/NGCP/Panel/Role/API/BillingZones.pm | 1 + lib/NGCP/Panel/Role/API/CustomerBalances.pm | 1 + ngcp_panel.conf | 15 ++ t/api-journals.t | 215 +++++++++++++++++- 16 files changed, 406 insertions(+), 23 deletions(-) diff --git a/lib/NGCP/Panel/Controller/API/AutoAttendantsItem.pm b/lib/NGCP/Panel/Controller/API/AutoAttendantsItem.pm index 49f5662070..b63097bc71 100644 --- a/lib/NGCP/Panel/Controller/API/AutoAttendantsItem.pm +++ b/lib/NGCP/Panel/Controller/API/AutoAttendantsItem.pm @@ -22,16 +22,23 @@ class_has('resource_name', is => 'ro', default => 'autoattendants'); class_has('dispatch_path', is => 'ro', default => '/api/autoattendants/'); class_has('relation', is => 'ro', default => 'http://purl.org/sipwise/ngcp-api/#rel-autoattendants'); +class_has(@{ __PACKAGE__->get_journal_query_params() }); + __PACKAGE__->config( action => { - map { $_ => { + (map { $_ => { ACLDetachTo => '/api/root/invalid_user', AllowedRole => [qw/admin reseller/], Args => 1, Does => [qw(ACL RequireSSL)], Method => $_, Path => __PACKAGE__->dispatch_path, - } } @{ __PACKAGE__->allowed_methods }, + } } @{ __PACKAGE__->allowed_methods }), + @{ __PACKAGE__->get_journal_action_config(__PACKAGE__->resource_name,{ + ACLDetachTo => '/api/root/invalid_user', + AllowedRole => [qw/admin reseller/], + Does => [qw(ACL RequireSSL)], + }) } }, action_roles => [qw(HTTPMethods)], ); @@ -106,6 +113,9 @@ sub PUT :Allow { $subscriber = $self->update_item($c, $subscriber, undef, $resource, $form); last unless $subscriber; + my $hal = $self->hal_from_item($c, $subscriber); + last unless $self->add_update_journal_item_hal($c,{ hal => $hal, id => $subscriber->id }); + $guard->commit; if ('minimal' eq $preference) { @@ -113,7 +123,7 @@ sub PUT :Allow { $c->response->header(Preference_Applied => 'return=minimal'); $c->response->body(q()); } else { - my $hal = $self->hal_from_item($c, $subscriber); + #my $hal = $self->hal_from_item($c, $subscriber); my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new( $hal->http_headers, ), $hal->as_json); @@ -150,6 +160,9 @@ sub PATCH :Allow { $subscriber = $self->update_item($c, $subscriber, undef, $resource, $form); last unless $subscriber; + + my $hal = $self->hal_from_item($c, $subscriber); + last unless $self->add_update_journal_item_hal($c,{ hal => $hal, id => $subscriber->id }); $guard->commit; @@ -158,7 +171,7 @@ sub PATCH :Allow { $c->response->header(Preference_Applied => 'return=minimal'); $c->response->body(q()); } else { - my $hal = $self->hal_from_item($c, $subscriber); + #my $hal = $self->hal_from_item($c, $subscriber); my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new( $hal->http_headers, ), $hal->as_json); @@ -170,6 +183,41 @@ sub PATCH :Allow { return; } +sub item_base_journal :Journal { + my $self = shift @_; + return $self->handle_item_base_journal(@_); +} + +sub journals_get :Journal { + my $self = shift @_; + return $self->handle_journals_get(@_); +} + +sub journalsitem_get :Journal { + my $self = shift @_; + return $self->handle_journalsitem_get(@_); +} + +sub journals_options :Journal { + my $self = shift @_; + return $self->handle_journals_options(@_); +} + +sub journalsitem_options :Journal { + my $self = shift @_; + return $self->handle_journalsitem_options(@_); +} + +sub journals_head :Journal { + my $self = shift @_; + return $self->handle_journals_head(@_); +} + +sub journalsitem_head :Journal { + my $self = shift @_; + return $self->handle_journalsitem_head(@_); +} + sub end : Private { my ($self, $c) = @_; diff --git a/lib/NGCP/Panel/Controller/API/BillingZones.pm b/lib/NGCP/Panel/Controller/API/BillingZones.pm index 906270d6a5..b2fd949522 100644 --- a/lib/NGCP/Panel/Controller/API/BillingZones.pm +++ b/lib/NGCP/Panel/Controller/API/BillingZones.pm @@ -182,7 +182,13 @@ sub POST :Allow { $self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to create billing zone."); last; } - + + last unless $self->add_create_journal_item_hal($c,sub { + my $self = shift; + my ($c) = @_; + my $_zone = $self->zone_by_id($c, $zone->id); + return $self->hal_from_zone($c, $_zone, $form); }); + $guard->commit; $c->response->status(HTTP_CREATED); diff --git a/lib/NGCP/Panel/Controller/API/BillingZonesItem.pm b/lib/NGCP/Panel/Controller/API/BillingZonesItem.pm index e119905b36..e8d27804e7 100644 --- a/lib/NGCP/Panel/Controller/API/BillingZonesItem.pm +++ b/lib/NGCP/Panel/Controller/API/BillingZonesItem.pm @@ -19,16 +19,23 @@ class_has('resource_name', is => 'ro', default => 'billingzones'); class_has('dispatch_path', is => 'ro', default => '/api/billingzones/'); class_has('relation', is => 'ro', default => 'http://purl.org/sipwise/ngcp-api/#rel-billingzones'); +class_has(@{ __PACKAGE__->get_journal_query_params() }); + __PACKAGE__->config( action => { - map { $_ => { + (map { $_ => { ACLDetachTo => '/api/root/invalid_user', AllowedRole => [qw/admin reseller/], Args => 1, Does => [qw(ACL RequireSSL)], Method => $_, Path => __PACKAGE__->dispatch_path, - } } @{ __PACKAGE__->allowed_methods } + } } @{ __PACKAGE__->allowed_methods }), + @{ __PACKAGE__->get_journal_action_config(__PACKAGE__->resource_name,{ + ACLDetachTo => '/api/root/invalid_user', + AllowedRole => [qw/admin reseller/], + Does => [qw(ACL RequireSSL)], + }) } }, action_roles => [qw(HTTPMethods)], ); @@ -107,6 +114,9 @@ sub PATCH :Allow { $zone = $self->update_zone($c, $zone, $old_resource, $resource, $form); last unless $zone; + my $hal = $self->hal_from_zone($c, $zone, $form); + last unless $self->add_update_journal_item_hal($c,$hal); + $guard->commit; if ('minimal' eq $preference) { @@ -114,7 +124,7 @@ sub PATCH :Allow { $c->response->header(Preference_Applied => 'return=minimal'); $c->response->body(q()); } else { - my $hal = $self->hal_from_zone($c, $zone, $form); + #my $hal = $self->hal_from_zone($c, $zone, $form); my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new( $hal->http_headers, ), $hal->as_json); @@ -147,6 +157,9 @@ sub PUT :Allow { $zone = $self->update_zone($c, $zone, $old_resource, $resource, $form); last unless $zone; + my $hal = $self->hal_from_zone($c, $zone, $form); + last unless $self->add_update_journal_item_hal($c,$hal); + $guard->commit; if ('minimal' eq $preference) { @@ -154,7 +167,7 @@ sub PUT :Allow { $c->response->header(Preference_Applied => 'return=minimal'); $c->response->body(q()); } else { - my $hal = $self->hal_from_zone($c, $zone, $form); + #my $hal = $self->hal_from_zone($c, $zone, $form); my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new( $hal->http_headers, ), $hal->as_json); @@ -172,6 +185,13 @@ sub DELETE :Allow { { my $zone = $self->zone_by_id($c, $id); last unless $self->resource_exists($c, billingzone => $zone); + + last unless $self->add_delete_journal_item_hal($c,sub { + my $self = shift; + my ($c) = @_; + my $_form = $self->get_form($c); + return $self->hal_from_zone($c, $zone, $_form); }); + try { $zone->billing_fees->delete_all; $zone->delete; @@ -188,6 +208,41 @@ sub DELETE :Allow { return; } +sub item_base_journal :Journal { + my $self = shift @_; + return $self->handle_item_base_journal(@_); +} + +sub journals_get :Journal { + my $self = shift @_; + return $self->handle_journals_get(@_); +} + +sub journalsitem_get :Journal { + my $self = shift @_; + return $self->handle_journalsitem_get(@_); +} + +sub journals_options :Journal { + my $self = shift @_; + return $self->handle_journals_options(@_); +} + +sub journalsitem_options :Journal { + my $self = shift @_; + return $self->handle_journalsitem_options(@_); +} + +sub journals_head :Journal { + my $self = shift @_; + return $self->handle_journals_head(@_); +} + +sub journalsitem_head :Journal { + my $self = shift @_; + return $self->handle_journalsitem_head(@_); +} + sub end : Private { my ($self, $c) = @_; diff --git a/lib/NGCP/Panel/Controller/API/CallForwardsItem.pm b/lib/NGCP/Panel/Controller/API/CallForwardsItem.pm index 43cf1d050b..33c0a85900 100644 --- a/lib/NGCP/Panel/Controller/API/CallForwardsItem.pm +++ b/lib/NGCP/Panel/Controller/API/CallForwardsItem.pm @@ -200,7 +200,6 @@ sub DELETE :Allow { last unless $self->add_delete_journal_item_hal($c,{ hal_from_item => sub { my $self = shift; my ($c) = @_; - #my $_callforward = $self->item_by_id($c, $id, "callforwards"); return $self->hal_from_item($c,$item,"callforwards"); }, id => $id}); diff --git a/lib/NGCP/Panel/Controller/API/CustomerBalancesItem.pm b/lib/NGCP/Panel/Controller/API/CustomerBalancesItem.pm index bbc6f12de6..f41ca17a74 100644 --- a/lib/NGCP/Panel/Controller/API/CustomerBalancesItem.pm +++ b/lib/NGCP/Panel/Controller/API/CustomerBalancesItem.pm @@ -19,16 +19,23 @@ class_has('resource_name', is => 'ro', default => 'customerbalances'); class_has('dispatch_path', is => 'ro', default => '/api/customerbalances/'); class_has('relation', is => 'ro', default => 'http://purl.org/sipwise/ngcp-api/#rel-customerbalances'); +class_has(@{ __PACKAGE__->get_journal_query_params() }); + __PACKAGE__->config( action => { - map { $_ => { + (map { $_ => { ACLDetachTo => '/api/root/invalid_user', AllowedRole => [qw/admin reseller/], Args => 1, Does => [qw(ACL RequireSSL)], Method => $_, Path => __PACKAGE__->dispatch_path, - } } @{ __PACKAGE__->allowed_methods } + } } @{ __PACKAGE__->allowed_methods }), + @{ __PACKAGE__->get_journal_action_config(__PACKAGE__->resource_name,{ + ACLDetachTo => '/api/root/invalid_user', + AllowedRole => [qw/admin reseller/], + Does => [qw(ACL RequireSSL)], + }) } }, action_roles => [qw(HTTPMethods)], ); @@ -106,6 +113,9 @@ sub PATCH :Allow { $item = $self->update_item($c, $item, $old_resource, $resource, $form); last unless $item; + my $hal = $self->hal_from_item($c, $item, $form); + last unless $self->add_update_journal_item_hal($c,$hal); + $guard->commit; if ('minimal' eq $preference) { @@ -113,7 +123,7 @@ sub PATCH :Allow { $c->response->header(Preference_Applied => 'return=minimal'); $c->response->body(q()); } else { - my $hal = $self->hal_from_item($c, $item, $form); + #my $hal = $self->hal_from_item($c, $item, $form); my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new( $hal->http_headers, ), $hal->as_json); @@ -146,6 +156,9 @@ sub PUT :Allow { $item = $self->update_item($c, $item, $old_resource, $resource, $form); last unless $item; + my $hal = $self->hal_from_item($c, $item, $form); + last unless $self->add_update_journal_item_hal($c,$hal); + $guard->commit; if ('minimal' eq $preference) { @@ -165,6 +178,41 @@ sub PUT :Allow { return; } +sub item_base_journal :Journal { + my $self = shift @_; + return $self->handle_item_base_journal(@_); +} + +sub journals_get :Journal { + my $self = shift @_; + return $self->handle_journals_get(@_); +} + +sub journalsitem_get :Journal { + my $self = shift @_; + return $self->handle_journalsitem_get(@_); +} + +sub journals_options :Journal { + my $self = shift @_; + return $self->handle_journals_options(@_); +} + +sub journalsitem_options :Journal { + my $self = shift @_; + return $self->handle_journalsitem_options(@_); +} + +sub journals_head :Journal { + my $self = shift @_; + return $self->handle_journals_head(@_); +} + +sub journalsitem_head :Journal { + my $self = shift @_; + return $self->handle_journalsitem_head(@_); +} + sub end : Private { my ($self, $c) = @_; diff --git a/lib/NGCP/Panel/Controller/API/DomainsItem.pm b/lib/NGCP/Panel/Controller/API/DomainsItem.pm index 56cf9eea4a..d8441f7304 100644 --- a/lib/NGCP/Panel/Controller/API/DomainsItem.pm +++ b/lib/NGCP/Panel/Controller/API/DomainsItem.pm @@ -118,7 +118,6 @@ sub DELETE :Allow { last unless $self->add_delete_journal_item_hal($c,sub { my $self = shift; my ($c) = @_; - #my $_domain = $self->item_by_id($c, $id); return $self->hal_from_item($c,$domain); }); $domain->delete; diff --git a/lib/NGCP/Panel/Controller/API/SoundSetsItem.pm b/lib/NGCP/Panel/Controller/API/SoundSetsItem.pm index a391c03fc8..6236657f5f 100644 --- a/lib/NGCP/Panel/Controller/API/SoundSetsItem.pm +++ b/lib/NGCP/Panel/Controller/API/SoundSetsItem.pm @@ -205,7 +205,8 @@ sub DELETE :Allow { last unless $self->add_delete_journal_item_hal($c,sub { my $self = shift; my ($c) = @_; - return $self->hal_from_item($c, $item); }); + my $_form = $self->get_form($c); + return $self->hal_from_item($c, $item, $_form); }); $item->delete; diff --git a/lib/NGCP/Panel/Controller/API/SubscriberProfileSetsItem.pm b/lib/NGCP/Panel/Controller/API/SubscriberProfileSetsItem.pm index 71846d9725..58d8401856 100644 --- a/lib/NGCP/Panel/Controller/API/SubscriberProfileSetsItem.pm +++ b/lib/NGCP/Panel/Controller/API/SubscriberProfileSetsItem.pm @@ -218,7 +218,8 @@ sub DELETE :Allow { last unless $self->add_delete_journal_item_hal($c,sub { my $self = shift; my ($c) = @_; - return $self->hal_from_item($c, $item); }); + my $_form = $self->get_form($c); + return $self->hal_from_item($c, $item, $_form); }); $item->delete; diff --git a/lib/NGCP/Panel/Controller/API/SubscriberProfilesItem.pm b/lib/NGCP/Panel/Controller/API/SubscriberProfilesItem.pm index 6eb772642f..adad27ed45 100644 --- a/lib/NGCP/Panel/Controller/API/SubscriberProfilesItem.pm +++ b/lib/NGCP/Panel/Controller/API/SubscriberProfilesItem.pm @@ -212,7 +212,8 @@ sub DELETE :Allow { last unless $self->add_delete_journal_item_hal($c,sub { my $self = shift; my ($c) = @_; - return $self->hal_from_item($c, $item); }); + my $_form = $self->get_form($c); + return $self->hal_from_item($c, $item, $_form); }); $item->delete; diff --git a/lib/NGCP/Panel/Controller/API/Subscribers.pm b/lib/NGCP/Panel/Controller/API/Subscribers.pm index d85aaf50be..c7a18e5526 100644 --- a/lib/NGCP/Panel/Controller/API/Subscribers.pm +++ b/lib/NGCP/Panel/Controller/API/Subscribers.pm @@ -281,7 +281,7 @@ sub POST :Allow { $resource = $r->{resource}; try { - my ($uuid_bin, $uuid_string); + my ($uuid_bin, $uuid_string); #what for? UUID::generate($uuid_bin); UUID::unparse($uuid_bin, $uuid_string); diff --git a/lib/NGCP/Panel/Controller/Peering.pm b/lib/NGCP/Panel/Controller/Peering.pm index 2b8368a261..7a4f6ed8a2 100644 --- a/lib/NGCP/Panel/Controller/Peering.pm +++ b/lib/NGCP/Panel/Controller/Peering.pm @@ -7,7 +7,7 @@ BEGIN { extends 'Catalyst::Controller'; } use NGCP::Panel::Form::PeeringGroup; use NGCP::Panel::Form::PeeringRule; use NGCP::Panel::Form::PeeringServer; -use NGCP::Panel::Utils::DialogicImg; +#use NGCP::Panel::Utils::DialogicImg; use NGCP::Panel::Utils::Message; use NGCP::Panel::Utils::Navigation; use NGCP::Panel::Utils::Preferences; diff --git a/lib/NGCP/Panel/Role/API/AutoAttendants.pm b/lib/NGCP/Panel/Role/API/AutoAttendants.pm index 104de33b7c..a2584d1084 100644 --- a/lib/NGCP/Panel/Role/API/AutoAttendants.pm +++ b/lib/NGCP/Panel/Role/API/AutoAttendants.pm @@ -40,6 +40,7 @@ sub hal_from_item { Data::HAL::Link->new(relation => 'self', href => sprintf("%s%d", $self->dispatch_path, $item->id)), Data::HAL::Link->new(relation => 'ngcp:autoattendants', href => sprintf("/api/autoattendants/%d", $item->id)), Data::HAL::Link->new(relation => 'ngcp:subscribers', href => sprintf("/api/subscribers/%d", $item->id)), + $self->get_journal_relation_link($item->id), ], relation => 'ngcp:'.$self->resource_name, ); diff --git a/lib/NGCP/Panel/Role/API/BillingZones.pm b/lib/NGCP/Panel/Role/API/BillingZones.pm index d84e07272f..d6baf69783 100644 --- a/lib/NGCP/Panel/Role/API/BillingZones.pm +++ b/lib/NGCP/Panel/Role/API/BillingZones.pm @@ -59,6 +59,7 @@ sub hal_from_zone { Data::HAL::Link->new(relation => 'self', href => sprintf("%s%d", $self->dispatch_path, $zone->id)), Data::HAL::Link->new(relation => 'ngcp:billingprofiles', href => sprintf("/api/billingprofiles/%d", $zone->billing_profile->id)), ( map { Data::HAL::Link->new(relation => 'ngcp:billingfees', href => sprintf("/api/billingfees/%d", $_->id)) } $zone->billing_fees->all ), + $self->get_journal_relation_link($zone->id), ], relation => 'ngcp:'.$self->resource_name, ); diff --git a/lib/NGCP/Panel/Role/API/CustomerBalances.pm b/lib/NGCP/Panel/Role/API/CustomerBalances.pm index b63728f345..b18c9c4db1 100644 --- a/lib/NGCP/Panel/Role/API/CustomerBalances.pm +++ b/lib/NGCP/Panel/Role/API/CustomerBalances.pm @@ -53,6 +53,7 @@ sub hal_from_item { Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), Data::HAL::Link->new(relation => 'self', href => sprintf("%s%d", $self->dispatch_path, $item->contract->id)), Data::HAL::Link->new(relation => 'ngcp:customers', href => sprintf("/api/customers/%d", $item->contract->id)), + $self->get_journal_relation_link($item->contract->id), ], relation => 'ngcp:'.$self->resource_name, ); diff --git a/ngcp_panel.conf b/ngcp_panel.conf index 416fd2a8c9..409aa9e9a2 100644 --- a/ngcp_panel.conf +++ b/ngcp_panel.conf @@ -317,4 +317,19 @@ log4perl.appender.Default.layout.ConversionPattern=%d{ISO8601} [%p] [%F +%L] %m{ enabled 1 + + operations create + operations update + operations delete + format sereal + enabled 1 + + + operations create + operations update + operations delete + format sereal + enabled 1 + + \ No newline at end of file diff --git a/t/api-journals.t b/t/api-journals.t index 01e785e6f8..206277e932 100644 --- a/t/api-journals.t +++ b/t/api-journals.t @@ -13,8 +13,12 @@ BEGIN { } use NGCP::Panel::Utils::Journal qw(); +my $json = JSON->new(); +$json->allow_blessed(1); +$json->convert_blessed(1); + my $is_local_env = 0; -my $mysql_sqlstrict = not $is_local_env; +my $mysql_sqlstrict = 1; #not $is_local_env; my $enable_journal_tests = 1; use Config::General; @@ -64,6 +68,7 @@ my $t = time; my $default_reseller_id = 1; my $billingprofile = test_billingprofile($t,$default_reseller_id); +my $billingzone = test_billingzone($billingprofile); my $systemcontact = test_systemcontact($t); my $contract = test_contract($billingprofile,$systemcontact); (my $reseller,$billingprofile) = test_reseller($t,$contract); @@ -72,12 +77,14 @@ my $customercontact = test_customercontact($t,$reseller); my $customer = test_customer($customercontact,$billingprofile); my $customerpreferences = test_customerpreferences($customer); -my $subscriberprofileset = test_subscriberprofileset($t,$reseller); -my $subscriberprofile = test_subscriberprofile($t,$subscriberprofileset); -my $profilepreferences = test_profilepreferences($subscriberprofile); +#my $subscriberprofileset = test_subscriberprofileset($t,$reseller); +#my $subscriberprofile = test_subscriberprofile($t,$subscriberprofileset); +#my $profilepreferences = test_profilepreferences($subscriberprofile); my $subscriber = test_subscriber($t,$customer,$domain); +#my $autoattendants = test_autoattendants($t,$subscriber); + my $voicemailsettings = test_voicemailsettings($t,$subscriber); my $trustedsource = test_trustedsource($subscriber); @@ -106,6 +113,198 @@ my $subscriberpreferences = test_subscriberpreferences($subscriber,$customersoun done_testing; + +#sub test_customerbalances { +# my ($t,$subscriber) = @_; +# +# my $customerbalances_uri = $uri.'/api/customerbalances/'.$subscriber->{id}; +# $req = HTTP::Request->new('PUT', $customerbalances_uri); #$customer->{id}); +# $req->header('Content-Type' => 'application/json'); +# $req->header('Prefer' => 'return=representation'); +# $req->content(JSON::to_json({ +# cash_balance => 10, +# free_time_balance => 10, +# })); +# $res = $ua->request($req); +# is($res->code, 200, "PUT test customerbalances"); +# $req = HTTP::Request->new('GET', $customerbalances_uri); # . '?page=1&rows=' . (scalar keys %$put_data)); +# $res = $ua->request($req); +# is($res->code, 200, "fetch PUT test customerbalances"); +# my $customerbalances = JSON::from_json($res->decoded_content); +# +# _test_item_journal_link('customerbalances',$customerbalances,$subscriber->{id}); +# _test_journal_options_head('customerbalances',$subscriber->{id}); +# my $journals = {}; +# my $journal = _test_journal_top_journalitem('customerbalances',$subscriber->{id},$customerbalances,'update',$journals); +# _test_journal_options_head('customerbalances',$subscriber->{id},$journal->{id}); +# +# $req = HTTP::Request->new('PATCH', $customerbalances_uri); +# $req->header('Content-Type' => 'application/json-patch+json'); +# $req->header('Prefer' => 'return=representation'); +# $req->content(JSON::to_json({ +# cash_balance => 10, +# free_time_balance => 10, +# })); +# $res = $ua->request($req); +# is($res->code, 200, "PATCH test customerbalances"); +# $req = HTTP::Request->new('GET', $customerbalances_uri); +# $res = $ua->request($req); +# is($res->code, 200, "fetch PATCHED test customerbalances"); +# $customerbalances = JSON::from_json($res->decoded_content); +# +# _test_item_journal_link('customerbalances',$customerbalances,$subscriber->{id}); +# $journal = _test_journal_top_journalitem('customerbalances',$subscriber->{id},$customerbalances,'update',$journals,$journal); +# +# _test_journal_collection('customerbalances',$subscriber->{id},$journals); +# +# return $customerbalances; +# +#} + + +sub test_billingzone { + my ($billingprofile) = @_; + $req = HTTP::Request->new('POST', $uri.'/api/billingzones/'); + $req->header('Content-Type' => 'application/json'); + $req->content(JSON::to_json({ + zone => 'CH', + billing_profile_id => $billingprofile->{id}, + })); + $res = $ua->request($req); + is($res->code, 201, "POST test billingzone"); + my $billingzone_uri = $uri.'/'.$res->header('Location'); + $req = HTTP::Request->new('GET', $billingzone_uri); + $res = $ua->request($req); + is($res->code, 200, "fetch POSTed test billingzone"); + my $billingzone = JSON::from_json($res->decoded_content); + + _test_item_journal_link('billingzones',$billingzone,$billingzone->{id}); + _test_journal_options_head('billingzones',$billingzone->{id}); + my $journals = {}; + my $journal = _test_journal_top_journalitem('billingzones',$billingzone->{id},$billingzone,'create',$journals); + _test_journal_options_head('billingzones',$billingzone->{id},$journal->{id}); + + $req = HTTP::Request->new('PUT', $billingzone_uri); + $req->header('Content-Type' => 'application/json'); + $req->header('Prefer' => 'return=representation'); + $req->content(JSON::to_json({ + zone => 'DE', + billing_profile_id => $billingprofile->{id}, + })); + $res = $ua->request($req); + is($res->code, 200, "PUT test billingzone"); + $req = HTTP::Request->new('GET', $billingzone_uri); + $res = $ua->request($req); + is($res->code, 200, "fetch PUT test billingzone"); + $billingzone = JSON::from_json($res->decoded_content); + + _test_item_journal_link('billingzones',$billingzone,$billingzone->{id}); + $journal = _test_journal_top_journalitem('billingzones',$billingzone->{id},$billingzone,'update',$journals,$journal); + + $req = HTTP::Request->new('PATCH', $billingzone_uri); + $req->header('Content-Type' => 'application/json-patch+json'); + $req->header('Prefer' => 'return=representation'); + $req->content(JSON::to_json( + [ { op => 'replace', path => '/zone', value => 'AT' } ] + )); + $res = $ua->request($req); + is($res->code, 200, "PATCH test billingzone"); + $req = HTTP::Request->new('GET', $billingzone_uri); + $res = $ua->request($req); + is($res->code, 200, "fetch PATCHed test billingzone"); + $billingzone = JSON::from_json($res->decoded_content); + + _test_item_journal_link('billingzones',$billingzone,$billingzone->{id}); + $journal = _test_journal_top_journalitem('billingzones',$billingzone->{id},$billingzone,'update',$journals,$journal); + + $req = HTTP::Request->new('DELETE', $billingzone_uri); + $res = $ua->request($req); + is($res->code, 204, "delete POSTed test billingzone"); + #$domain = JSON::from_json($res->decoded_content); + + $journal = _test_journal_top_journalitem('billingzones',$billingzone->{id},$billingzone,'delete',$journals,$journal); + + _test_journal_collection('billingzones',$billingzone->{id},$journals); + + $req = HTTP::Request->new('POST', $uri.'/api/billingzones/'); + $req->header('Content-Type' => 'application/json'); + $req->content(JSON::to_json({ + zone => 'AT', + billing_profile_id => $billingprofile->{id}, + })); + $res = $ua->request($req); + is($res->code, 201, "POST another test billingzone"); + $billingzone_uri = $uri.'/'.$res->header('Location'); + $req = HTTP::Request->new('GET', $billingzone_uri); + $res = $ua->request($req); + is($res->code, 200, "fetch POSTed test billingzone"); + $billingzone = JSON::from_json($res->decoded_content); + + return $billingzone; + +} + +sub test_autoattendants { + my ($t,$subscriber) = @_; + + my $autoattendants_uri = $uri.'/api/autoattendants/'.$subscriber->{id}; + $req = HTTP::Request->new('PUT', $autoattendants_uri); #$customer->{id}); + $req->header('Content-Type' => 'application/json'); + $req->header('Prefer' => 'return=representation'); + $req->content(JSON::to_json({ + slots => [ {slot => '0', + destination => 'autoattendant_dest_'.$t.'@example.com' }, + {slot => '1', + destination => 'autoattendant_dest_'.$t.'@example.com' }, + {slot => '2', + destination => 'autoattendant_dest_'.$t.'@example.com' },], + })); + $res = $ua->request($req); + is($res->code, 200, "PUT test autoattendants"); + $req = HTTP::Request->new('GET', $autoattendants_uri); # . '?page=1&rows=' . (scalar keys %$put_data)); + $res = $ua->request($req); + is($res->code, 200, "fetch PUT test autoattendants"); + my $autoattendants = JSON::from_json($res->decoded_content); + + _test_item_journal_link('autoattendants',$autoattendants,$subscriber->{id}); + _test_journal_options_head('autoattendants',$subscriber->{id}); + my $journals = {}; + my $journal = _test_journal_top_journalitem('autoattendants',$subscriber->{id},$autoattendants,'update',$journals); + _test_journal_options_head('autoattendants',$subscriber->{id},$journal->{id}); + + $req = HTTP::Request->new('PATCH', $autoattendants_uri); + $req->header('Content-Type' => 'application/json-patch+json'); + $req->header('Prefer' => 'return=representation'); + $req->content(JSON::to_json( + [ { op => 'replace', path => '/slots', value => [ {slot => '3', + destination => 'autoattendant_dest_'.$t.'@example.com' }, + {slot => '4', + destination => 'autoattendant_dest_'.$t.'@example.com' }, + {slot => '5', + destination => 'autoattendant_dest_'.$t.'@example.com' },] } ] + )); + $res = $ua->request($req); + is($res->code, 200, "PATCH test autoattendants"); + $req = HTTP::Request->new('GET', $autoattendants_uri); + $res = $ua->request($req); + is($res->code, 200, "fetch PATCHED test autoattendants"); + $autoattendants = JSON::from_json($res->decoded_content); + + _test_item_journal_link('autoattendants',$autoattendants,$subscriber->{id}); + $journal = _test_journal_top_journalitem('autoattendants',$subscriber->{id},$autoattendants,'update',$journals,$journal); + + _test_journal_collection('autoattendants',$subscriber->{id},$journals); + + return $autoattendants; + +} + + + + + + + sub test_voicemailsettings { my ($t,$subscriber) = @_; @@ -2098,4 +2297,12 @@ sub _get_preference_value { return undef; } +sub _to_json { + return $json->encode(shift); +} + +sub _from_json { + return $json->decode(shift); +} + # vim: set tabstop=4 expandtab: