MT#7447 fix api customers test

we now show terminated customers by default, so filter for
active ones only. see also MT#7797
gjungwirth/voicemail_number
Gerhard Jungwirth 12 years ago
parent 6dd1562252
commit 49f14f8e8f

@ -20,7 +20,7 @@ class_has 'api_description' => (
is => 'ro',
isa => 'Str',
default =>
'Defines a billing container for end customers. Customers usually have one or more <a href="#subscribers">Subscribers</a>. A <a href="#billingprofiles">Billing Profile</a> is assigned to a customer, and it has <a href="#contractbalances">Contract Balances</a> indicating the saldo of the customer for current and past billing intervals.'
'Defines a billing container for end customers. Customers usually have one or more <a href="#subscribers">Subscribers</a>. A <a href="#billingprofiles">Billing Profile</a> is assigned to a customer, and it has <a href="#contractbalances">Contract Balances</a> indicating the saldo of the customer for current and past billing intervals.',
);
class_has 'query_params' => (
@ -80,7 +80,7 @@ __PACKAGE__->config(
Does => [qw(ACL CheckTrailingSlash RequireSSL)],
Method => $_,
Path => __PACKAGE__->dispatch_path,
} } @{ __PACKAGE__->allowed_methods }
} } @{ __PACKAGE__->allowed_methods },
},
action_roles => [qw(HTTPMethods)],
);
@ -90,6 +90,7 @@ sub auto :Private {
$self->set_body($c);
$self->log_request($c);
return 1;
}
sub GET :Allow {
@ -115,15 +116,9 @@ sub GET :Allow {
name => 'ngcp',
templated => true,
),
Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'),
Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows));
Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/');
if(($total_count / $rows) > $page ) {
push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows));
}
if($page > 1) {
push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows));
}
push @links, $self->collection_nav_links($page, $rows, $total_count, $c->request->path, $c->request->query_params);
my $hal = Data::HAL->new(
embedded => [@embedded],
@ -272,6 +267,7 @@ sub end : Private {
my ($self, $c) = @_;
$self->log_response($c);
return;
}
# vim: set tabstop=4 expandtab:

@ -409,6 +409,25 @@ sub paginate_order_collection {
return ($total_count, $item_rs);
}
sub collection_nav_links {
my ($self, $page, $rows, $total_count, $path, $params) = @_;
$params = { %{ $params } }; #copy
delete @{$params}{'page', 'rows'};
my $rest_params = join( '&', map {"$_=".$params->{$_}} keys %{$params});
$rest_params = $rest_params ? "&$rest_params" : "";
my @links = (Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s%s', $path, $page, $rows, $rest_params)));
if(($total_count / $rows) > $page ) {
push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d%s', $path, $page + 1, $rows, $rest_params));
}
if($page > 1) {
push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d%s', $path, $page - 1, $rows, $rest_params));
}
return @links;
}
sub apply_patch {
my ($self, $c, $entity, $json) = @_;
my $patch = JSON::decode_json($json);

@ -192,7 +192,7 @@ my @allcustomers = ();
ok($err->{message} =~ /field='max_subscribers'/, "check error message in body");
# iterate over customers collection to check next/prev links and status
my $nexturi = $uri.'/api/customers/?page=1&rows=5';
my $nexturi = $uri.'/api/customers/?page=1&rows=5&status=active';
do {
$res = $ua->get($nexturi);
is($res->code, 200, "fetch contacts page");
@ -408,18 +408,6 @@ my @allcustomers = ();
$pc = JSON::from_json($res->decoded_content);
is($pc->{status}, "terminated", "check termination status of customer");
}
# check if we can still get the terminated customer
$req = HTTP::Request->new('GET', $uri.'/'.$pc->{_links}->{self}->{href});
$res = $ua->request($req);
is($res->code, 404, "check fetching of terminated customer");
# check if deletion of contact is now ok
# TODO: are we supposed to be able to delete a contact for a terminated
# customer? there are still DB contstraints in the way!
#$req = HTTP::Request->new('DELETE', $uri.'/'.$custcontact->{_links}->{self}->{href});
#$res = $ua->request($req);
#is($res->code, 204, "check deletion of unused contact");
}
done_testing;

Loading…
Cancel
Save