-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reajuste estrutura de mocks + suporte ao end-point de club
- Loading branch information
1 parent
c9dafb8
commit 188595a
Showing
32 changed files
with
514 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
namespace Hotmart\Http\Endpoints; | ||
|
||
use Hotmart\Http\Routes; | ||
|
||
class Club extends Endpoint | ||
{ | ||
/** | ||
* @param string $subdomain | ||
* @param array $params | ||
* @return array | ||
*/ | ||
public function modules(string $subdomain, array $params = []) | ||
{ | ||
$params = array_merge(['subdomain' => $subdomain], $params); | ||
|
||
return $this->http->request( | ||
self::GET, | ||
Routes::club()->modules(), | ||
$this->bindQueryParams($params, $this->bindToken()) | ||
); | ||
} | ||
|
||
/** | ||
* @param string $subdomain | ||
* @param string $moduleId | ||
* @param array $params | ||
* @return array | ||
*/ | ||
public function modulePages(string $subdomain, string $moduleId) | ||
{ | ||
$params = [ | ||
'subdomain' => $subdomain, | ||
'module_id' => $moduleId | ||
]; | ||
|
||
return $this->http->request( | ||
self::GET, | ||
Routes::club()->modulePages($moduleId), | ||
$this->bindQueryParams($params, $this->bindToken()) | ||
); | ||
} | ||
|
||
/** | ||
* @param string $subdomain | ||
* @param array $params | ||
* @return array | ||
*/ | ||
public function users(string $subdomain) | ||
{ | ||
$params = [ | ||
'subdomain' => $subdomain, | ||
]; | ||
|
||
return $this->http->request( | ||
self::GET, | ||
Routes::club()->users(), | ||
$this->bindQueryParams($params, $this->bindToken()) | ||
); | ||
} | ||
|
||
/** | ||
* @param string $subdomain | ||
* @param array $params | ||
* @param string $userId | ||
* @return array | ||
*/ | ||
public function userLessons(string $subdomain, string $userId) | ||
{ | ||
$params = [ | ||
'subdomain' => $subdomain, | ||
]; | ||
|
||
return $this->http->request( | ||
self::GET, | ||
Routes::club()->userLessons($userId), | ||
$this->bindQueryParams($params, $this->bindToken()) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
<?php | ||
|
||
namespace Hotmart\Test\Http\Endpoints; | ||
|
||
use GuzzleHttp\Psr7\Response; | ||
use GuzzleHttp\Handler\MockHandler; | ||
use Hotmart\Http\Endpoints\Club; | ||
use Hotmart\Http\Routes; | ||
use Hotmart\Test\BaseTestCase; | ||
|
||
class ClubTest extends BaseTestCase | ||
{ | ||
public function mockProvider() | ||
{ | ||
return [[[ | ||
'modules' => new MockHandler([ | ||
new Response(200, [], self::jsonMock('Authentication')), | ||
new Response(200, [], self::jsonMock('ClubModules')), | ||
]), | ||
'modulePages' => new MockHandler([ | ||
new Response(200, [], self::jsonMock('Authentication')), | ||
new Response(200, [], self::jsonMock('ClubModulePages')), | ||
]), | ||
'users' => new MockHandler([ | ||
new Response(200, [], self::jsonMock('Authentication')), | ||
new Response(200, [], self::jsonMock('ClubUsers')), | ||
]), | ||
'userLessons' => new MockHandler([ | ||
new Response(200, [], self::jsonMock('Authentication')), | ||
new Response(200, [], self::jsonMock('ClubUserLessons')), | ||
]), | ||
]]]; | ||
} | ||
|
||
/** | ||
* @dataProvider mockProvider | ||
*/ | ||
public function test_get_modules($mock) | ||
{ | ||
$container = []; | ||
|
||
$client = self::buildClient($container, $mock['modules']); | ||
$response = $client->club()->modules('SUBDOMAIN', ['is_extra' => true]); | ||
|
||
$this->assertEquals( | ||
Club::GET, | ||
self::getRequestMethod($container[1]) | ||
); | ||
|
||
$this->assertEquals( | ||
Routes::club()->modules(), | ||
self::getRequestUri($container[1]) | ||
); | ||
|
||
$this->assertEquals( | ||
json_decode(self::jsonMock('ClubModules'), true), | ||
$response | ||
); | ||
|
||
$query = self::getQueryString($container[1]); | ||
$this->assertContains('subdomain=SUBDOMAIN', $query); | ||
$this->assertContains('is_extra=1', $query); | ||
} | ||
|
||
/** | ||
* @dataProvider mockProvider | ||
*/ | ||
public function test_get_module_pages($mock) | ||
{ | ||
$container = []; | ||
|
||
$client = self::buildClient($container, $mock['modulePages']); | ||
$response = $client->club()->modulePages('SUBDOMAIN', 'MODULE_ID'); | ||
|
||
$this->assertEquals( | ||
Club::GET, | ||
self::getRequestMethod($container[1]) | ||
); | ||
|
||
$this->assertEquals( | ||
Routes::club()->modulePages('MODULE_ID'), | ||
self::getRequestUri($container[1]) | ||
); | ||
|
||
$this->assertEquals( | ||
json_decode(self::jsonMock('ClubModulePages'), true), | ||
$response | ||
); | ||
|
||
$query = self::getQueryString($container[1]); | ||
$this->assertContains('subdomain=SUBDOMAIN', $query); | ||
$this->assertContains('module_id=MODULE_ID', $query); | ||
} | ||
|
||
/** | ||
* @dataProvider mockProvider | ||
*/ | ||
public function test_get_users($mock) | ||
{ | ||
$container = []; | ||
|
||
$client = self::buildClient($container, $mock['users']); | ||
$response = $client->club()->users('SUBDOMAIN'); | ||
|
||
$this->assertEquals( | ||
Club::GET, | ||
self::getRequestMethod($container[1]) | ||
); | ||
|
||
$this->assertEquals( | ||
Routes::club()->users(), | ||
self::getRequestUri($container[1]) | ||
); | ||
|
||
$this->assertEquals( | ||
json_decode(self::jsonMock('ClubUsers'), true), | ||
$response | ||
); | ||
|
||
$query = self::getQueryString($container[1]); | ||
$this->assertContains('subdomain=SUBDOMAIN', $query); | ||
} | ||
|
||
/** | ||
* @dataProvider mockProvider | ||
*/ | ||
public function test_get_user_lessons($mock) | ||
{ | ||
$container = []; | ||
|
||
$client = self::buildClient($container, $mock['userLessons']); | ||
$response = $client->club()->userLessons('SUBDOMAIN', 'USER_ID'); | ||
|
||
$this->assertEquals( | ||
Club::GET, | ||
self::getRequestMethod($container[1]) | ||
); | ||
|
||
$this->assertEquals( | ||
Routes::club()->userLessons('USER_ID'), | ||
self::getRequestUri($container[1]) | ||
); | ||
|
||
$this->assertEquals( | ||
json_decode(self::jsonMock('ClubUserLessons'), true), | ||
$response | ||
); | ||
|
||
$query = self::getQueryString($container[1]); | ||
$this->assertContains('subdomain=SUBDOMAIN', $query); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
[ | ||
{ | ||
"liberation_days": 100, | ||
"name": "Dripping 100 days", | ||
"total_comments": 0, | ||
"liberation_type": "BY_DAYS", | ||
"page_order": 1, | ||
"days_of_duration": 120, | ||
"has_media": false, | ||
"type": "CONTENT", | ||
"has_duration": true | ||
}, | ||
{ | ||
"name": "Dripping BY_DATE", | ||
"liberation_date": 1585278000000, | ||
"liberation_type": "BY_DATE", | ||
"page_order": 2, | ||
"type": "CONTENT", | ||
"total_comments": 5, | ||
"has_media": false, | ||
"has_duration": false, | ||
"rates": [ | ||
{ | ||
"rate": 3, | ||
"total": 1 | ||
}, | ||
{ | ||
"rate": 5, | ||
"total": 1 | ||
} | ||
] | ||
}, | ||
{ | ||
"page_order": 3, | ||
"type": "ADVERTISEMENT", | ||
"has_media": false, | ||
"name": "Offer product", | ||
"has_duration": false, | ||
"total_comments": 0 | ||
} | ||
] |
Oops, something went wrong.