Commit 1acc4cd4 authored by Emiliano Balbuena's avatar Emiliano Balbuena

(wip): Spec tests

1 merge request!235WIP: Boost Campaigns (&24)
Pipeline #73841011 running with stages
......@@ -41,6 +41,7 @@ class Dispatcher
/**
* @param Campaign $campaignRef
* @return bool
* @throws CampaignException
* @throws Exception
*/
......@@ -69,5 +70,7 @@ class Dispatcher
error_log("[BoostCampaignsDispatcher] Starting {$campaign->getUrn()}...");
$this->manager->start($campaign);
}
return true;
}
}
<?php
namespace Spec\Minds\Core\Boost\Campaigns;
use Minds\Core\Boost\Campaigns\CampaignException;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class CampaignExceptionSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(CampaignException::class);
}
}
<?php
namespace Spec\Minds\Core\Boost\Campaigns;
use Minds\Core\Boost\Campaigns\Campaign;
use Minds\Core\Boost\Campaigns\Payments\Payment;
use Minds\Entities\Object;
use Minds\Entities\User;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class CampaignSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(Campaign::class);
}
function it_should_get_guid()
{
$this
->setUrn('urn:campaign:1000')
->getGuid()
->shouldReturn('1000');
$this
->setUrn(null)
->getGuid()
->shouldReturn('');
$this
->setUrn(new \stdClass())
->getGuid()
->shouldReturn('');
}
function it_should_set_owner(
User $user
)
{
$user->get('guid')
->shouldBeCalled()
->willReturn('5000');
$this
->setOwner($user)
->getOwnerGuid()
->shouldReturn('5000');
}
function it_should_push_payment(
Payment $payment1,
Payment $payment2,
Payment $payment3
)
{
$this
->setPayments([ $payment1 ])
->pushPayment($payment2)
->pushPayment($payment3)
->getPayments()
->shouldReturn([
$payment1,
$payment2,
$payment3
]);
}
function it_should_get_delivery_status()
{
$this
->getDeliveryStatus()
->shouldReturn(Campaign::PENDING_STATUS);
$this
->setCreatedTimestamp(1564537097)
->getDeliveryStatus()
->shouldReturn(Campaign::CREATED_STATUS);
$this
->setReviewedTimestamp(1564537097)
->getDeliveryStatus()
->shouldReturn(Campaign::APPROVED_STATUS);
$this
->setReviewedTimestamp(null)
->setRevokedTimestamp(1564537097)
->getDeliveryStatus()
->shouldReturn(Campaign::REVOKED_STATUS);
$this
->setRevokedTimestamp(null)
->setRejectedTimestamp(1564537097)
->getDeliveryStatus()
->shouldReturn(Campaign::REJECTED_STATUS);
$this
->setRejectedTimestamp(null)
->setCompletedTimestamp(1564537097)
->getDeliveryStatus()
->shouldReturn(Campaign::COMPLETED_STATUS);
}
function it_should_set_nsfw_along_with_rating()
{
$this
->setNsfw([]);
$this
->getNsfw()
->shouldReturn([]);
$this->getRating()
->shouldReturn(Campaign::SAFE_RATING);
$this
->setNsfw([1, 3]);
$this
->getNsfw()
->shouldReturn([1, 3]);
$this->getRating()
->shouldReturn(Campaign::OPEN_RATING);
}
function it_should_calculate_cpm()
{
$this
->setImpressions(0)
->setBudget(0)
->cpm()
->shouldReturn(0);
$this
->setImpressions(5000)
->setBudget(5)
->cpm()
->shouldReturn(1.0);
$this
->setImpressions(4000)
->setBudget(10)
->cpm()
->shouldReturn(2.5);
}
function it_should_calculate_if_is_delivering()
{
$this
->setReviewedTimestamp(null)
->isDelivering()
->shouldReturn(false);
$this
->setReviewedTimestamp(1564537097)
->isDelivering()
->shouldReturn(true);
}
function it_should_calculate_if_be_started()
{
$this
->setCreatedTimestamp(1564537097)
->setStart(1564600000)
->setEnd(1564700000)
->callOnWrappedObject('shouldBeStarted', [ 1564500000 ])
->shouldReturn(false);
$this
->setCreatedTimestamp(1564537097)
->setStart(1564600000)
->setEnd(1564700000)
->callOnWrappedObject('shouldBeStarted', [ 1564611111 ])
->shouldReturn(true);
}
}
<?php
namespace Spec\Minds\Core\Boost\Campaigns\Delegates;
use Minds\Core\Boost\Campaigns\Delegates\CampaignUrnDelegate;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class CampaignUrnDelegateSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(CampaignUrnDelegate::class);
}
}
<?php
namespace Spec\Minds\Core\Boost\Campaigns\Delegates;
use Minds\Core\Boost\Campaigns\Delegates\NormalizeDatesDelegate;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class NormalizeDatesDelegateSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(NormalizeDatesDelegate::class);
}
}
<?php
namespace Spec\Minds\Core\Boost\Campaigns\Delegates;
use Minds\Core\Boost\Campaigns\Delegates\NormalizeEntityUrnsDelegate;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class NormalizeEntityUrnsDelegateSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(NormalizeEntityUrnsDelegate::class);
}
}
<?php
namespace Spec\Minds\Core\Boost\Campaigns\Delegates;
use Minds\Core\Boost\Campaigns\Delegates\NormalizeHashtagsDelegate;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class NormalizeHashtagsDelegateSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(NormalizeHashtagsDelegate::class);
}
}
<?php
namespace Spec\Minds\Core\Boost\Campaigns\Delegates;
use Minds\Core\Boost\Campaigns\Delegates\PaymentsDelegate;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class PaymentsDelegateSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(PaymentsDelegate::class);
}
}
<?php
namespace Spec\Minds\Core\Boost\Campaigns;
use Exception;
use Minds\Core\Boost\Campaigns\Campaign;
use Minds\Core\Boost\Campaigns\Dispatcher;
use Minds\Core\Boost\Campaigns\Manager;
use Minds\Core\Boost\Campaigns\Metrics;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class DispatcherSpec extends ObjectBehavior
{
/** @var Manager */
protected $manager;
/** @var Metrics */
protected $metrics;
function let(
Manager $manager,
Metrics $metrics
)
{
$this->beConstructedWith($manager, $metrics, 10);
$this->manager = $manager;
$this->metrics = $metrics;
}
function it_is_initializable()
{
$this->shouldHaveType(Dispatcher::class);
}
function it_should_not_sync_campaign_on_lifecycle_if_below_threshold(
Campaign $campaignRef,
Campaign $initialCampaign,
Campaign $campaign
)
{
$campaignRef->getUrn()
->shouldBeCalled()
->willReturn('urn:campaign:1000');
$campaign->getUrn()
->willReturn('urn:campaign:1000');
$this->manager->get('urn:campaign:1000')
->shouldBeCalled()
->willReturn($initialCampaign);
$initialCampaign->isDelivering()
->shouldBeCalled()
->willReturn(true);
$initialCampaign->getImpressionsMet()
->shouldBeCalled()
->willReturn(0);
$this->metrics
->setCampaign($initialCampaign)
->shouldBeCalled()
->willReturn($this->metrics);
$this->metrics
->syncImpressionsMet()
->shouldBeCalled()
->willReturn($campaign);
$campaign->getImpressionsMet()
->shouldBeCalled()
->willReturn(1);
$this->manager->sync($campaign)
->shouldNotBeCalled();
$campaign->shouldBeCompleted(Argument::any())
->shouldBeCalled()
->willReturn(false);
$campaign->shouldBeStarted(Argument::any())
->shouldBeCalled()
->willReturn(false);
$this
->onLifecycle($campaignRef)
->shouldReturn(true);
}
function it_should_sync_campaign_on_lifecycle_if_above_threshold(
Campaign $campaignRef,
Campaign $initialCampaign,
Campaign $campaign
)
{
$campaignRef->getUrn()
->shouldBeCalled()
->willReturn('urn:campaign:1000');
$campaign->getUrn()
->willReturn('urn:campaign:1000');
$this->manager->get('urn:campaign:1000')
->shouldBeCalled()
->willReturn($initialCampaign);
$initialCampaign->isDelivering()
->shouldBeCalled()
->willReturn(true);
$initialCampaign->getImpressionsMet()
->shouldBeCalled()
->willReturn(0);
$this->metrics
->setCampaign($initialCampaign)
->shouldBeCalled()
->willReturn($this->metrics);
$this->metrics
->syncImpressionsMet()
->shouldBeCalled()
->willReturn($campaign);
$campaign->getImpressionsMet()
->shouldBeCalled()
->willReturn(10);
$this->manager->sync($campaign)
->shouldBeCalled()
->willReturn(true);
$campaign->shouldBeCompleted(Argument::any())
->shouldBeCalled()
->willReturn(false);
$campaign->shouldBeStarted(Argument::any())
->shouldBeCalled()
->willReturn(false);
$this
->onLifecycle($campaignRef)
->shouldReturn(true);
}
function it_should_complete_campaign(
Campaign $campaignRef,
Campaign $campaign
)
{
$campaignRef->getUrn()
->shouldBeCalled()
->willReturn('urn:campaign:1000');
$campaign->getUrn()
->willReturn('urn:campaign:1000');
$this->manager->get('urn:campaign:1000')
->shouldBeCalled()
->willReturn($campaign);
$campaign->isDelivering()
->shouldBeCalled()
->willReturn(false);
$campaign->shouldBeCompleted(Argument::any())
->shouldBeCalled()
->willReturn(true);
$this->manager->complete($campaign)
->shouldBeCalled()
->willReturn(true);
$campaign->shouldBeStarted(Argument::any())
->willReturn(false);
$this
->onLifecycle($campaignRef)
->shouldReturn(true);
}
function it_should_start_campaign(
Campaign $campaignRef,
Campaign $campaign
)
{
$campaignRef->getUrn()
->shouldBeCalled()
->willReturn('urn:campaign:1000');
$campaign->getUrn()
->willReturn('urn:campaign:1000');
$this->manager->get('urn:campaign:1000')
->shouldBeCalled()
->willReturn($campaign);
$campaign->isDelivering()
->shouldBeCalled()
->willReturn(false);
$campaign->shouldBeCompleted(Argument::any())
->shouldBeCalled()
->willReturn(false);
$campaign->shouldBeStarted(Argument::any())
->shouldBeCalled()
->willReturn(true);
$this->manager->start($campaign)
->shouldBeCalled()
->willReturn(true);
$this
->onLifecycle($campaignRef)
->shouldReturn(true);
}
}
<?php
namespace Spec\Minds\Core\Boost\Campaigns;
use Minds\Core\Boost\Campaigns\ElasticRepository;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class ElasticRepositorySpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(ElasticRepository::class);
}
}
<?php
namespace Spec\Minds\Core\Boost\Campaigns;
use Minds\Core\Boost\Campaigns\Iterator;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class IteratorSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(Iterator::class);
}
}
<?php
namespace Spec\Minds\Core\Boost\Campaigns;
use Minds\Core\Boost\Campaigns\Manager;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class ManagerSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(Manager::class);
}
}
<?php
namespace Spec\Minds\Core\Boost\Campaigns;
use Minds\Core\Boost\Campaigns\Metrics;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class MetricsSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(Metrics::class);
}
}
<?php
namespace Spec\Minds\Core\Boost\Campaigns\Payments;
use Minds\Core\Boost\Campaigns\Payments\OnChain;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class OnChainSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(OnChain::class);
}
}
<?php
namespace Spec\Minds\Core\Boost\Campaigns\Payments;
use Minds\Core\Boost\Campaigns\Payments\Payment;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class PaymentSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(Payment::class);
}
}
<?php
namespace Spec\Minds\Core\Boost\Campaigns\Payments;
use Minds\Core\Boost\Campaigns\Payments\Repository;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class RepositorySpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(Repository::class);
}
}
<?php
namespace Spec\Minds\Core\Boost\Campaigns;
use Minds\Core\Boost\Campaigns\Repository;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class RepositorySpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(Repository::class);
}
}
<?php
namespace Spec\Minds\Core\Boost\Campaigns;
use Minds\Core\Boost\Campaigns\Stats;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class StatsSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(Stats::class);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment