Commit 762224c1 authored by Mark Harding's avatar Mark Harding

(chore): apply contibutions score to prospect too

1 merge request!236epic/referrals
Pipeline #71657809 passed with stages
in 8 minutes and 41 seconds
......@@ -10,6 +10,7 @@ class ContributionValues
'votes' => 1,
'subscribers' => 4,
'referrals' => 50,
'referrals_welcome' => 50,
'checkin' => 2,
'jury_duty' => 25,
];
......
......@@ -96,6 +96,15 @@ class Manager
return $contributions;
}
/**
* Add a contibution score row manually
* @param Contribution $contribution
* @return bool
*/
public function add(Contribution $contribution) : bool
{
return $this->repository->add($contribution);
}
public function issueCheckins($count)
{
......
......@@ -7,6 +7,8 @@ namespace Minds\Core\Rewards\Delegates;
use Minds\Core\Di\Di;
use Minds\Entities\User;
use Minds\Core\Referrals\Referral;
use Minds\Core\Rewards\Contributions\Contribution;
use Minds\Core\Rewards\Contributions\ContributionValues;
class ReferralDelegate
{
......@@ -14,9 +16,10 @@ class ReferralDelegate
/** @var Manager $manager */
private $manager;
public function __construct($manager = null)
public function __construct($manager = null, $contributionsManager = null)
{
$this->manager = $manager ?: Di::_()->get('Referrals\Manager');
$this->contributionsManager = $contributionsManager ?? Di::_()->get('Rewards\Contributions\Manager');
}
/**
......@@ -33,6 +36,25 @@ class ReferralDelegate
$this->manager->update($referral);
// TODO: This should be in its own delegate?
$this->issueContributionScore($user);
}
/**
* Issue contribution score when referred
* TODO: Move to own delegate?
* @param User $user
* @return void
*/
private function issueContributionScore(User $user) : void
{
$ts = strtotime('midnight');
$contribution = new Contribution();
$contribution->setTimestamp($ts)
->setUser($user)
->setScore(ContributionValues::$multipliers['referrals_welcome'])
->setAmount(1);
$this->contributionsManager->add($contribution);
}
}
\ No newline at end of file
......@@ -7,6 +7,10 @@ class RewardsProvider extends Provider
{
public function register()
{
$this->di->bind('Rewards\Contributions\Manager', function ($di) {
return new Contributions\Manager();
}, [ 'useFactory'=> true ]);
$this->di->bind('Rewards\Contributions\Repository', function ($di) {
return new Contributions\Repository();
}, [ 'useFactory'=> true ]);
......
......@@ -7,23 +7,30 @@ use Minds\Core\Referrals\Referral;
use Minds\Core\Referrals\Manager;
use Minds\Entities\User;
use Minds\Core\Di\Di;
use Minds\Core\Rewards\Contributions;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class ReferralDelegateSpec extends ObjectBehavior
{
/** @var Manager $manager */
private $manager;
/** @var $contributionsManager */
private $contributionsManager;
/** @var User $user */
private $user;
function let(
Manager $manager,
User $user
User $user,
Contributions\Manager $contributionsManager
)
{
$this->beConstructedWith($manager, $user);
$this->beConstructedWith($manager, $contributionsManager);
$this->manager = $manager;
$this->contributionsManager = $contributionsManager;
$this->user = $user;
}
......@@ -32,8 +39,9 @@ class ReferralDelegateSpec extends ObjectBehavior
$this->shouldHaveType(ReferralDelegate::class);
}
function it_should_tell_manager_to_update_referral(User $user)
function it_should_tell_manager_to_update_referral()
{
$user = new User();
$user->referrer = 123;
$user->guid = 456;
......@@ -50,6 +58,14 @@ class ReferralDelegateSpec extends ObjectBehavior
$this->manager->update($referral)
->shouldBeCalled();
$this->contributionsManager->add(Argument::that(function($contribution) {
return $contribution->getScore() === 50
&& $contribution->getAmount() === 1
&& $contribution->getUser()->guid === 456
&& $contribution->getTimestamp() === strtotime('midnight');
}))
->willReturn(true);
$this->onReferral($user);
}
}
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