Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/Models/EventAttendance.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class EventAttendance extends Model
*/
protected Collection $unsureUsers;

/**
* The confirmed companies.
*
* @var Collection
*/
protected Collection $confirmedCompanies;

/**
* Create a new EventAttendance instance.
*
Expand All @@ -32,10 +39,12 @@ public function __construct(Client $client, array $attendance)
{
parent::__construct($client, $attendance);

$mapAttendee = fn (array $attendee) => new EventAttendee($client, $attendee);
$mapUser = fn (array $attendee) => new EventAttendee($client, $attendee);
$mapCompany = fn (array $attendee) => new EventCompanyAttendee($client, $attendee);

$this->confirmedUsers = (new Collection($this->getValue('confirmed_users', [])))->map($mapAttendee);
$this->unsureUsers = (new Collection($this->getValue('unsure_users', [])))->map($mapAttendee);
$this->confirmedUsers = (new Collection($this->getValue('confirmed_users', [])))->map($mapUser);
$this->unsureUsers = (new Collection($this->getValue('unsure_users', [])))->map($mapUser);
$this->confirmedCompanies = (new Collection($this->getValue('confirmed_vtcs', [])))->map($mapCompany);
}

/**
Expand Down Expand Up @@ -81,4 +90,14 @@ public function getUnsureUsers(): Collection
{
return $this->unsureUsers;
}

/**
* Get the confirmed companies.
*
* @return Collection
*/
public function getConfirmedCompanies(): Collection
{
return $this->confirmedCompanies;
}
}
112 changes: 112 additions & 0 deletions src/Models/EventCompanyAttendee.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

namespace TruckersMP\APIClient\Models;

use Carbon\Carbon;
use TruckersMP\APIClient\Client;

class EventCompanyAttendee extends Model
{
/**
* The attending company's ID.
*
* @var int
*/
protected int $id;

/**
* The attending company's name.
*
* @var string
*/
protected string $name;

/**
* If the attending company is following the event.
*
* @var bool
*/
protected bool $following;

/**
* The date and time the company marked their attendance (UTC).
*
* @var Carbon
*/
protected Carbon $createdAt;

/**
* The date and time the company updated their attendance (UTC).
*
* @var Carbon
*/
protected Carbon $updatedAt;

/**
* Create a new EventCompanyAttendee instance.
*
* @param Client $client
* @param array $attendee
* @return void
*/
public function __construct(Client $client, array $attendee)
{
parent::__construct($client, $attendee);

$this->id = $this->getValue('id');
$this->name = $this->getValue('name');
$this->following = $this->getValue('following', false);
$this->createdAt = new Carbon($this->getValue('created_at'), 'UTC');
$this->updatedAt = new Carbon($this->getValue('updated_at'), 'UTC');
}

/**
* Get the ID of the attending company.
*
* @return int
*/
public function getId(): int
{
return $this->id;
}

/**
* Get the name of the attending company.
*
* @return string
*/
public function getName(): string
{
return $this->name;
}

/**
* Get the event following status of the attending company.
*
* @return bool
*/
public function isFollowing(): bool
{
return $this->following;
}

/**
* Get the date and time the company marked their attendance.
*
* @return Carbon
*/
public function getCreatedAt(): Carbon
{
return $this->createdAt;
}

/**
* Get the date and time the company updated their attendance.
*
* @return Carbon
*/
public function getUpdatedAt(): Carbon
{
return $this->updatedAt;
}
}
11 changes: 11 additions & 0 deletions tests/Unit/Models/EventAttendanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Tests\Unit\MockModelData;
use TruckersMP\APIClient\Models\EventAttendance;
use TruckersMP\APIClient\Models\EventAttendee;
use TruckersMP\APIClient\Models\EventCompanyAttendee;

class EventAttendanceTest extends TestCase
{
Expand Down Expand Up @@ -50,4 +51,14 @@ public function testItHasUnsureUsers()

$this->assertInstanceOf(EventAttendee::class, $users->first());
}

