Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project
Project
Details
Activity
Releases
Dependency List
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
191
Issues
191
List
Boards
Labels
Service Desk
Milestones
Merge Requests
31
Merge Requests
31
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
List
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Commits
1acc4cd4
Commit
1acc4cd4
authored
23 minutes ago
by
Emiliano Balbuena
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(wip): Spec tests
parent
f0b50533
goal/boost-campaigns-e24
1 merge request
!235
WIP: Boost Campaigns (&24)
Pipeline
#73841011
failed with stages
in 13 minutes and 36 seconds
Changes
18
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
624 additions
and
0 deletions
+624
-0
Dispatcher.php
Core/Boost/Campaigns/Dispatcher.php
+3
-0
CampaignExceptionSpec.php
Spec/Core/Boost/Campaigns/CampaignExceptionSpec.php
+15
-0
CampaignSpec.php
Spec/Core/Boost/Campaigns/CampaignSpec.php
+177
-0
CampaignUrnDelegateSpec.php
...ore/Boost/Campaigns/Delegates/CampaignUrnDelegateSpec.php
+15
-0
NormalizeDatesDelegateSpec.php
.../Boost/Campaigns/Delegates/NormalizeDatesDelegateSpec.php
+15
-0
NormalizeEntityUrnsDelegateSpec.php
...t/Campaigns/Delegates/NormalizeEntityUrnsDelegateSpec.php
+15
-0
NormalizeHashtagsDelegateSpec.php
...ost/Campaigns/Delegates/NormalizeHashtagsDelegateSpec.php
+15
-0
PaymentsDelegateSpec.php
Spec/Core/Boost/Campaigns/Delegates/PaymentsDelegateSpec.php
+15
-0
DispatcherSpec.php
Spec/Core/Boost/Campaigns/DispatcherSpec.php
+219
-0
ElasticRepositorySpec.php
Spec/Core/Boost/Campaigns/ElasticRepositorySpec.php
+15
-0
IteratorSpec.php
Spec/Core/Boost/Campaigns/IteratorSpec.php
+15
-0
ManagerSpec.php
Spec/Core/Boost/Campaigns/ManagerSpec.php
+15
-0
MetricsSpec.php
Spec/Core/Boost/Campaigns/MetricsSpec.php
+15
-0
OnChainSpec.php
Spec/Core/Boost/Campaigns/Payments/OnChainSpec.php
+15
-0
PaymentSpec.php
Spec/Core/Boost/Campaigns/Payments/PaymentSpec.php
+15
-0
RepositorySpec.php
Spec/Core/Boost/Campaigns/Payments/RepositorySpec.php
+15
-0
RepositorySpec.php
Spec/Core/Boost/Campaigns/RepositorySpec.php
+15
-0
StatsSpec.php
Spec/Core/Boost/Campaigns/StatsSpec.php
+15
-0
No files found.
Core/Boost/Campaigns/Dispatcher.php
View file @
1acc4cd4
...
...
@@ -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
;
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Campaigns/CampaignExceptionSpec.php
0 → 100644
View file @
1acc4cd4
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Campaigns/CampaignSpec.php
0 → 100644
View file @
1acc4cd4
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Campaigns/Delegates/CampaignUrnDelegateSpec.php
0 → 100644
View file @
1acc4cd4
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Campaigns/Delegates/NormalizeDatesDelegateSpec.php
0 → 100644
View file @
1acc4cd4
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Campaigns/Delegates/NormalizeEntityUrnsDelegateSpec.php
0 → 100644
View file @
1acc4cd4
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Campaigns/Delegates/NormalizeHashtagsDelegateSpec.php
0 → 100644
View file @
1acc4cd4
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Campaigns/Delegates/PaymentsDelegateSpec.php
0 → 100644
View file @
1acc4cd4
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Campaigns/DispatcherSpec.php
0 → 100644
View file @
1acc4cd4
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Campaigns/ElasticRepositorySpec.php
0 → 100644
View file @
1acc4cd4
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Campaigns/IteratorSpec.php
0 → 100644
View file @
1acc4cd4
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Campaigns/ManagerSpec.php
0 → 100644
View file @
1acc4cd4
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Campaigns/MetricsSpec.php
0 → 100644
View file @
1acc4cd4
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Campaigns/Payments/OnChainSpec.php
0 → 100644
View file @
1acc4cd4
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Campaigns/Payments/PaymentSpec.php
0 → 100644
View file @
1acc4cd4
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Campaigns/Payments/RepositorySpec.php
0 → 100644
View file @
1acc4cd4
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Campaigns/RepositorySpec.php
0 → 100644
View file @
1acc4cd4
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Campaigns/StatsSpec.php
0 → 100644
View file @
1acc4cd4
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment