diff --git a/lib/NGCP/Panel/Controller/API/EmailTemplates.pm b/lib/NGCP/Panel/Controller/API/EmailTemplates.pm index 253165c6d4..8bc7cfdcb0 100644 --- a/lib/NGCP/Panel/Controller/API/EmailTemplates.pm +++ b/lib/NGCP/Panel/Controller/API/EmailTemplates.pm @@ -38,6 +38,17 @@ sub query_params { second => sub {}, }, }, + { + param => 'name', + description => 'Filter for email templates with a specific name', + query => { + first => sub { + my $q = shift; + { 'me.name' => { like => $q } }; + }, + second => sub {}, + }, + }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/InvoiceTemplates.pm b/lib/NGCP/Panel/Controller/API/InvoiceTemplates.pm index 2779c4b588..a7210c4a14 100644 --- a/lib/NGCP/Panel/Controller/API/InvoiceTemplates.pm +++ b/lib/NGCP/Panel/Controller/API/InvoiceTemplates.pm @@ -38,6 +38,17 @@ sub query_params { second => sub {}, }, }, + { + param => 'name', + description => 'Filter for invoice templates with a specific name', + query => { + first => sub { + my $q = shift; + { 'me.name' => { like => $q } }; + }, + second => sub {}, + }, + }, ]; } diff --git a/lib/NGCP/Panel/Form/Contract/CustomerAPI.pm b/lib/NGCP/Panel/Form/Contract/CustomerAPI.pm index c108fe2698..ebc244f28c 100644 --- a/lib/NGCP/Panel/Form/Contract/CustomerAPI.pm +++ b/lib/NGCP/Panel/Form/Contract/CustomerAPI.pm @@ -55,7 +55,7 @@ has_field 'type' => ( }, ); -has_field 'subscriber_email_template' => ( +has_field 'subscriber_email_template_id' => ( type => 'PosInteger', required => 0, element_attr => { @@ -64,7 +64,7 @@ has_field 'subscriber_email_template' => ( }, ); -has_field 'passreset_email_template' => ( +has_field 'passreset_email_template_id' => ( type => 'PosInteger', required => 0, element_attr => { @@ -73,7 +73,7 @@ has_field 'passreset_email_template' => ( }, ); -has_field 'invoice_email_template' => ( +has_field 'invoice_email_template_id' => ( type => 'PosInteger', required => 0, element_attr => { @@ -81,7 +81,7 @@ has_field 'invoice_email_template' => ( title => ['The email template used to notify users about invoice.'] }, ); -has_field 'invoice_template' => ( +has_field 'invoice_template_id' => ( type => 'PosInteger', required => 0, element_attr => { diff --git a/lib/NGCP/Panel/Role/API/Customers.pm b/lib/NGCP/Panel/Role/API/Customers.pm index b47ac876ec..55ec20dd8d 100644 --- a/lib/NGCP/Panel/Role/API/Customers.pm +++ b/lib/NGCP/Panel/Role/API/Customers.pm @@ -104,7 +104,6 @@ sub hal_from_customer { $customer->subscriber_email_template_id ? (Data::HAL::Link->new(relation => 'ngcp:subscriberemailtemplates', href => sprintf("/api/emailtemplates/%d", $customer->subscriber_email_template_id))) : (), $customer->passreset_email_template_id ? (Data::HAL::Link->new(relation => 'ngcp:passresetemailtemplates', href => sprintf("/api/emailtemplates/%d", $customer->passreset_email_template_id))) : (), $customer->invoice_email_template_id ? (Data::HAL::Link->new(relation => 'ngcp:invoiceemailtemplates', href => sprintf("/api/emailtemplates/%d", $customer->invoice_email_template_id))) : (), - $customer->invoice_template_id ? (Data::HAL::Link->new(relation => 'ngcp:invoicetemplates', href => sprintf("/api/invoicetemplates/%d", $customer->invoice_template_id))) : (), Data::HAL::Link->new(relation => 'ngcp:calls', href => sprintf("/api/calls/?customer_id=%d", $customer->id)), $self->get_journal_relation_link($customer->id), ], @@ -161,7 +160,7 @@ sub update_customer { c => $c, form => $form, resource => $resource, - exceptions => [ "contact_id", "billing_profile_id", "profile_package_id", "invoice_email_template_id", "invoice_template_id", "passreset_email_template_id", "subscriber_email_template_id" ], + exceptions => [ "contact_id", "billing_profile_id", "profile_package_id"], ); #$resource->{profile_package_id} = undef unless NGCP::Panel::Utils::ProfilePackages::ENABLE_PROFILE_PACKAGES; diff --git a/t/api-rest/api-customers-collection.t b/t/api-rest/api-customers-collection.t new file mode 100644 index 0000000000..9405c271f6 --- /dev/null +++ b/t/api-rest/api-customers-collection.t @@ -0,0 +1,62 @@ +use strict; +use warnings; + +use Test::Collection; +use Test::FakeData; +use Test::More; +use Data::Dumper; + +#init test_machine +my $test_machine = Test::Collection->new( + name => 'customers', +); +$test_machine->methods->{collection}->{allowed} = {map {$_ => 1} qw(GET HEAD OPTIONS POST)}; +$test_machine->methods->{item}->{allowed} = {map {$_ => 1} qw(GET HEAD OPTIONS PUT PATCH)}; + +my $fake_data = Test::FakeData->new; +$fake_data->set_data_from_script({ + 'customers' => { + 'data' => { + status => 'active', + contact_id => sub { return shift->get_id('customercontacts',@_); }, + billing_profile_id => sub { return shift->get_id('billingprofiles',@_); }, + max_subscribers => undef, + external_id => 'api_test customer'.time(), + type => 'pbxaccount',#sipaccount + 'invoice_template_id' => sub { return shift->get_id('invoicetemplates',@_); }, + 'subscriber_email_template_id' => sub { return shift->get_id('emailtemplates',@_); }, + 'passreset_email_template_id' => sub { return shift->get_id('emailtemplates',@_); }, + 'invoice_email_template_id' => sub { return shift->get_id('emailtemplates',@_); }, + }, + 'query' => ['external_id'], + 'no_delete_available' => 1, + }, +}); + +SKIP:{ + my ($res,$req,$content); + #ew don't have POST fro the invoice templates + my $invoicetemplate = $test_machine->get_item_hal('invoicetemplates','/api/invoicetemplates/?name=api_test'); + + if(!$invoicetemplate->{total_count} ){ + skip("Testing requires at least one present callforward. No creation is available.",1); + } + $fake_data->data->{customers}->{data}->{invoice_template_id} = $invoicetemplate->{content}->{id}; + #for item creation test purposes /post request data/ + $test_machine->DATA_ITEM_STORE($fake_data->process('customers')); + + $test_machine->form_data_item( ); + # create 3 new sound sets from DATA_ITEM + $test_machine->check_create_correct( 1, sub{ $_[0]->{external_id} .= $_[1]->{i}; } ); + $test_machine->check_bundle(); +} + + +$fake_data->clear_test_data_all(); +$test_machine->clear_test_data_all(); +undef $fake_data; +undef $test_machine; + +done_testing; + +# vim: set tabstop=4 expandtab: diff --git a/t/api-rest/api-emailtemplates.t b/t/api-rest/api-emailtemplates.t new file mode 100644 index 0000000000..184f863aae --- /dev/null +++ b/t/api-rest/api-emailtemplates.t @@ -0,0 +1,42 @@ +use strict; +use warnings; + +use Test::Collection; +use Test::FakeData; +use Test::More; +use Data::Dumper; + +#init test_machine +my $test_machine = Test::Collection->new( + name => 'emailtemplates', +); +$test_machine->methods->{collection}->{allowed} = {map {$_ => 1} qw(GET HEAD OPTIONS POST)}; +$test_machine->methods->{item}->{allowed} = {map {$_ => 1} qw(GET HEAD OPTIONS PUT PATCH DELETE)}; + +my $fake_data = Test::FakeData->new; +$fake_data->set_data_from_script({ + emailtemplates => { + data => { + reseller_id => sub { return shift->get_id('resellers',@_); }, + name => 'api_test_email_template_name', + from_email => 'api_test@api-test.emal.com', + subject => 'api_test email template', + body => 'api_test email template: a lot of the text here',#0 + }, + 'query' => ['name'], + }, +}); + +#for item creation test purposes /post request data/ +$test_machine->DATA_ITEM_STORE($fake_data->process('emailtemplates')); + +$test_machine->form_data_item( ); +# create 3 new sound sets from DATA_ITEM +$test_machine->check_create_correct( 3, sub{ $_[0]->{name} .= $_[1]->{i}; } ); +$test_machine->check_get2put(); +$test_machine->check_bundle(); +$test_machine->clear_test_data_all(); + +done_testing; + +# vim: set tabstop=4 expandtab: diff --git a/t/api-rest/api-invoicetemplates.t b/t/api-rest/api-invoicetemplates.t new file mode 100644 index 0000000000..33b29745cf --- /dev/null +++ b/t/api-rest/api-invoicetemplates.t @@ -0,0 +1,39 @@ +use strict; +use warnings; + +use Test::Collection; +use Test::FakeData; +use Test::More; +use Data::Dumper; + +#init test_machine +my $test_machine = Test::Collection->new( + name => 'invoicetemplates', +); +$test_machine->methods->{collection}->{allowed} = {map {$_ => 1} qw(GET OPTIONS HEAD)}; +$test_machine->methods->{item}->{allowed} = {map {$_ => 1} qw(GET OPTIONS HEAD)}; + +my $fake_data = Test::FakeData->new; +$fake_data->set_data_from_script({ + invoicetemplates => { + data => { + 'reseller_id' => sub { return shift->get_id('resellers',@_); }, + 'name' => 'api_test invoice template name'.time(), + 'type' => 'svg', + 'data' => 'api_test email template', + }, + 'query' => ['name'], + }, +}); + +#for item creation test purposes /post request data/ +$test_machine->DATA_ITEM_STORE($fake_data->process('invoicetemplates')); + +$test_machine->form_data_item( ); +# create 3 new sound sets from DATA_ITEM +$test_machine->check_bundle(); +$test_machine->clear_test_data_all(); + +done_testing; + +# vim: set tabstop=4 expandtab: