Commit 0f12af4c authored by Ben Hayward's avatar Ben Hayward

Updated

1 merge request!347[Sprint/OldfashionedOwl](fix): Subscription feed upgrade #435
Pipeline #84839674 failed with stages
in 13 minutes and 58 seconds
......@@ -49,9 +49,14 @@ class subscribe implements Interfaces\Api
'message' => 'Unable to find '.$type,
]);
}
$response['users'] = Factory::exportable(array_values($users->toArray()));
$response['load-next'] = (string) $users->getPagingToken();
$pagingToken = (string) $users->getPagingToken();
$users = array_filter(Factory::exportable($users->toArray()), function ($user) {
return ($user->enabled != 'no' && $user->banned != 'yes');
});
$response['users'] = $users;
$response['load-next'] = $pagingToken;
return Factory::response($response);
}
......
......@@ -37,4 +37,9 @@ class Custom implements Interfaces\PreparedInterface
{
return $this->opts;
}
public function getTemplate()
{
return $this->template;
}
}
......@@ -73,6 +73,10 @@ class Manager
*/
public function getList($opts)
{
if (!$opts['guid']) {
return [];
}
$opts = array_merge([
'limit' => 12,
'offset' => '',
......@@ -80,9 +84,6 @@ class Manager
'type' => 'subscribers',
], $opts);
if (!$opts['guid']) {
return [];
}
return $this->repository->getList($opts);
}
......
......@@ -43,7 +43,7 @@ class Repository
}
$response = new Response;
if ($opts['type'] === 'subscibers') {
if ($opts['type'] === 'subscribers') {
$statement = "SELECT * FROM friends";
} else {
$statement = "SELECT * FROM friendsof";
......@@ -77,7 +77,7 @@ class Repository
$response->setPagingToken(base64_encode($rows->pagingStateToken()));
$response->setLastPage($rows->isLastPage());
} catch (\Exception $e) {
return $response;
// do nothing.
}
return $response;
......
......@@ -7,6 +7,8 @@ use Minds\Core\Subscriptions\Subscription;
use Minds\Core\Data\Cassandra\Client;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Spec\Minds\Mocks\Cassandra\Rows;
use Minds\Common\Repository\Response;
class RepositorySpec extends ObjectBehavior
{
......@@ -62,4 +64,38 @@ class RepositorySpec extends ObjectBehavior
$newSubscription->isActive()
->shouldBe(false);
}
public function it_should_get_subscribers()
{
$this->client->request(Argument::that(function ($prepared) {
return $prepared->getTemplate() === "SELECT * FROM friends WHERE column1 = ? ALLOW FILTERING";
}))
->shouldBeCalled()
->willReturn(new Rows([
[ 'guid' => 1 ],
[ 'guid' => 2 ],
], 'paging-token'));
$this->getList([
'guid' => '1234567891',
'type' => 'subscribers',
])->shouldImplement(Response::class);
}
public function it_should_get_subscriptions()
{
$this->client->request(Argument::that(function ($prepared) {
return $prepared->getTemplate() === "SELECT * FROM friendsof WHERE column1 = ? ALLOW FILTERING";
}))
->shouldBeCalled()
->willReturn(new Rows([
[ 'guid' => 1 ],
[ 'guid' => 2 ],
], 'paging-token'));
$this->getList([
'guid' => '1234567891',
'type' => 'subscriptions',
])->shouldImplement(Response::class);
}
}
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