Skip to content
Commits on Source (2)
......@@ -70,7 +70,8 @@ class Manager
if ($opts['useElastic']) {
$response = $this->elasticRepository->getList($opts);
if ($this->optStateIsUsedAndValid($opts)) {
// TODO: Check if it is *really* necessary to re fetch the boosts from cassandra ??
if ($this->optStateIsUsedAndValid($opts) && $opts['state'] !== self::OPT_STATEQUERY_APPROVED) {
$opts['guids'] = array_map(function ($boost) {
return $boost->getGuid();
}, $response->toArray());
......@@ -114,7 +115,7 @@ class Manager
protected function optStateIsValid(array $opts): bool
{
return in_array($opts['state'], self::VALID_OPT_STATEQUERY);
return in_array($opts['state'], self::VALID_OPT_STATEQUERY, true);
}
/**
......
......@@ -19,7 +19,7 @@ use Minds\Core\Di\Di;
class ManagerSpec extends ObjectBehavior
{
/** @var CassandraRepository */
private $repository;
private $cassandraRepository;
/** @var ElasticRepository */
private $elasticRepository;
/** @var EntitiesBuilder */
......@@ -28,13 +28,13 @@ class ManagerSpec extends ObjectBehavior
private $guidBuilder;
public function let(
CassandraRepository $repository,
CassandraRepository $cassandraRepository,
ElasticRepository $elasticRepository,
EntitiesBuilder $entitiesBuilder,
GuidBuilder $guidBuilder
) {
$this->beConstructedWith($repository, $elasticRepository, $entitiesBuilder, $guidBuilder);
$this->repository = $repository;
$this->beConstructedWith($cassandraRepository, $elasticRepository, $entitiesBuilder, $guidBuilder);
$this->cassandraRepository = $cassandraRepository;
$this->elasticRepository = $elasticRepository;
$this->entitiesBuilder = $entitiesBuilder;
$this->guidBuilder = $guidBuilder;
......@@ -47,7 +47,7 @@ class ManagerSpec extends ObjectBehavior
public function it_should_return_a_list_of_boosts_to_review()
{
$response = new Response([
$responseObj = new Response([
(new Boost)
->setGuid(1)
->setEntityGuid(123)
......@@ -61,19 +61,19 @@ class ManagerSpec extends ObjectBehavior
]);
$this->elasticRepository->getList([
'state' => 'review',
'state' => Manager::OPT_STATEQUERY_REVIEW,
'useElastic' => true,
])
->shouldBeCalled()
->willReturn($response);
->willReturn($responseObj);
$this->repository->getList([
'state' => 'review',
$this->cassandraRepository->getList([
'state' => Manager::OPT_STATEQUERY_REVIEW,
'useElastic' => true,
'guids' => [1, 2],
])
->shouldBeCalled()
->willReturn($response);
->willReturn($responseObj);
$this->entitiesBuilder->single(123)->shouldBeCalled()->willReturn((new Activity)->set('guid', 123));
$this->entitiesBuilder->single(1)->shouldBeCalled()->willReturn((new User)->set('guid', 1));
......@@ -81,7 +81,7 @@ class ManagerSpec extends ObjectBehavior
$this->entitiesBuilder->single(2)->shouldBeCalled()->willReturn((new User)->set('guid', 2));
$response = $this->getList([
'state' => 'review',
'state' => Manager::OPT_STATEQUERY_REVIEW,
]);
$response[0]->getEntity()->getGuid()->shouldBe(123);
......@@ -95,7 +95,7 @@ class ManagerSpec extends ObjectBehavior
public function it_should_return_a_list_of_boosts_to_deliver()
{
$response = new Response([
$responseObj = new Response([
(new Boost)
->setEntityGuid(123)
->setImpressions(1000)
......@@ -105,12 +105,11 @@ class ManagerSpec extends ObjectBehavior
->setImpressions(100)
->setOwnerGuid(2)
]);
$this->elasticRepository->getList([
'state' => 'approved',
'state' => Manager::OPT_STATEQUERY_APPROVED,
'useElastic' => true,
])
->shouldBeCalled()
->willReturn($response);
])->shouldBeCalled()->willReturn($responseObj);
$this->entitiesBuilder->single(123)->shouldBeCalled()->willReturn((new Activity)->set('guid', 123));
$this->entitiesBuilder->single(1)->shouldBeCalled()->willReturn((new User)->set('guid', 1));
......@@ -118,7 +117,7 @@ class ManagerSpec extends ObjectBehavior
$this->entitiesBuilder->single(2)->shouldBeCalled()->willReturn((new User)->set('guid', 2));
$response = $this->getList([
'state' => 'approved',
'state' => Manager::OPT_STATEQUERY_APPROVED,
'useElastic' => true,
]);
......@@ -144,7 +143,7 @@ class ManagerSpec extends ObjectBehavior
->setOwnerGuid(2)
]);
$this->repository->getList([
$this->cassandraRepository->getList([
'state' => null,
'guids' => [123, 456],
'useElastic' => false,
......@@ -177,7 +176,7 @@ class ManagerSpec extends ObjectBehavior
$boost->getGuid()->shouldbeCalled()->willReturn(null);
$boost->setGuid(1)->shouldBeCalled();
$this->repository->add($boost)->shouldBeCalled();
$this->cassandraRepository->add($boost)->shouldBeCalled();
$this->elasticRepository->add($boost)->shouldBeCalled();
$this->add($boost)->shouldReturn(true);
......@@ -185,7 +184,7 @@ class ManagerSpec extends ObjectBehavior
public function it_should_update_a_boost(Boost $boost)
{
$this->repository->update($boost, ['@timestamp'])->shouldBeCalled();
$this->cassandraRepository->update($boost, ['@timestamp'])->shouldBeCalled();
$this->elasticRepository->update($boost, ['@timestamp'])->shouldBeCalled();
$this->update($boost, ['@timestamp']);
......@@ -210,7 +209,7 @@ class ManagerSpec extends ObjectBehavior
$this->elasticRepository->getList($params)->shouldBeCalled()->willReturn($response);
$response->toArray()->shouldbeCalled()->willReturn([$boost]);
$this->repository->getList(Argument::any())->shouldBeCalled()->willReturn($response);
$this->cassandraRepository->getList(Argument::any())->shouldBeCalled()->willReturn($response);
$boost->getGuid()->shouldBeCalled()->willReturn('9012');
$boost->getType()->shouldBeCalled()->willReturn('newsfeed');
......@@ -250,7 +249,7 @@ class ManagerSpec extends ObjectBehavior
];
$this->elasticRepository->getList($params)->shouldBeCalled()->willReturn($response);
$response->toArray()->shouldbeCalled()->willReturn([$boost]);
$this->repository->getList(Argument::any())->shouldBeCalled()->willReturn($response);
$this->cassandraRepository->getList(Argument::any())->shouldBeCalled()->willReturn($response);
$boost->getGuid()->shouldBeCalled()->willReturn('9012');
$boost->getEntityGuid()->shouldBeCalled()->willReturn('1234');
......@@ -350,7 +349,7 @@ class ManagerSpec extends ObjectBehavior
->shouldBeCalled()
->willReturn(new Response($existingBoosts, ''));
$this->repository->getList(Argument::any())
$this->cassandraRepository->getList(Argument::any())
->shouldBeCalled()
->willReturn(new Response($existingBoosts));
......