Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project
Project
Details
Activity
Releases
Dependency List
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
157
Issues
157
List
Boards
Labels
Service Desk
Milestones
Merge Requests
48
Merge Requests
48
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Packages
Packages
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
a161171d
Commit
a161171d
authored
31 minutes ago
by
Olivia Madrid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(wip): Referrals console
parent
d07a5173
epic/referrals
No related merge requests found
Pipeline
#68846223
canceled with stages
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
281 additions
and
40 deletions
+281
-40
referrals.php
Controllers/api/v2/referrals.php
+20
-1
ManagerSpec.php
Spec/Core/Referrals/ManagerSpec.php
+94
-39
ReferralSpec.php
Spec/Core/Referrals/ReferralSpec.php
+1
-0
RepositorySpec.php
Spec/Core/Referrals/RepositorySpec.php
+166
-0
No files found.
Controllers/api/v2/referrals.php
View file @
a161171d
...
...
@@ -25,7 +25,7 @@ class referrals implements Interfaces\Api
$response
=
[];
$referrer_guid
=
isset
(
$pages
[
0
])
?
$pages
[
0
]
:
Core\Session
::
getLoggedInUser
()
->
guid
;
$limit
=
isset
(
$_GET
[
'limit'
])
?
$_GET
[
'limit'
]
:
3
;
$limit
=
isset
(
$_GET
[
'limit'
])
?
$_GET
[
'limit'
]
:
24
;
$offset
=
isset
(
$_GET
[
'offset'
])
?
$_GET
[
'offset'
]
:
""
;
$manager
=
Di
::
_
()
->
get
(
'Referrals\Manager'
);
...
...
@@ -47,6 +47,25 @@ class referrals implements Interfaces\Api
$response
[
'referrals'
]
=
Factory
::
exportable
(
array_values
(
$referrals
->
toArray
()));
$response
[
'load-next'
]
=
(
string
)
$referrals
->
getPagingToken
();
$tempProspect
=
(
object
)
[
"guid"
=>
"988145006634078224"
,
"verified"
=>
true
,
"username"
=>
"oldprospector"
,
"name"
=>
"oldprospector"
,
"icontime"
=>
"1560987887"
];
$tempRef
=
(
object
)
[
'referrer_guid'
=>
'987892327202689039'
,
'state'
=>
'complete'
,
'score'
=>
10
,
'register_timestamp'
=>
"1560857128000"
,
'join_timestamp'
=>
"1560867128000"
,
'prospect'
=>
$tempProspect
];
array_push
(
$response
[
'referrals'
],
$tempRef
);
return
Factory
::
response
(
$response
);
}
...
...
This diff is collapsed.
Click to expand it.
Spec/Core/Referrals/ManagerSpec.php
View file @
a161171d
...
...
@@ -4,7 +4,10 @@ namespace Spec\Minds\Core\Referrals;
use
Minds\Core\Referrals\Manager
;
use
Minds\Core\Referrals\Repository
;
use
Minds\Entities\User
;
use
Minds\Common\Repository\Response
;
use
Minds\Core\Referrals\Referral
;
use
Minds\Core\EntitiesBuilder
;
use
Minds\Core
;
use
PhpSpec\ObjectBehavior
;
use
Prophecy\Argument
;
...
...
@@ -12,53 +15,105 @@ use Prophecy\Argument;
class
ManagerSpec
extends
ObjectBehavior
{
private
$repository
;
private
$entitiesBuilder
;
function
let
(
Repository
$repository
)
function
let
(
Repository
$repository
,
EntitiesBuilder
$entitiesBuilder
)
{
$this
->
beConstructedWith
(
$repository
);
$this
->
beConstructedWith
(
$repository
,
$entitiesBuilder
);
$this
->
repository
=
$repository
;
$this
->
entitiesBuilder
=
$entitiesBuilder
;
}
function
it_is_initializable
()
{
$this
->
shouldHaveType
(
Manager
::
class
);
}
// function it_should_pass_referral_to_repository()
// {
// $referral = new Referral();
// $referral->setProspectGuid(Core\Session::getLoggedInUserGuid())
// ->setReferrerGuid('1234')
// ->setRegisterTimestamp(time());
// $this->repository->add($referral)
// ->shouldBeCalled();
// $this->add('123')
// ->shouldReturn(true);
// }
}
function
it_should_add_a_referral
()
{
$referral
=
new
Referral
();
$referral
->
setProspectGuid
(
444
)
->
setReferrerGuid
(
456
)
->
setRegisterTimestamp
(
21
);
$this
->
repository
->
add
(
$referral
)
->
shouldBeCalled
();
$this
->
add
(
$referral
)
->
shouldReturn
(
true
);
}
function
it_should_update_a_referral
()
{
$referral
=
new
Referral
();
$referral
->
setProspectGuid
(
555
)
->
setReferrerGuid
(
456
)
->
setJoinTimestamp
(
22
);
$this
->
repository
->
update
(
$referral
)
->
shouldBeCalled
();
$this
->
update
(
$referral
)
->
shouldReturn
(
true
);
}
function
it_should_return_a_list_of_referrals
()
{
$response
=
new
Response
();
$response
[]
=
(
new
Referral
)
->
setReferrerGuid
(
123
)
->
setProspectGuid
(
777
)
->
setRegisterTimestamp
(
11
)
->
setJoinTimestamp
(
12
);
$response
[]
=
(
new
Referral
)
->
setReferrerGuid
(
123
)
->
setProspectGuid
(
888
)
->
setRegisterTimestamp
(
13
)
->
setJoinTimestamp
(
14
);
// '$this' is the class of the spec
// * @method void beConstructedWith(...$arguments)
// * @method void beConstructedThrough($factoryMethod, array $constructorArguments = array())
// * @method void beAnInstanceOf($class)
// *
// * @method void shouldHaveType($type)
// * @method void shouldNotHaveType($type)
// * @method void shouldBeAnInstanceOf($type)
// * @method void shouldNotBeAnInstanceOf($type)
// * @method void shouldImplement($interface)
// * @method void shouldNotImplement($interface)
// *
// * @method Subject\Expectation\DuringCall shouldThrow($exception = null)
// * @method Subject\Expectation\DuringCall shouldNotThrow($exception = null)
// * @method Subject\Expectation\DuringCall shouldTrigger($level = null, $message = null)
// *
// * @method void shouldHaveCount($count)
// * @method void shouldNotHaveCount($count)
// *
// * @method void shouldHaveKeyWithValue($key, $value)
// * @method void shouldNotHaveKeyWithValue($key, $value)
// *
// * @method void shouldHaveKey($key)
// * @method void shouldNotHaveKey($key)
$this
->
repository
->
getList
([
'limit'
=>
12
,
'offset'
=>
''
,
'referrer_guid'
=>
123
,
'hydrate'
=>
true
,
])
->
shouldBeCalled
()
->
willReturn
(
$response
);
$this
->
entitiesBuilder
->
single
(
777
)
->
shouldBeCalled
()
->
willReturn
((
new
User
)
->
set
(
'guid'
,
777
));
$this
->
entitiesBuilder
->
single
(
888
)
->
shouldBeCalled
()
->
willReturn
((
new
User
)
->
set
(
'guid'
,
888
));
$newResponse
=
$this
->
getList
([
'limit'
=>
12
,
'offset'
=>
''
,
'referrer_guid'
=>
123
,
'hydrate'
=>
true
]);
$newResponse
[
0
]
->
getReferrerGuid
()
->
shouldBe
(
123
);
$newResponse
[
0
]
->
getProspect
()
->
getGuid
()
->
shouldBe
(
777
);
$newResponse
[
0
]
->
getRegisterTimestamp
()
->
shouldBe
(
11
);
$newResponse
[
0
]
->
getJoinTimestamp
()
->
shouldBe
(
12
);
$newResponse
[
1
]
->
getReferrerGuid
()
->
shouldBe
(
123
);
$newResponse
[
1
]
->
getProspect
()
->
getGuid
()
->
shouldBe
(
888
);
$newResponse
[
1
]
->
getRegisterTimestamp
()
->
shouldBe
(
13
);
$newResponse
[
1
]
->
getJoinTimestamp
()
->
shouldBe
(
14
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Referrals/ReferralSpec.php
View file @
a161171d
...
...
@@ -3,6 +3,7 @@
namespace
Spec\Minds\Core\Referrals
;
use
Minds\Core\Referrals\Referral
;
use
Minds\Entities\User
;
use
PhpSpec\ObjectBehavior
;
use
Prophecy\Argument
;
...
...
This diff is collapsed.
Click to expand it.
Spec/Core/Referrals/RepositorySpec.php
View file @
a161171d
...
...
@@ -2,14 +2,180 @@
namespace
Spec\Minds\Core\Referrals
;
use
Minds\Common\Repository\Response
;
use
Minds\Core\Referrals\Referral
;
use
Minds\Core\Referrals\Repository
;
use
Minds\Core\Data\Cassandra\Client
;
use
PhpSpec\ObjectBehavior
;
use
Prophecy\Argument
;
class
RepositorySpec
extends
ObjectBehavior
{
private
$client
;
function
let
(
Client
$client
)
{
$this
->
beConstructedWith
(
$client
);
$this
->
client
=
$client
;
}
function
it_is_initializable
()
{
$this
->
shouldHaveType
(
Repository
::
class
);
}
// function it_should_insert_a_new_referral()
// {
// $referral = new Referral();
// $referral->setReferrerGuid(123)
// ->setProspectGuid(456)
// ->setRegisterimestamp(789);
// $this
// ->add($referral)
// ->shouldReturn(true);
// }
function
it_should_add_a_referral
(
Referral
$referral
)
{
$referral
->
getReferrerGuid
()
->
shouldBeCalled
()
->
willReturn
(
123
);
$referral
->
getProspectGuid
()
->
shouldBeCalled
()
->
willReturn
(
456
);
$referral
->
getRegisterTimestamp
()
->
shouldBeCalled
()
->
willReturn
(
78
);
$this
->
client
->
request
(
Argument
::
that
(
function
(
$prepared
)
{
$values
=
$prepared
->
build
()[
'values'
];
$template
=
$prepared
->
build
()[
'string'
];
return
strpos
(
$template
,
'INSERT INTO referrals'
)
!==
FALSE
&&
$values
[
0
]
->
value
()
==
123
&&
$values
[
1
]
->
value
()
==
456
&&
$values
[
2
]
->
value
()
==
78
;
}))
->
shouldBeCalled
()
->
willReturn
(
true
);
$this
->
add
(
$referral
)
->
shouldBe
(
true
);
}
// function it_should_get_a_list_of_referrals()
// {
// $this->client->request(Argument::that(function($prepared) {
// $query = $prepared->build();
// $values = $query['values'];
// return $values[0] === 'reported';
// }))
// ->shouldBeCalled()
// ->willReturn([
// [
// 'user_hashes' => (new Set(Type::text()))
// ->add('hash'),
// 'entity_urn' => 'urn:activity:123',
// 'entity_owner_guid' => new Bigint(456),
// 'reason_code' => new Float_(2),
// 'sub_reason_code' => new Float_(5),
// 'timestamp' => new Timestamp(time() * 1000),
// 'state' => 'reported',
// 'state_changes' => (new Map(Type::text(), Type::timestamp()))
// ->set('reported', time() * 1000),
// 'reports' => (new Set(Type::bigint()))
// ->add(789),
// ],
// [
// 'user_hashes' => (new Set(Type::text()))
// ->add('hash'),
// 'entity_urn' => 'urn:activity:456',
// 'entity_owner_guid' => new Bigint(456),
// 'reason_code' => new Float_(2),
// 'sub_reason_code' => new Float_(5),
// 'timestamp' => new Timestamp(time() * 1000),
// 'state' => 'reported',
// 'state_changes' => (new Map(Type::text(), Type::timestamp()))
// ->set('reported', time() * 1000),
// 'reports' => (new Set(Type::bigint()))
// ->add(789),
// ],
// ]);
// $response = $this->getList([
// 'user' => $user,
// 'juryType' => 'initial',
// ]);
// $response->shouldHaveCount(2);
// }
// function it_should_update_a_referral()
// {
// $referral = new Referral();
// $referral->setReferrerGuid(123)
// ->setProspectGuid(456)
// ->setJoinTimestamp(789);
// $this
// ->update($referral)
// ->shouldReturn(true);
// }
function
it_should_throw_if_no_referrer_guid_during_get_list
()
{
$opts
=
[
'limit'
=>
1000
,
'offset'
=>
2000
,
];
$this
->
shouldThrow
(
new
\Exception
(
'Referrer GUID is required'
))
->
duringGetList
(
$opts
);
}
function
it_should_throw_if_no_prospect_guid_during_add
()
{
$referral
=
new
Referral
();
$referral
->
setReferrerGuid
(
123
);
$referral
->
setRegisterTimestamp
(
456
);
$this
->
shouldThrow
(
new
\Exception
(
'Prospect GUID is required'
))
->
duringAdd
(
$referral
);
}
function
it_should_throw_if_no_referrer_guid_during_add
()
{
$referral
=
new
Referral
();
$referral
->
setProspectGuid
(
123
);
$referral
->
setRegisterTimestamp
(
456
);
$this
->
shouldThrow
(
new
\Exception
(
'Referrer GUID is required'
))
->
duringAdd
(
$referral
);
}
function
it_should_throw_if_no_register_timestamp_during_add
()
{
$referral
=
new
Referral
();
$referral
->
setReferrerGuid
(
123
);
$referral
->
setProspectGuid
(
456
);
$this
->
shouldThrow
(
new
\Exception
(
'Register timestamp is required'
))
->
duringAdd
(
$referral
);
}
function
it_should_throw_if_no_join_timestamp_during_update
()
{
$referral
=
new
Referral
();
$referral
->
setReferrerGuid
(
123
);
$referral
->
setProspectGuid
(
456
);
$this
->
shouldThrow
(
new
\Exception
(
'Join timestamp is required'
))
->
duringUpdate
(
$referral
);
}
}
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