TT#8272 Fix customer creation with invoices and email templates in API

Change-Id: Ia568d7a752fd9c1f32ebd81b7a2c909cccb99449
changes/55/10355/2
Irina Peshinskaya 9 years ago
parent c31e254486
commit 207517408a

@ -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 {},
},
},
];
}

@ -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 {},
},
},
];
}

@ -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 => {

@ -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;

@ -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:

@ -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:

@ -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:
Loading…
Cancel
Save