Skip to content

Commit

Permalink
Add page parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-elios committed Jul 17, 2024
1 parent 8b04646 commit cb57aea
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
11 changes: 8 additions & 3 deletions src/Concerns/Customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
*/
trait Customers
{
public function getCustomers(int $perPage = 100): Response
public function getCustomers(int $perPage = 100, int $page = 1): Response
{
return $this->get('customers', [
'per_page' => $perPage,
'page' => $page,
]);
}

Expand All @@ -30,10 +31,14 @@ public function getCustomer(int $customerId): Response
return $this->get("customers/$customerId");
}

public function getCustomerAttachments(int $customerId, int $perPage = 50): Response
{
public function getCustomerAttachments(
int $customerId,
int $perPage = 50,
int $page = 1
): Response {
return $this->get("customers/$customerId/attachments", [
'per_page' => $perPage,
'page' => $page,
]);
}

Expand Down
8 changes: 6 additions & 2 deletions src/Concerns/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
*/
trait Users
{
public function getUsers(?int $companyId = null, int $perPage = 30): Response
{
public function getUsers(
?int $companyId = null,
int $perPage = 30,
int $page = 1
): Response {
return $this->get('users/minimal', [
'company_id' => $companyId ?? $this->companyId,
'per_page' => $perPage,
'page' => $page,
]);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Facades/RepCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

/**
* @method static \Illuminate\Http\Client\Response getCompanies()
* @method static \Illuminate\Http\Client\Response getCustomers(int $perPage = 100)
* @method static \Illuminate\Http\Client\Response getCustomers(int $perPage = 100, int $page = 1)
* @method static \Illuminate\Http\Client\Response getCustomer(int $customerId)
* @method static \Illuminate\Http\Client\Response getCustomerAttachments(int $customerId, int $perPage = 50)
* @method static \Illuminate\Http\Client\Response getCustomerAttachments(int $customerId, int $perPage = 50, int $page = 1)
* @method static \Illuminate\Http\Client\Response getCustomerStatusLogs(string|int $customerId, \DateTimeInterface|string|null $from = null, \DateTimeInterface|string|null $to = null)
* @method static \Illuminate\Http\Client\Response getCustomerStatuses(\RepCard\Enums\StatusType|null $type = null)
* @method static \Illuminate\Http\Client\Response getLeaderboards(\DateTimeInterface|string|null $from = null, \DateTimeInterface|string|null $to = null)
* @method static \Illuminate\Http\Client\Response getOffices(string|null $search = null)
* @method static \Illuminate\Http\Client\Response getOfficeTeams(int $officeId)
* @method static \Illuminate\Http\Client\Response getUsers(int|null $companyId = null, int $perPage = 30)
* @method static \Illuminate\Http\Client\Response getUsers(int|null $companyId = null, int $perPage = 30, int $page = 1)
* @method static \Illuminate\Http\Client\Response getUser(int $userId)
* @method static \Illuminate\Http\Client\Response getEventUser(int $userId)
* @method static \Illuminate\Http\Client\Response createUser(\RepCard\Http\Requests\UserRequest $request)
Expand Down
23 changes: 9 additions & 14 deletions tests/Facades/RepCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,9 @@ public function test_get_companies(): void

public function test_get_customers(): void
{
$perPage = 100;

RepCard::fake('/customers', [
'per_page' => $perPage,
'per_page' => 100,
'page' => 1,
]);

$this->assertOk(RepCard::getCustomers());
Expand All @@ -105,15 +104,14 @@ public function test_get_customer(): void
public function test_get_customer_attachments(): void
{
$customerId = 1;
$perPage = 50;

RepCard::fake("/customers/$customerId/attachments", [
'per_page' => $perPage,
'per_page' => 50,
'page' => 1,
]);

$this->assertOk(RepCard::getCustomerAttachments(
customerId: $customerId,
perPage: $perPage
customerId: $customerId
));
}

Expand Down Expand Up @@ -206,19 +204,16 @@ public function test_get_office_teams(): void
public function test_get_users(): void
{
$companyId = config('repcard.company_id');
$perPage = 30;

RepCard::fake('/users/minimal', [
RepCard::fake('/users/minimal', $query = [
'company_id' => $companyId,
'per_page' => $perPage,
'per_page' => 30,
'page' => 1,
]);

$this->assertOk(RepCard::getUsers());

RepCard::fake('/users/minimal', [
'company_id' => $companyId,
'per_page' => $perPage,
]);
RepCard::fake('/users/minimal', $query);

$this->assertOk(RepCard::getUsers(
companyId: $companyId
Expand Down

0 comments on commit cb57aea

Please sign in to comment.