TT#5954 Add Custom Hours option to CF

Change-Id: I1296caa99bbf6a2537ca3aca0c696639f30a7704
changes/60/9760/5
Irina Peshinskaya 9 years ago
parent 2426f59060
commit daf92dcb84

@ -62,10 +62,12 @@ sub build_destinations {
if($c->config->{features}->{callingcard}); if($c->config->{features}->{callingcard});
push @options, { label => 'Call Through', value => 'callthrough' } push @options, { label => 'Call Through', value => 'callthrough' }
if($c->config->{features}->{callthrough}); if($c->config->{features}->{callthrough});
push @options, { label => 'Auto Attendant', value => 'autoattendant' } if($c->config->{features}->{cloudpbx} && $c->stash->{pbx}){
if($c->config->{features}->{cloudpbx} && $c->stash->{pbx}); push @options,
push @options, { label => 'Office Hours Announcement', value => 'officehours' } { label => 'Auto Attendant', value => 'autoattendant' },
if($c->config->{features}->{cloudpbx} && $c->stash->{pbx}); { label => 'Office Hours Announcement', value => 'officehours' },
{ label => 'Custom Hours Announcement', value => 'customhours' };
}
push @options, { label => 'Local Subscriber', value => 'localuser' } push @options, { label => 'Local Subscriber', value => 'localuser' }
if($c->config->{features}->{callthrough} || $c->config->{features}->{callingcard} ); if($c->config->{features}->{callthrough} || $c->config->{features}->{callingcard} );
} }

@ -47,10 +47,12 @@ sub build_destinations {
if($c->config->{features}->{callingcard}); if($c->config->{features}->{callingcard});
push @options, { label => 'Call Through', value => 'callthrough' } push @options, { label => 'Call Through', value => 'callthrough' }
if($c->config->{features}->{callthrough}); if($c->config->{features}->{callthrough});
push @options, { label => 'Auto Attendant', value => 'autoattendant' } if($c->config->{features}->{cloudpbx} && $c->stash->{pbx}){
if($c->config->{features}->{cloudpbx} && $c->stash->{pbx}); push @options,
push @options, { label => 'Office Hours Announcement', value => 'officehours' } { label => 'Auto Attendant', value => 'autoattendant' },
if($c->config->{features}->{cloudpbx} && $c->stash->{pbx}); { label => 'Office Hours Announcement', value => 'officehours' },
{ label => 'Custom Hours Announcement', value => 'customhours' };
}
push @options, { label => 'Local Subscriber', value => 'localuser' } push @options, { label => 'Local Subscriber', value => 'localuser' }
if($c->config->{features}->{callthrough} || $c->config->{features}->{callingcard} ); if($c->config->{features}->{callthrough} || $c->config->{features}->{callingcard} );
} }

