Fix on merge speakers
* fixed same speaker merge ( added validation) * fixed summit event serialization error Change-Id: Iadcaab456f6f82df6ba3294354da7a0436591bba
This commit is contained in:
parent
1c0b1a24e4
commit
e0dddf3558
@ -504,7 +504,7 @@ class SummitEvent extends SilverstripeBaseModel
|
||||
public function getTypeId()
|
||||
{
|
||||
try {
|
||||
return $this->type->getId();
|
||||
return !is_null($this->type) ? $this->type->getId() : 0;
|
||||
}
|
||||
catch(\Exception $ex){
|
||||
return 0;
|
||||
|
@ -405,6 +405,9 @@ final class SpeakerService implements ISpeakerService
|
||||
public function merge(PresentationSpeaker $speaker_from, PresentationSpeaker $speaker_to, array $data)
|
||||
{
|
||||
return $this->tx_service->transaction(function () use ($speaker_from, $speaker_to, $data) {
|
||||
|
||||
if($speaker_from->getIdentifier() == $speaker_to->getIdentifier())
|
||||
throw new ValidationException("You can not merge the same speaker!");
|
||||
// bio
|
||||
if (!isset($data['bio'])) throw new ValidationException("bio field is required");
|
||||
$speaker_id = intval($data['bio']);
|
||||
|
@ -290,7 +290,7 @@ class OAuth2SpeakersApiTest extends ProtectedApiTest
|
||||
public function testGetSpeaker(){
|
||||
|
||||
$params = [
|
||||
'speaker_id' => 1
|
||||
'speaker_id' => 2884
|
||||
];
|
||||
|
||||
$headers = [
|
||||
@ -355,4 +355,45 @@ class OAuth2SpeakersApiTest extends ProtectedApiTest
|
||||
$this->assertTrue(!is_null($speaker));
|
||||
}
|
||||
|
||||
public function testMergeSpeakersSame(){
|
||||
|
||||
$params = [
|
||||
'speaker_from_id' => 1,
|
||||
'speaker_to_id' => 1
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$data = [
|
||||
'title' => 1,
|
||||
'bio' => 1,
|
||||
'first_name' => 1,
|
||||
'last_name' => 1,
|
||||
'irc' => 1,
|
||||
'twitter' => 1,
|
||||
'pic' => 1,
|
||||
'registration_request' => 1,
|
||||
'member' => 1,
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"PUT",
|
||||
"OAuth2SummitSpeakersApiController@merge",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers,
|
||||
json_encode($data)
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(412);
|
||||
$speaker = json_decode($content);
|
||||
$this->assertTrue(!is_null($speaker));
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user