Commit 32d6fdec authored by Marcelo Rivera's avatar Marcelo Rivera
Browse files

(fix): spec tests and lint

parent b03f0147
Pipeline #117960018 failed with stages
in 2 minutes and 45 seconds
......@@ -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);
......
......@@ -24,9 +24,9 @@ class RepositorySpec extends ObjectBehavior
public function let(Client $cql, ReportsRepository $reportsRepository)
{
$this->beConstructedWith($cql);
$this->beConstructedWith($cql, $reportsRepository);
$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');
......
Supports Markdown
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