Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project
Project
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
213
Issues
213
List
Boards
Labels
Service Desk
Milestones
Merge Requests
35
Merge Requests
35
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Security & Compliance
Security & Compliance
Dependency List
Packages
Packages
List
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Commits
8cffd4c9
Commit
8cffd4c9
authored
15 minutes ago
by
Emiliano Balbuena
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(wip): Spec tests
parent
1a67287a
epic/minds-pro
1 merge request
!308
WIP: (feat): Minds Pro
Pipeline
#82826899
failed with stages
in 4 minutes and 15 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
461 additions
and
21 deletions
+461
-21
SetupRoutingDelegate.php
Core/Pro/Delegates/SetupRoutingDelegate.php
+3
-2
Domain.php
Core/Pro/Domain.php
+2
-3
ManagerSpec.php
Spec/Core/Pro/Channel/ManagerSpec.php
+127
-0
HydrateSettingsDelegateSpec.php
Spec/Core/Pro/Delegates/HydrateSettingsDelegateSpec.php
+117
-0
InitializeSettingsDelegateSpec.php
Spec/Core/Pro/Delegates/InitializeSettingsDelegateSpec.php
+81
-0
SetupRoutingDelegateSpec.php
Spec/Core/Pro/Delegates/SetupRoutingDelegateSpec.php
+96
-0
DomainSpec.php
Spec/Core/Pro/DomainSpec.php
+34
-15
settings.example.php
settings.example.php
+1
-1
No files found.
Core/Pro/Delegates/SetupRoutingDelegate.php
View file @
8cffd4c9
...
...
@@ -38,7 +38,7 @@ class SetupRoutingDelegate
$userGuid
=
$settings
->
getUserGuid
();
if
(
!
$settings
->
getDomain
())
{
$settings
->
setDomain
(
sprintf
(
"pro-%s.%s"
,
$userGuid
,
$this
->
config
->
get
(
'pro'
)[
'subdomain_
pre
fix'
]
??
'minds.com'
));
$settings
->
setDomain
(
sprintf
(
"pro-%s.%s"
,
$userGuid
,
$this
->
config
->
get
(
'pro'
)[
'subdomain_
suf
fix'
]
??
'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
}
}
}
This diff is collapsed.
Click to expand it.
Core/Pro/Domain.php
View file @
8cffd4c9
...
...
@@ -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
*/
...
...
This diff is collapsed.
Click to expand it.
Spec/Core/Pro/Channel/ManagerSpec.php
0 → 100644
View file @
8cffd4c9
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Pro/Delegates/HydrateSettingsDelegateSpec.php
0 → 100644
View file @
8cffd4c9
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Pro/Delegates/InitializeSettingsDelegateSpec.php
0 → 100644
View file @
8cffd4c9
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Pro/Delegates/SetupRoutingDelegateSpec.php
0 → 100644
View file @
8cffd4c9
<?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
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Pro/DomainSpec.php
View file @
8cffd4c9
...
...
@@ -34,38 +34,57 @@ class DomainSpec extends ObjectBehavior
$this
->
shouldHaveType
(
Domain
::
class
);
}
public
function
it_should_lookup
_for_a_domain
(
Response
$
repository
Response
,
public
function
it_should_lookup
(
Response
$
getList
Response
,
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
(
$
repository
Response
);
$
repository
Response
->
first
()
->
willReturn
(
$
getList
Response
);
$
getList
Response
->
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
$
us
er
User
$
own
er
)
{
$
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'
);
}
}
This diff is collapsed.
Click to expand it.
settings.example.php
View file @
8cffd4c9
...
...
@@ -576,6 +576,6 @@ $CONFIG->set('gitlab', [
$CONFIG
->
set
(
'pro'
,
[
'root_domains'
=>
[
'minds.com'
,
'www.minds.com'
,
'localhost'
],
'subdomain_
pre
fix'
=>
'minds.com'
,
'subdomain_
suf
fix'
=>
'minds.com'
,
'dynamodb_table_name'
=>
'traefik'
,
]);
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment