Commit 8cffd4c9 authored by Emiliano Balbuena's avatar Emiliano Balbuena

(wip): Spec tests

1 merge request!308WIP: (feat): Minds Pro
Pipeline #82826899 failed with stages
in 4 minutes and 15 seconds
......@@ -38,7 +38,7 @@ class SetupRoutingDelegate
$userGuid = $settings->getUserGuid();
if (!$settings->getDomain()) {
$settings->setDomain(sprintf("pro-%s.%s", $userGuid, $this->config->get('pro')['subdomain_prefix'] ?? 'minds.com'));
$settings->setDomain(sprintf("pro-%s.%s", $userGuid, $this->config->get('pro')['subdomain_suffix'] ?? 'minds.com'));
}
$success = $this->edgeRouter
......@@ -46,7 +46,8 @@ class SetupRoutingDelegate
->putEndpoint($settings);
if (!$success) {
// TODO: Issue a warning based on $success
error_log("[MindsPro] Cannot setup endpoint.");
// TODO: Implement user-facing warning
}
}
}
......@@ -44,15 +44,14 @@ class Domain
return null;
}
$settings = $this->repository->getList([
return $this->repository->getList([
'domain' => $domain,
])->first();
return $settings;
}
/**
* @param Settings $settings
* @param User|null $owner
* @return string
* @throws Exception
*/
......
<?php
namespace Spec\Minds\Core\Pro\Channel;
use Minds\Common\Repository\Response;
use Minds\Core\Data\cache\abstractCacher;
use Minds\Core\Feeds\Top\Manager as TopManager;
use Minds\Core\Pro\Channel\Manager;
use Minds\Core\Pro\Repository;
use Minds\Core\Pro\Settings;
use Minds\Entities\User;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class ManagerSpec extends ObjectBehavior
{
/** @var Repository */
protected $repository;
/** @var TopManager */
protected $top;
/** @var abstractCacher */
protected $cache;
public function let(
Repository $repository,
TopManager $top,
abstractCacher $cache
) {
$this->repository = $repository;
$this->top = $top;
$this->cache = $cache;
$this->beConstructedWith($repository, $top, $cache);
}
public function it_is_initializable()
{
$this->shouldHaveType(Manager::class);
}
public function it_should_get_all_categories_content(
User $user,
Response $getListResponse,
Response $topGetListResponse1,
Response $topGetListResponse2Top,
Response $topGetListResponse2Latest,
Settings $settings
) {
$user->get('guid')
->shouldBeCalled()
->willReturn(1000);
$this->repository->getList([
'user_guid' => 1000
])
->shouldBeCalled()
->willReturn($getListResponse);
$getListResponse->first()
->shouldBeCalled()
->willReturn($settings);
$this->cache->get(Argument::containingString('::1000'))
->shouldBeCalled()
->willReturn(null);
$settings->getTagList()
->shouldBeCalled()
->willReturn([
['tag' => 'test1', 'label' => 'Test 1'],
['tag' => 'test2', 'label' => 'Test 2'],
]);
$this->top->getList(Argument::that(function (array $opts) {
return $opts['algorithm'] === 'top' && $opts['hashtags'] === ['test1'];
}))
->shouldBeCalled()
->willReturn($topGetListResponse1);
$topGetListResponse1->toArray()
->shouldBeCalled()
->willReturn([5000, 5001, 5002]);
$this->top->getList(Argument::that(function (array $opts) {
return $opts['algorithm'] === 'top' && $opts['hashtags'] === ['test2'];
}))
->shouldBeCalled()
->willReturn($topGetListResponse2Top);
$topGetListResponse2Top->toArray()
->shouldBeCalled()
->willReturn([]);
$this->top->getList(Argument::that(function (array $opts) {
return $opts['algorithm'] === 'latest' && $opts['hashtags'] === ['test2'];
}))
->shouldBeCalled()
->willReturn($topGetListResponse2Latest);
$topGetListResponse2Latest->toArray()
->shouldBeCalled()
->willReturn([5100, 5101, 5102]);
$output = [
[
'tag' => ['tag' => 'test1', 'label' => 'Test 1'],
'content' => [5000, 5001, 5002],
],
[
'tag' => ['tag' => 'test2', 'label' => 'Test 2'],
'content' => [5100, 5101, 5102],
],
];
$this->cache->set(Argument::containingString('::1000'), $output, Argument::type('int'))
->shouldBeCalled()
->willReturn(true);
$this
->setUser($user)
->getAllCategoriesContent()
->shouldReturn($output);
}
}
<?php
namespace Spec\Minds\Core\Pro\Delegates;
use Exception;
use Minds\Core\Config;
use Minds\Core\EntitiesBuilder;
use Minds\Core\Pro\Delegates\HydrateSettingsDelegate;
use Minds\Core\Pro\Settings;
use Minds\Entities\Activity;
use Minds\Entities\Object\Carousel;
use Minds\Entities\User;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class HydrateSettingsDelegateSpec extends ObjectBehavior
{
/** @var EntitiesBuilder */
protected $entitiesBuilder;
/** @var Config */
protected $config;
public function let(
EntitiesBuilder $entitiesBuilder,
Config $config
) {
$this->entitiesBuilder = $entitiesBuilder;
$this->config = $config;
$this->beConstructedWith($entitiesBuilder, $config);
}
public function it_is_initializable()
{
$this->shouldHaveType(HydrateSettingsDelegate::class);
}
public function it_should_hydrate_settings_on_get(
User $user,
Settings $settings,
Carousel $carousel,
Activity $activity1,
Activity $activity2
) {
$settings->getLogoGuid()
->shouldBeCalled()
->willReturn(7500);
$this->config->get('cdn_url')
->shouldBeCalled()
->willReturn('http://phpspec.test/');
$settings->setLogoImage('http://phpspec.test/fs/v1/thumbnail/7500/master')
->shouldBeCalled()
->willReturn($settings);
$user->get('guid')
->shouldBeCalled()
->willReturn(1000);
$this->entitiesBuilder->get([
'subtype' => 'carousel',
'owner_guid' => '1000'
])
->shouldBeCalled()
->willReturn([ $carousel ]);
$carousel->get('guid')
->shouldBeCalled()
->willReturn(9500);
$carousel->get('last_updated')
->shouldBeCalled()
->willReturn(9999999);
$settings->setBackgroundImage('http://phpspec.test/fs/v1/banners/9500/fat/9999999')
->shouldBeCalled()
->willReturn($settings);
$user->getPinnedPosts()
->shouldBeCalled()
->willReturn([5000, 5001]);
$this->entitiesBuilder->get(['guids' => ['5000', '5001']])
->shouldBeCalled()
->willReturn([ $activity1, $activity2 ]);
$activity1->get('time_created')
->shouldBeCalled()
->willReturn(10000010);
$activity1->get('entity_guid')
->shouldBeCalled()
->willReturn(7400);
$activity2->get('time_created')
->shouldBeCalled()
->willReturn(10000090);
$activity2->get('guid')
->shouldBeCalled()
->willReturn(5001);
$activity2->get('entity_guid')
->shouldBeCalled()
->willReturn(null);
$settings->setFeaturedContent([5001, 7400])
->shouldBeCalled()
->willReturn($settings);
$this
->shouldNotThrow(Exception::class)
->duringOnGet($user, $settings);
}
}
<?php
namespace Spec\Minds\Core\Pro\Delegates;
use Exception;
use Minds\Common\Repository\Response;
use Minds\Core\Pro\Delegates\InitializeSettingsDelegate;
use Minds\Core\Pro\Delegates\SetupRoutingDelegate;
use Minds\Core\Pro\Repository;
use Minds\Core\Pro\Settings;
use Minds\Entities\User;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class InitializeSettingsDelegateSpec extends ObjectBehavior
{
/** @var Repository */
protected $repository;
/** @var SetupRoutingDelegate */
protected $setupRoutingDelegate;
public function let(
Repository $repository,
SetupRoutingDelegate $setupRoutingDelegate
) {
$this->repository = $repository;
$this->setupRoutingDelegate = $setupRoutingDelegate;
$this->beConstructedWith($repository, $setupRoutingDelegate);
}
public function it_is_initializable()
{
$this->shouldHaveType(InitializeSettingsDelegate::class);
}
public function it_should_initialize_settings_on_enable(
User $user,
Response $getListResponse,
Settings $settings
) {
$user->get('guid')
->shouldBeCalled()
->willReturn(1000);
$user->get('name')
->shouldBeCalled()
->willReturn('PHPSpec');
$this->repository->getList([
'user_guid' => 1000
])
->shouldBeCalled()
->willReturn($getListResponse);
$getListResponse->first()
->shouldBeCalled()
->willReturn($settings);
$settings->getTitle()
->shouldBeCalled()
->willReturn('');
$settings->setTitle('PHPSpec')
->shouldBeCalled()
->willReturn($settings);
$this->setupRoutingDelegate->onUpdate($settings)
->shouldBeCalled()
->willReturn(null);
$this->repository->add($settings)
->shouldBeCalled()
->willReturn(true);
$this
->shouldNotThrow(Exception::class)
->duringOnEnable($user);
}
}
<?php
namespace Spec\Minds\Core\Pro\Delegates;
use Exception;
use Minds\Core\Config;
use Minds\Core\Pro\Delegates\SetupRoutingDelegate;
use Minds\Core\Pro\Domain\EdgeRouters\EdgeRouterInterface;
use Minds\Core\Pro\Settings;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class SetupRoutingDelegateSpec extends ObjectBehavior
{
/** @var Config */
protected $config;
/** @var EdgeRouterInterface */
protected $edgeRouter;
public function let(
Config $config,
EdgeRouterInterface $edgeRouter
) {
$this->config = $config;
$this->edgeRouter = $edgeRouter;
$this->beConstructedWith($config, $edgeRouter);
}
public function it_is_initializable()
{
$this->shouldHaveType(SetupRoutingDelegate::class);
}
public function it_should_setup_routing_on_update_with_default_subdomain(
Settings $settings
) {
$settings->getUserGuid()
->shouldBeCalled()
->willReturn(1000);
$settings->getDomain()
->shouldBeCalled()
->willReturn(null);
$this->config->get('pro')
->shouldBeCalled()
->willReturn([
'subdomain_suffix' => 'phpspec.test',
]);
$settings->setDomain('pro-1000.phpspec.test')
->shouldBeCalled()
->willReturn($settings);
$this->edgeRouter->initialize()
->shouldBeCalled()
->willReturn($this->edgeRouter);
$this->edgeRouter->putEndpoint($settings)
->shouldBeCalled()
->willReturn(true);
$this
->shouldNotThrow(Exception::class)
->duringOnUpdate($settings);
}
public function it_should_setup_routing_on_update_with_a_custom_domain(
Settings $settings
) {
$settings->getUserGuid()
->shouldBeCalled()
->willReturn(1000);
$settings->getDomain()
->shouldBeCalled()
->willReturn('routing-test.phpspec.test');
$settings->setDomain(Argument::cetera())
->shouldNotBeCalled();
$this->edgeRouter->initialize()
->shouldBeCalled()
->willReturn($this->edgeRouter);
$this->edgeRouter->putEndpoint($settings)
->shouldBeCalled()
->willReturn(true);
$this
->shouldNotThrow(Exception::class)
->duringOnUpdate($settings);
}
}
......@@ -34,38 +34,57 @@ class DomainSpec extends ObjectBehavior
$this->shouldHaveType(Domain::class);
}
public function it_should_lookup_for_a_domain(
Response $repositoryResponse,
public function it_should_lookup(
Response $getListResponse,
Settings $settings
) {
$this->config->get('root_domains')
$this->config->get('pro')
->shouldBeCalled()
->willReturn(['minds.com']);
->willReturn([
'root_domains' => ['phpspec.test']
]);
$this->repository->getList([
'domain' => 'minds.test',
'domain' => 'phpspec-test.com'
])
->shouldBeCalled()
->willReturn($repositoryResponse);
$repositoryResponse->first()
->willReturn($getListResponse);
$getListResponse->first()
->shouldBeCalled()
->willReturn($settings);
$this
->lookup('minds.test')
->lookup('phpspec-test.com')
->shouldReturn($settings);
}
public function it_should_get_an_icon(
public function it_should_not_lookup_if_root_domain()
{
$this->config->get('pro')
->shouldBeCalled()
->willReturn([
'root_domains' => ['phpspec.test']
]);
$this->repository->getList(Argument::cetera())
->shouldNotBeCalled();
$this
->lookup('phpspec.test')
->shouldReturn(null);
}
public function it_should_get_icon(
Settings $settings,
User $user
User $owner
) {
$user->getIconURL('large')
$owner->getIconURL(Argument::type('string'))
->shouldBeCalled()
->willReturn('/1000/large');
->willReturn('http://phpspec/icon');
$this->getIcon($settings, $user)
->shouldReturn('/1000/large');
$this
->getIcon($settings, $owner)
->shouldReturn('http://phpspec/icon');
}
}
......@@ -576,6 +576,6 @@ $CONFIG->set('gitlab', [
$CONFIG->set('pro', [
'root_domains' => ['minds.com', 'www.minds.com', 'localhost'],
'subdomain_prefix' => 'minds.com',
'subdomain_suffix' => 'minds.com',
'dynamodb_table_name' => 'traefik',
]);
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