Commit f9832ac2 authored by Marcelo Rivera's avatar Marcelo Rivera

(fix): spec tests and lint

1 merge request!467When an entity gets reported, save a copy that can't be edited
Pipeline #117968029 failed with stages
in 62 minutes and 51 seconds
<?php
namespace Minds\Core\Reports\Appeals;
use Cassandra;
use Cassandra\Bigint;
use Cassandra\Tinyint;
use Cassandra\Decimal;
use Cassandra\Type;
use Cassandra\Map;
use Cassandra\Timestamp;
use Minds\Core;
use Minds\Core\Di\Di;
use Cassandra\Tinyint;
use Cassandra\Type;
use Minds\Common\Repository\Response;
use Minds\Core\Data;
use Minds\Core\Data\Cassandra\Prepared\Custom as Prepared;
use Minds\Entities;
use Minds\Entities\DenormalizedEntity;
use Minds\Entities\NormalizedEntity;
use Minds\Common\Repository\Response;
use Minds\Core\Di\Di;
use Minds\Core\Reports\Repository as ReportsRepository;
class Repository
......
......@@ -255,7 +255,7 @@ class Repository
isset($row['user_hashes']) ?
$row['user_hashes']->values() : null
)
->setOriginalEntity($row['original_entity'] ? $this->buildFromJson($row['original_entity']) : null);
->setOriginalEntity(isset($row['original_entity']) ? $this->buildFromJson($row['original_entity']) : null);
return $report;
}
......@@ -277,8 +277,9 @@ class Repository
private function isJson($string)
{
if (!is_string($string))
if (!is_string($string)) {
return false;
}
json_decode($string);
return (json_last_error() == JSON_ERROR_NONE);
......
......@@ -26,7 +26,7 @@ class RepositorySpec extends ObjectBehavior
{
$this->beConstructedWith($cql);
$this->cql = $cql;
//$this->reportsRepository = $reportsRepository;
$this->reportsRepository = $reportsRepository;
}
public function it_is_initializable()
......@@ -149,11 +149,11 @@ class RepositorySpec extends ObjectBehavior
$appeal->getReport()
->shouldBeCalled()
->willReturn($report);
$appeal->getNote()
->shouldBeCalled()
->willReturn('Should not be reported because this is a test');
$this->add($appeal)
->shouldBe(true);
}
......
......@@ -6,6 +6,7 @@ use Minds\Core\Reports\UserReports\Repository;
use Minds\Core\Reports\UserReports\UserReport;
use Minds\Core\Reports\Report;
use Minds\Core\Data\Cassandra\Client;
use Minds\Entities\Activity;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
......@@ -24,7 +25,7 @@ class RepositorySpec extends ObjectBehavior
$this->shouldHaveType(Repository::class);
}
public function it_should_add_a_report(UserReport $userReport)
public function it_should_add_a_report(UserReport $userReport, Activity $activity)
{
$ts = (int) microtime(true);
$this->cql->request(Argument::that(function ($prepared) use ($ts) {
......@@ -32,11 +33,12 @@ class RepositorySpec extends ObjectBehavior
$values = $query['values'];
return $values[0]->values()[0]->value() == 456
&& $values[2]->values()[0]->value() == 'hash'
&& $values[3] === 'urn:activity:123'
&& $values[4]->value() == 2
&& $values[5]->value() == 4
&& $values[6]->time() == $ts;
&& $values[2] == "{}"
&& $values[3]->values()[0] == 'hash'
&& $values[4] === 'urn:activity:123'
&& $values[5]->value() == 2
&& $values[6]->value() == 4
&& $values[7]->time() == $ts;
}))
->shouldBeCalled()
->willReturn(true);
......@@ -45,16 +47,18 @@ class RepositorySpec extends ObjectBehavior
->shouldBeCalled()
->willReturn(
(new Report)
->setEntityUrn("urn:activity:123")
->setTimestamp($ts)
->setReasonCode(2)
->setSubReasonCode(4)
->setEntityUrn("urn:activity:123")
->setEntity($activity)
->setEntityOwnerGuid(1)
->setTimestamp($ts)
->setReasonCode(2)
->setSubReasonCode(4)
);
$userReport->getReporterGuid()
->shouldBeCalled()
->willReturn(456);
$userReport->getReporterHash()
->shouldBeCalled()
->willReturn('hash');
......
Please register or to comment