MT#7959 fix contract PUT/PATCH, tests

now that type is checked by form, it must be
properly passed by put/patch. Also error message changed.
mr3.3
Gerhard Jungwirth 12 years ago
parent df16360d72
commit 526a6c1a19

@ -31,7 +31,7 @@ __PACKAGE__->config(
Does => [qw(ACL RequireSSL)], Does => [qw(ACL RequireSSL)],
Method => $_, Method => $_,
Path => __PACKAGE__->dispatch_path, Path => __PACKAGE__->dispatch_path,
} } @{ __PACKAGE__->allowed_methods } } } @{ __PACKAGE__->allowed_methods },
}, },
action_roles => [qw(HTTPMethods)], action_roles => [qw(HTTPMethods)],
); );
@ -41,6 +41,7 @@ sub auto :Private {
$self->set_body($c); $self->set_body($c);
$self->log_request($c); $self->log_request($c);
return 1;
} }
sub GET :Allow { sub GET :Allow {
@ -54,9 +55,8 @@ sub GET :Allow {
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new( my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
(map { # XXX Data::HAL must be able to generate links with multiple relations (map { # XXX Data::HAL must be able to generate links with multiple relations
s|rel="(http://purl.org/sipwise/ngcp-api/#rel-resellers)"|rel="item $1"|; s|rel="(http://purl.org/sipwise/ngcp-api/#rel-resellers)"|rel="item $1"|r =~
s/rel=self/rel="item self"/; s/rel=self/rel="item self"/r;
$_
} $hal->http_headers), } $hal->http_headers),
), $hal->as_json); ), $hal->as_json);
$c->response->headers($response->headers); $c->response->headers($response->headers);
@ -104,6 +104,7 @@ sub PATCH :Allow {
my $old_resource = { $contract->get_inflated_columns }; my $old_resource = { $contract->get_inflated_columns };
my $billing_mapping = $contract->billing_mappings->find($contract->get_column('bmid')); my $billing_mapping = $contract->billing_mappings->find($contract->get_column('bmid'));
$old_resource->{billing_profile_id} = $billing_mapping->billing_profile_id; $old_resource->{billing_profile_id} = $billing_mapping->billing_profile_id;
$old_resource->{type} = $billing_mapping->product->class;
my $resource = $self->apply_patch($c, $old_resource, $json); my $resource = $self->apply_patch($c, $old_resource, $json);
last unless $resource; last unless $resource;
@ -146,6 +147,8 @@ sub PUT :Allow {
); );
last unless $resource; last unless $resource;
my $old_resource = { $contract->get_inflated_columns }; my $old_resource = { $contract->get_inflated_columns };
my $billing_mapping = $contract->billing_mappings->find($contract->get_column('bmid'));
$old_resource->{type} = $billing_mapping->product->class;
my $form = $self->get_form($c); my $form = $self->get_form($c);
$contract = $self->update_contract($c, $contract, $old_resource, $resource, $form); $contract = $self->update_contract($c, $contract, $old_resource, $resource, $form);
@ -171,6 +174,7 @@ sub PUT :Allow {
} }
=pod =pod
# we don't allow to delete contracts # we don't allow to delete contracts
sub DELETE :Allow { sub DELETE :Allow {
my ($self, $c, $id) = @_; my ($self, $c, $id) = @_;
@ -196,12 +200,14 @@ sub DELETE :Allow {
} }
return; return;
} }
=cut =cut
sub end : Private { sub end : Private {
my ($self, $c) = @_; my ($self, $c) = @_;
$self->log_response($c); $self->log_response($c);
return;
} }
# vim: set tabstop=4 expandtab: # vim: set tabstop=4 expandtab:

@ -128,6 +128,7 @@ sub update_contract {
form => $form, form => $form,
resource => $resource, resource => $resource,
); );
delete $resource->{type};
my $now = NGCP::Panel::Utils::DateTime::current_local; my $now = NGCP::Panel::Utils::DateTime::current_local;
$resource->{modify_timestamp} = $now; $resource->{modify_timestamp} = $now;

@ -108,7 +108,7 @@ my @allcontracts = ();
is($res->code, 422, "create contract with invalid type"); is($res->code, 422, "create contract with invalid type");
my $err = JSON::from_json($res->decoded_content); my $err = JSON::from_json($res->decoded_content);
is($err->{code}, "422", "check error code in body"); is($err->{code}, "422", "check error code in body");
ok($err->{message} =~ /Invalid 'type'/, "check error message in body"); like($err->{message}, qr/Validation failed.*type/, "check error message in body");
# try to create invalid contract with wrong billing profile # try to create invalid contract with wrong billing profile
$req->content(JSON::to_json({ $req->content(JSON::to_json({

Loading…
Cancel
Save