Fixed feed type validation rules for summit
Change-Id: I5284818100954277c8e3651abb7a4c5639ba0797
This commit is contained in:
parent
5d209e8a36
commit
c6bd34a3cc
@ -47,8 +47,8 @@ final class SummitValidationRulesFactory
|
||||
'meeting_room_booking_slot_length' => 'nullable|integer',
|
||||
'meeting_room_booking_max_allowed' => 'nullable|integer|min:1',
|
||||
'api_feed_type' => sprintf('nullable|in:%s',implode(',', Summit::$valid_feed_types)),
|
||||
'api_feed_url' => 'nullable|string|url',
|
||||
'api_feed_key' => 'nullable|string',
|
||||
'api_feed_url' => 'nullable|string|url|required_with:api_feed_type',
|
||||
'api_feed_key' => 'nullable|string|required_with:api_feed_type',
|
||||
];
|
||||
}
|
||||
|
||||
@ -78,8 +78,8 @@ final class SummitValidationRulesFactory
|
||||
'meeting_room_booking_slot_length' => 'nullable|integer',
|
||||
'meeting_room_booking_max_allowed' => 'nullable|integer|min:1',
|
||||
'api_feed_type' => sprintf('nullable|in:%s',implode(',', Summit::$valid_feed_types)),
|
||||
'api_feed_url' => 'nullable|string|url',
|
||||
'api_feed_key' => 'nullable|string',
|
||||
'api_feed_url' => 'nullable|string|url|required_with:api_feed_type',
|
||||
'api_feed_key' => 'nullable|string|required_with:api_feed_type',
|
||||
];
|
||||
}
|
||||
}
|
@ -180,11 +180,11 @@ final class SummitFactory
|
||||
}
|
||||
|
||||
if(isset($data['api_feed_url'])){
|
||||
$summit->setApiFeedUrl($data['api_feed_url']);
|
||||
$summit->setApiFeedUrl(trim($data['api_feed_url']));
|
||||
}
|
||||
|
||||
if(isset($data['api_feed_key'])){
|
||||
$summit->setApiFeedKey($data['api_feed_key']);
|
||||
$summit->setApiFeedKey(trim($data['api_feed_key']));
|
||||
}
|
||||
|
||||
return $summit;
|
||||
|
@ -2653,7 +2653,7 @@ SQL;
|
||||
*/
|
||||
public function setApiFeedType(string $api_feed_type): void
|
||||
{
|
||||
if(!in_array($api_feed_type, self::$valid_feed_types))
|
||||
if(!empty($api_feed_type) && !in_array($api_feed_type, self::$valid_feed_types))
|
||||
throw new ValidationException(sprintf("feed type %s is not valid!", $api_feed_type));
|
||||
$this->api_feed_type = $api_feed_type;
|
||||
}
|
||||
|
@ -161,7 +161,9 @@ final class DoctrineSummitRepository
|
||||
return $this->getEntityManager()->createQueryBuilder()
|
||||
->select("e")
|
||||
->from(\models\summit\Summit::class, "e")
|
||||
->where('e.active = 1')->andWhere("e.api_feed_type is not null")
|
||||
->where('e.active = 1')
|
||||
->andWhere("e.api_feed_type is not null")
|
||||
//->andWhere("e.api_feed_type <> '' ")
|
||||
->orderBy('e.begin_date', 'DESC')
|
||||
->getQuery()
|
||||
->getResult();
|
||||
|
@ -14,6 +14,7 @@
|
||||
use App\Services\Apis\ExternalScheduleFeeds\SchedScheduleFeed;
|
||||
use GuzzleHttp\ClientInterface;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use LaravelDoctrine\ORM\Facades\EntityManager;
|
||||
use Mockery;
|
||||
use models\summit\Summit;
|
||||
use App\Services\Apis\ExternalScheduleFeeds\IExternalScheduleFeedFactory;
|
||||
@ -78,4 +79,10 @@ JSON;
|
||||
$this->assertTrue(count($events) == 218);
|
||||
$this->assertTrue(count($speakers) == 1009);
|
||||
}
|
||||
|
||||
public function testGetSummitWithFeeds(){
|
||||
$repository = EntityManager::getRepository(Summit::class);
|
||||
$summitsWithExternalFeeds = $repository->getActivesWithExternalFeed();
|
||||
$this->assertTrue(count($summitsWithExternalFeeds)>0);
|
||||
}
|
||||
}
|
@ -172,6 +172,82 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
$this->assertResponseStatus(412);
|
||||
}
|
||||
|
||||
public function testAddSummitFeedNull(){
|
||||
$params = [
|
||||
];
|
||||
$name = str_random(16).'_summit';
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'start_date' => 1522853212,
|
||||
'end_date' => 1542853212,
|
||||
'time_zone_id' => 'America/Argentina/Buenos_Aires',
|
||||
'submission_begin_date' => null,
|
||||
'submission_end_date' => null,
|
||||
'api_feed_type' => null,
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"POST",
|
||||
"OAuth2SummitApiController@addSummit",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers,
|
||||
json_encode($data)
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(201);
|
||||
$summit = json_decode($content);
|
||||
$this->assertTrue(!is_null($summit));
|
||||
return $summit;
|
||||
}
|
||||
|
||||
public function testAddSummitFeedEmpty(){
|
||||
$params = [
|
||||
];
|
||||
$name = str_random(16).'_summit';
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'start_date' => 1522853212,
|
||||
'end_date' => 1542853212,
|
||||
'time_zone_id' => 'America/Argentina/Buenos_Aires',
|
||||
'submission_begin_date' => null,
|
||||
'submission_end_date' => null,
|
||||
'api_feed_type' => '',
|
||||
'api_feed_url' => '',
|
||||
'api_feed_key' => ''
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"POST",
|
||||
"OAuth2SummitApiController@addSummit",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers,
|
||||
json_encode($data)
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(201);
|
||||
$summit = json_decode($content);
|
||||
$this->assertTrue(!is_null($summit));
|
||||
return $summit;
|
||||
}
|
||||
|
||||
public function testAddSummit(){
|
||||
$params = [
|
||||
];
|
||||
@ -211,6 +287,40 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
return $summit;
|
||||
}
|
||||
|
||||
public function testAddSummitFeedType412(){
|
||||
$params = [
|
||||
];
|
||||
$name = str_random(16).'_summit';
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'start_date' => 1522853212,
|
||||
'end_date' => 1542853212,
|
||||
'time_zone_id' => 'America/Argentina/Buenos_Aires',
|
||||
'submission_begin_date' => null,
|
||||
'submission_end_date' => null,
|
||||
'api_feed_type' => IExternalScheduleFeedFactory::SchedType,
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"POST",
|
||||
"OAuth2SummitApiController@addSummit",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers,
|
||||
json_encode($data)
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(412);
|
||||
}
|
||||
|
||||
public function testUpdateSummitAlreadyActiveError(){
|
||||
$summit = $this->testAddSummit();
|
||||
$params = [
|
||||
|
Loading…
x
Reference in New Issue
Block a user