@ -81,6 +81,8 @@ sub destination_as_string {
return "Auto Attendant"; return "Auto Attendant";
} elsif($dest =~ /^sip:office-hours\@app\.local$/) { } elsif($dest =~ /^sip:office-hours\@app\.local$/) {
return "Office Hours Announcement"; return "Office Hours Announcement";
} elsif($dest =~ /^sip:custom-hours\@app\.local$/) {
return "Custom Hours Announcement";
} else { } else {
my $d = $dest; my $d = $dest;
$d =~ s/^sips?://; $d =~ s/^sips?://;
@ -1121,6 +1123,8 @@ sub field_to_destination {
$d = "sip:auto-attendant\@app.local"; $d = "sip:auto-attendant\@app.local";
} elsif($d eq "officehours") { } elsif($d eq "officehours") {
$d = "sip:office-hours\@app.local"; $d = "sip:office-hours\@app.local";
} elsif($d eq "customhours") {
$d = "sip:custom-hours\@app.local";
} else { } else {
my $v = $uri; my $v = $uri;
$v =~ s/^sips?://; $v =~ s/^sips?://;
@ -1152,6 +1156,8 @@ sub destination_to_field {
$d = 'autoattendant'; $d = 'autoattendant';
} elsif($d =~ /^sip:office-hours\@app\.local$/) { } elsif($d =~ /^sip:office-hours\@app\.local$/) {
$d = 'officehours'; $d = 'officehours';
} elsif($d =~ /^sip:custom-hours\@app\.local$/) {
$d = 'customhours';
} else { } else {
$duri = $d; $duri = $d;
$d = 'uri'; $d = 'uri';

@ -5,7 +5,7 @@ use Test::More;
use Test::Collection; use Test::Collection;
use Test::FakeData; use Test::FakeData;
use Data::Dumper; use Data::Dumper;
use Clone qw/clone/;
my $fake_data = Test::FakeData->new; my $fake_data = Test::FakeData->new;
$fake_data->set_data_from_script({ $fake_data->set_data_from_script({
@ -25,7 +25,36 @@ $fake_data->set_data_from_script({
{ destination => "voicebox", timeout => 500 }, { destination => "voicebox", timeout => 500 },
], ],
ringtimeout => 10, ringtimeout => 10,
} },
cfb => {
destinations => [
{
destination => "customhours",
priority => "1",
timeout => "300"
},
{
destination => "officehours",
priority => "2",
timeout => "300"
},
],
sources => [
{
source => "123-13-13"
}
],
'times' => [
{
hour => "18-8",
mday => undef,
minute => "0-0",
month => undef,
wday => "6-2",
year => undef
}
]
},
}, },
}, },
}); });
@ -43,13 +72,12 @@ SKIP:{
my ($res,$req,$content); my ($res,$req,$content);
my $cf1 = $test_machine->get_item_hal(); my $cf1 = $test_machine->get_item_hal();
if(!$cf1->{content}->{total_count}){ if(!$cf1->{total_count} && !$cf1->{content_collection}->{total_count}){
skip("Testing requires at least one present callforward. No creation is available.",1); skip("Testing requires at least one present callforward. No creation is available.",1);
} }
$test_machine->check_bundle(); $test_machine->check_bundle();
my($cf1_id) = $test_machine->get_id_from_hal($cf1->{content_collection}); #($cf1,'callforwards');
my($cf1_id) = $test_machine->get_id_from_hal($cf1->{content}); #($cf1,'callforwards');
cmp_ok ($cf1_id, '>', 0, "should be positive integer"); cmp_ok ($cf1_id, '>', 0, "should be positive integer");
my $cf1single_uri = "/api/callforwards/$cf1_id"; my $cf1single_uri = "/api/callforwards/$cf1_id";
my $cf1single; my $cf1single;
@ -69,6 +97,8 @@ SKIP:{
is ($cf1_put->{content}->{cft}{destinations}->[0]->{simple_destination}, "5678", "Check first destination of cft"); is ($cf1_put->{content}->{cft}{destinations}->[0]->{simple_destination}, "5678", "Check first destination of cft");
like ($cf1_put->{content}->{cft}{destinations}->[0]->{destination}, qr/^sip:5678@/, "Check first destination of cft (regex, full uri)"); like ($cf1_put->{content}->{cft}{destinations}->[0]->{destination}, qr/^sip:5678@/, "Check first destination of cft (regex, full uri)");
is ($cf1_put->{content}->{cft}{destinations}->[1]->{destination}, "voicebox", "Check second destination of cft"); is ($cf1_put->{content}->{cft}{destinations}->[1]->{destination}, "voicebox", "Check second destination of cft");
is ($cf1_put->{content}->{cfb}{destinations}->[0]->{destination}, "customhours", "Check customhours destination");
is ($cf1_put->{content}->{cfb}{destinations}->[1]->{destination}, "officehours", "Check customhours destination");
#write invalid 'timeout' #write invalid 'timeout'
($res,$content,$req) = $test_machine->request_put({ ($res,$content,$req) = $test_machine->request_put({
@ -89,7 +119,7 @@ SKIP:{
is($content->{code}, "400", "check error code in body"); is($content->{code}, "400", "check error code in body");
like($content->{message}, qr/Invalid id/, "check error message in body"); like($content->{message}, qr/Invalid id/, "check error message in body");
my($cf2_put,$cf2_get) = $test_machine->check_put2get({data_in => $cf1_put->{content}, uri => $cf1single_uri},undef, 1 ); my($cf2_put,$cf2_get) = $test_machine->check_put2get({data_in => clone($cf1_put->{content}), uri => $cf1single_uri},undef, 1 );
is_deeply($cf1_put->{content}, $cf2_put->{content}, "check put if unmodified put returns the same"); is_deeply($cf1_put->{content}, $cf2_put->{content}, "check put if unmodified put returns the same");
$test_machine->check_embedded($cf2_put->{content}); $test_machine->check_embedded($cf2_put->{content});

@ -3,10 +3,39 @@ use warnings;
use Test::More; use Test::More;
use Test::Collection; use Test::Collection;
use Test::FakeData;
my $test_machine = Test::Collection->new( my $test_machine = Test::Collection->new(
name => 'cfdestinationsets', name => 'cfdestinationsets',
); );
my $fake_data = Test::FakeData->new;
$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)};
$fake_data->set_data_from_script({
'cfdestinationsets' => {
data => {
destinations => [
{
destination => "sip:custom-hours\@app.local",
priority => 1,
timeout => 300,
}
],
name => "Weekend days",
subscriber_id => sub { return shift->get_id('subscribers',@_); },
},
},
});
$test_machine->DATA_ITEM_STORE($fake_data->process('cfdestinationsets'));
$test_machine->form_data_item( );
# create 3 new billing zones from DATA_ITEM
$test_machine->check_create_correct( 3, sub{ $_[0]->{name} .= $_[1]->{i} ; } );
$test_machine->check_get2put();
$test_machine->check_bundle();
diag('Note that the next tests require at least one subscriber to be present ' . diag('Note that the next tests require at least one subscriber to be present ' .
'and accessible to the current API user.'); 'and accessible to the current API user.');
@ -66,6 +95,7 @@ SKIP:
is($res->code, 404, "check get nonexistent cftimesets item"); is($res->code, 404, "check get nonexistent cftimesets item");
} }
$test_machine->clear_test_data_all();
done_testing; done_testing;
# vim: set tabstop=4 expandtab: # vim: set tabstop=4 expandtab:

Loading…
Cancel
Save