public function testItHasConfirmedCompanies()
{
$companies = $this->attendance->getConfirmedCompanies();

$this->assertInstanceOf(Collection::class, $companies);
$this->assertCount(1, $companies);

$this->assertInstanceOf(EventCompanyAttendee::class, $companies->first());
}
}
2 changes: 1 addition & 1 deletion tests/Unit/Models/EventAttendeeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class EventAttendeeTest extends TestCase
*/
protected function setUp(): void
{
$data = $this->getFixtureData('event.attendee.json');
$data = $this->getFixtureData('event.attendee.user.json');

$this->attendee = new EventAttendee($this->client, $data);
}
Expand Down
56 changes: 56 additions & 0 deletions tests/Unit/Models/EventCompanyAttendeeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Tests\Unit\Models;

use Tests\TestCase;
use Tests\Unit\MockModelData;
use TruckersMP\APIClient\Models\EventCompanyAttendee;

class EventCompanyAttendeeTest extends TestCase
{
use MockModelData;

/**
* An EventCompanyAttendee model instance filled with mocked data.
*
* @var EventCompanyAttendee
*/
private EventCompanyAttendee $attendee;

/**
* This method is called before each test.
*
* @return void
*/
protected function setUp(): void
{
$data = $this->getFixtureData('event.attendee.company.json');

$this->attendee = new EventCompanyAttendee($this->client, $data);
}

public function testItHasAnId()
{
$this->assertSame(2, $this->attendee->getId());
}

public function testItHasAName()
{
$this->assertSame('TruckersMP Team', $this->attendee->getName());
}

public function testItIsNotFollowing()
{
$this->assertFalse($this->attendee->isFollowing());
}

public function testItHasACreationDate()
{
$this->assertDate('2023-02-25 11:01:05', $this->attendee->getCreatedAt());
}

public function testItHasAnUpdateDate()
{
$this->assertDate('2023-02-25 11:02:08', $this->attendee->getUpdatedAt());
}
}
10 changes: 10 additions & 0 deletions tests/Unit/Models/fixtures/event.attendance.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"confirmed": 1,
"unsure": 2,
"vtcs": 1,
"confirmed_users": [
{
"id": 879,
Expand All @@ -25,5 +26,14 @@
"created_at": "2023-01-04 18:59:01",
"updated_at": "2023-01-04 18:59:22"
}
],
"confirmed_vtcs": [
{
"id": 2,
"name": "TruckersMP Team",
"following": false,
"created_at": "2023-02-25 11:01:05",
"updated_at": "2023-02-25 11:02:08"
}
]
}
7 changes: 7 additions & 0 deletions tests/Unit/Models/fixtures/event.attendee.company.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"id": 2,
"name": "TruckersMP Team",
"following": false,
"created_at": "2023-02-25 11:01:05",
"updated_at": "2023-02-25 11:02:08"
}
10 changes: 10 additions & 0 deletions tests/Unit/Models/fixtures/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"attendances": {
"confirmed": 1,
"unsure": 1,
"vtcs": 1,
"confirmed_users": [
{
"id": 879,
Expand All @@ -56,6 +57,15 @@
"created_at": "2023-01-04 14:45:29",
"updated_at": "2023-01-04 14:45:37"
}
],
"confirmed_vtcs": [
{
"id": 2,
"name": "TruckersMP Team",
"following": false,
"created_at": "2023-02-25 11:01:05",
"updated_at": "2023-02-25 11:02:08"
}
]
},
"dlcs": {
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Requests/fixtures/company.event.index.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
},
"attendances": {
"confirmed": 24,
"unsure": 4
"unsure": 4,
"vtcs": 2
},
"dlcs": {
"304212": "Scandinavia",
Expand Down
10 changes: 10 additions & 0 deletions tests/Unit/Requests/fixtures/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"attendances": {
"confirmed": 1,
"unsure": 1,
"vtcs": 1,
"confirmed_users": [
{
"id": 879,
Expand All @@ -58,6 +59,15 @@
"created_at": "2023-01-04 14:45:29",
"updated_at": "2023-01-04 14:45:37"
}
],
"confirmed_vtcs": [
{
"id": 2,
"name": "TruckersMP Team",
"following": false,
"created_at": "2023-02-25 11:01:05",
"updated_at": "2023-02-25 11:02:08"
}
]
},
"dlcs": {
Expand Down