diff --git a/src/Models/Company.php b/src/Models/Company.php index 8ee8677..235328c 100644 --- a/src/Models/Company.php +++ b/src/Models/Company.php @@ -3,6 +3,7 @@ namespace TruckersMP\APIClient\Models; use Carbon\Carbon; +use Illuminate\Support\Collection; use TruckersMP\APIClient\Client; class Company extends Model @@ -110,6 +111,13 @@ class Company extends Model */ protected Game $games; + /** + * The required DLCs of the company. + * + * @var Collection + */ + protected Collection $dlcs; + /** * The number of members in the company. * @@ -190,6 +198,9 @@ public function __construct(Client $client, array $company) $this->getValue('games.ets'), ); + $this->dlcs = (new Collection($this->getValue('dlcs', []))) + ->map(fn (string $name, $id) => new Dlc($id, $name)); + $this->membersCount = $this->getValue('members_count'); $this->recruitment = $this->getValue('recruitment'); $this->language = $this->getValue('language'); @@ -338,6 +349,16 @@ public function getGames(): Game return $this->games; } + /** + * Get the required DLCs of the company. + * + * @return Collection + */ + public function getDlcs(): Collection + { + return $this->dlcs; + } + /** * Get the number of members that are part of the company. * diff --git a/src/Models/CompanyMember.php b/src/Models/CompanyMember.php index aaa2b06..a83b6da 100644 --- a/src/Models/CompanyMember.php +++ b/src/Models/CompanyMember.php @@ -3,6 +3,7 @@ namespace TruckersMP\APIClient\Models; use Carbon\Carbon; +use Illuminate\Support\Collection; use TruckersMP\APIClient\Client; class CompanyMember extends Model @@ -28,6 +29,13 @@ class CompanyMember extends Model */ protected string $username; + /** + * URL to the avatar used on the website. + * + * @var string + */ + protected string $avatar; + /** * The player's Steam ID. * @@ -35,6 +43,13 @@ class CompanyMember extends Model */ protected string $steamId; + /** + * The player's roles within the company. + * + * @var Collection + */ + protected Collection $roles; + /** * The player's role ID within the company. * @@ -77,7 +92,12 @@ public function __construct(Client $client, array $member) $this->id = $this->getValue('id'); $this->userId = $this->getValue('user_id'); $this->username = $this->getValue('username'); + $this->avatar = $this->getValue('avatar'); $this->steamId = (string) $this->getValue('steam_id'); + + $roles = new Collection($this->getValue('roles', [])); + $this->roles = $roles->map(fn (array $role) => new CompanyRole($client, $role)); + $this->roleId = $this->getValue('role_id'); $this->role = $this->getValue('role'); $this->owner = $this->getValue('is_owner', false); @@ -114,6 +134,16 @@ public function getUsername(): string return $this->username; } + /** + * Get the URL of the member's avatar. + * + * @return string + */ + public function getAvatar(): string + { + return $this->avatar; + } + /** * Get the Steam ID of the member. * @@ -124,6 +154,16 @@ public function getSteamId(): string return $this->steamId; } + /** + * Get the roles of the member within the company. + * + * @return Collection + */ + public function getRoles(): Collection + { + return $this->roles; + } + /** * Get the Role ID of the member. * diff --git a/src/Models/CompanyPartnership.php b/src/Models/CompanyPartnership.php new file mode 100644 index 0000000..45b4c22 --- /dev/null +++ b/src/Models/CompanyPartnership.php @@ -0,0 +1,130 @@ +id = $this->getValue('id'); + $this->status = $this->getValue('status'); + $this->createdAt = new Carbon($this->getValue('created_at'), 'UTC'); + $this->updatedAt = new Carbon($this->getValue('updated_at'), 'UTC'); + $this->sender = new Company($client, $this->getValue('sender')); + $this->receiver = new Company($client, $this->getValue('receiver')); + } + + /** + * Get the ID of the partnership. + * + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * Get the status of the partnership. The API only returns accepted partnerships. + * + * @return string + */ + public function getStatus(): string + { + return $this->status; + } + + /** + * Get the date which the partnership was first requested at by the sender. + * + * @return Carbon + */ + public function getCreatedAt(): Carbon + { + return $this->createdAt; + } + + /** + * Get the date which the partnership was last updated at due to the status changing. + * + * @return Carbon + */ + public function getUpdatedAt(): Carbon + { + return $this->updatedAt; + } + + /** + * Get the company that sent the partnership request. + * + * @return Company + */ + public function getSender(): Company + { + return $this->sender; + } + + /** + * Get the company that received the partnership request. + * + * @return Company + */ + public function getReceiver(): Company + { + return $this->receiver; + } +} diff --git a/src/Models/CompanyPartnershipIndex.php b/src/Models/CompanyPartnershipIndex.php new file mode 100644 index 0000000..af00509 --- /dev/null +++ b/src/Models/CompanyPartnershipIndex.php @@ -0,0 +1,58 @@ +partners = (new Collection($response['partners'])) + ->map(fn (array $partnership) => new CompanyPartnership($client, $partnership)); + + $this->pendingRequestsCount = $response['pending_requests_count'] ?? 0; + } + + /** + * Get the collection of accepted company partnerships. + * + * @return Collection + */ + public function getPartners(): Collection + { + return $this->partners; + } + + /** + * Get the number of pending partnership requests involving the company. + * + * @return int + */ + public function getPendingRequestsCount(): int + { + return $this->pendingRequestsCount; + } +} diff --git a/src/Models/CompanyRole.php b/src/Models/CompanyRole.php index d8983b2..6fa26c2 100644 --- a/src/Models/CompanyRole.php +++ b/src/Models/CompanyRole.php @@ -28,6 +28,13 @@ class CompanyRole extends Model */ protected int $order; + /** + * The color of the role. + * + * @var string + */ + protected string $color; + /** * The owner of the company. * @@ -63,6 +70,7 @@ public function __construct(Client $client, array $role) $this->id = $this->getValue('id'); $this->name = $this->getValue('name'); $this->order = $this->getValue('order'); + $this->color = $this->getValue('color'); $this->owner = $this->getValue('owner', false); $this->createdAt = new Carbon($this->getValue('created_at'), 'UTC'); $this->updatedAt = new Carbon($this->getValue('updated_at'), 'UTC'); @@ -98,6 +106,16 @@ public function getOrder(): int return $this->order; } + /** + * Get the color of the role. + * + * @return string + */ + public function getColor(): string + { + return $this->color; + } + /** * Check if the role is the role of the company owner. * diff --git a/src/Models/Event.php b/src/Models/Event.php index 6eef214..8724134 100644 --- a/src/Models/Event.php +++ b/src/Models/Event.php @@ -251,7 +251,8 @@ public function __construct(Client $client, array $event) $this->attendance = new EventAttendance($client, $this->getValue('attendances', [])); - $this->dlcs = (new Collection($this->getValue('dlcs', [])))->mapInto(Dlc::class); + $this->dlcs = (new Collection($this->getValue('dlcs', []))) + ->map(fn (string $name, $id) => new Dlc($id, $name)); $this->createdAt = new Carbon($this->getValue('created_at'), 'UTC'); $this->updatedAt = new Carbon($this->getValue('updated_at'), 'UTC'); diff --git a/src/Models/EventSlot.php b/src/Models/EventSlot.php new file mode 100644 index 0000000..5977c2b --- /dev/null +++ b/src/Models/EventSlot.php @@ -0,0 +1,152 @@ +number = $this->getValue('number'); + $this->name = $this->getValue('name'); + $this->imageUrl = $this->getValue('image_url'); + $this->totalSpaces = $this->getValue('total_spaces'); + $this->available = $this->getValue('available', false); + $this->eligibility = $this->getValue('eligibility'); + + $requesters = new Collection($this->getValue('requesters', [])); + $this->requesters = $requesters->map(fn (array $requester) => new EventSlotRequester($client, $requester)); + } + + /** + * Get the slot number. + * + * @return int + */ + public function getNumber(): int + { + return $this->number; + } + + /** + * Get the slot name. + * + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * Get the URL of the slot image. + * + * @return string + */ + public function getImageUrl(): string + { + return $this->imageUrl; + } + + /** + * Get the total amount of spaces the slot has. + * + * @return int + */ + public function getTotalSpaces(): int + { + return $this->totalSpaces; + } + + /** + * Check if the slot can be booked by companies. + * + * @return bool + */ + public function isAvailable(): bool + { + return $this->available; + } + + /** + * Get which companies are eligible to book the slot. + * + * The value is one of `all`, `partners`, `verified`, or `validated_and_verified`. + * + * @return string + */ + public function getEligibility(): string + { + return $this->eligibility; + } + + /** + * Get the companies that requested the slot. + * + * @return Collection + */ + public function getRequesters(): Collection + { + return $this->requesters; + } +} diff --git a/src/Models/EventSlotRequester.php b/src/Models/EventSlotRequester.php new file mode 100644 index 0000000..a5b77b4 --- /dev/null +++ b/src/Models/EventSlotRequester.php @@ -0,0 +1,95 @@ +id = $this->getValue('id'); + $this->name = $this->getValue('name'); + $this->logoUrl = $this->getValue('logo_url'); + $this->expectedAttendees = $this->getValue('expected_attendees'); + } + + /** + * Get the ID of the company that requested the slot. + * + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * Get the name of the company that requested the slot. + * + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * Get the logo URL of the company that requested the slot. + * + * @return string + */ + public function getLogoUrl(): string + { + return $this->logoUrl; + } + + /** + * Get the expected amount of attendees set by the requesting company. + * + * A value of 0 means the slot was allocated directly. + * + * @return int + */ + public function getExpectedAttendees(): int + { + return $this->expectedAttendees; + } +} diff --git a/src/Models/Player.php b/src/Models/Player.php index 1676505..25d1b0e 100644 --- a/src/Models/Player.php +++ b/src/Models/Player.php @@ -121,11 +121,11 @@ class Player extends Model protected bool $isStaff; /** - * If the user is an upper staff member. + * If the user is part of management within the TruckersMP team. * * @var bool */ - protected bool $isUpperStaff; + protected bool $isManagement; /** * If user is an in-game admin. @@ -237,7 +237,7 @@ public function __construct(Client $client, array $player) $this->awards = $awards->map(fn (array $entry) => new PlayerAward($client, $entry)); $this->isStaff = $this->getValue('permissions.isStaff', false); - $this->isUpperStaff = $this->getValue('permissions.isUpperStaff', false); + $this->isManagement = $this->getValue('permissions.isManagement', false); $this->inGameAdmin = $this->getValue('permissions.isGameAdmin', false); $this->companyId = $this->getValue('vtc.id'); $this->companyName = $this->getValue('vtc.name'); @@ -414,10 +414,23 @@ public function isStaff(): bool * Check if the player is an upper staff member. * * @return bool + * + * @deprecated Renamed by the API to management. + * @see Player::isManagement() */ public function isUpperStaff(): bool { - return $this->isUpperStaff; + return $this->isManagement; + } + + /** + * Check if the player is part of management within the TruckersMP team. + * + * @return bool + */ + public function isManagement(): bool + { + return $this->isManagement; } /** diff --git a/src/Models/Server.php b/src/Models/Server.php index a8d3148..fc0f41b 100644 --- a/src/Models/Server.php +++ b/src/Models/Server.php @@ -160,6 +160,13 @@ class Server extends Model */ protected int $syncDelay; + /** + * The event request currently assigned to the server. + * + * @var ServerEventRequest|null + */ + protected ?ServerEventRequest $eventRequest; + /** * Create a new Server instance. * @@ -194,6 +201,9 @@ public function __construct(Client $client, array $server) $this->event = $this->getValue('event', false); $this->specialEvent = $this->getValue('specialEvent', false); $this->promods = $this->getValue('promods', false); + + $eventRequest = $this->getValue('event_request'); + $this->eventRequest = $eventRequest ? new ServerEventRequest($client, $eventRequest) : null; } /** @@ -416,4 +426,16 @@ public function getSyncDelay(): int { return $this->syncDelay; } + + /** + * Get the event request currently assigned to the server. + * + * Only an event server may have an event request assigned, but it is not guaranteed. + * + * @return ServerEventRequest|null + */ + public function getEventRequest(): ?ServerEventRequest + { + return $this->eventRequest; + } } diff --git a/src/Models/ServerEventRequest.php b/src/Models/ServerEventRequest.php new file mode 100644 index 0000000..bbff783 --- /dev/null +++ b/src/Models/ServerEventRequest.php @@ -0,0 +1,204 @@ +id = $this->getValue('id'); + $this->eventId = $this->getValue('event_id'); + $this->userId = $this->getValue('user_id'); + $this->info = $this->getValue('info'); + $this->rules = $this->getValue('rules'); + $this->startAt = new Carbon($this->getValue('start_at'), 'UTC'); + $this->endAt = new Carbon($this->getValue('end_at'), 'UTC'); + $this->headerImage = $this->getValue('header_image'); + $this->eventLink = $this->getValue('event_link'); + $this->forumLink = $this->getValue('forum_link'); + } + + /** + * Get the ID of the event request. + * + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * Get the ID of the event for which the event request has been made. + * + * Returns null if the event request was created directly. + * + * @return int|null + */ + public function getEventId(): ?int + { + return $this->eventId; + } + + /** + * Get the ID of the user who created the event request. + * + * @return int + */ + public function getUserId(): int + { + return $this->userId; + } + + /** + * Get the information about the event request. + * + * @return string + */ + public function getInfo(): string + { + return $this->info; + } + + /** + * Get the temporary rules for the server. + * + * @return string + */ + public function getRules(): string + { + return $this->rules; + } + + /** + * Get the date and time the server starts at. + * + * @return Carbon + */ + public function getStartAt(): Carbon + { + return $this->startAt; + } + + /** + * Get the date and time the server shuts down at. + * + * @return Carbon + */ + public function getEndAt(): Carbon + { + return $this->endAt; + } + + /** + * Get the event request banner URL. + * + * @return string|null + */ + public function getHeaderImage(): ?string + { + return $this->headerImage; + } + + /** + * Get the URL to the page of the event. + * + * @return string|null + */ + public function getEventLink(): ?string + { + return $this->eventLink; + } + + /** + * Get the URL to the forum topic of the event. + * + * @return string|null + */ + public function getForumLink(): ?string + { + return $this->forumLink; + } +} diff --git a/src/Requests/Company/PartnerIndexRequest.php b/src/Requests/Company/PartnerIndexRequest.php new file mode 100644 index 0000000..3f24ccb --- /dev/null +++ b/src/Requests/Company/PartnerIndexRequest.php @@ -0,0 +1,59 @@ +companyKey = $companyKey; + } + + /** + * Get the endpoint of the request. + * + * @return string + */ + public function getEndpoint(): string + { + return 'vtc/' . $this->companyKey . '/partners'; + } + + /** + * Get the data for the request. + * + * @return CompanyPartnershipIndex + * + * @throws ApiErrorException + * @throws ClientExceptionInterface + */ + public function get(): CompanyPartnershipIndex + { + return new CompanyPartnershipIndex( + $this->client, + $this->send()['response'] + ); + } +} diff --git a/src/Requests/CompanyRequest.php b/src/Requests/CompanyRequest.php index 7837b3c..4a1ae19 100644 --- a/src/Requests/CompanyRequest.php +++ b/src/Requests/CompanyRequest.php @@ -10,6 +10,7 @@ use TruckersMP\APIClient\Requests\Company\EventRequest; use TruckersMP\APIClient\Requests\Company\MemberIndexRequest; use TruckersMP\APIClient\Requests\Company\MemberRequest; +use TruckersMP\APIClient\Requests\Company\PartnerIndexRequest; use TruckersMP\APIClient\Requests\Company\PostIndexRequest; use TruckersMP\APIClient\Requests\Company\PostRequest; use TruckersMP\APIClient\Requests\Company\RoleIndexRequest; @@ -175,4 +176,17 @@ public function event(int $id): EventRequest $id ); } + + /** + * Get the partners of the company. + * + * @return PartnerIndexRequest + */ + public function partners(): PartnerIndexRequest + { + return new PartnerIndexRequest( + $this->client, + $this->key + ); + } } diff --git a/src/Requests/Event/SlotIndexRequest.php b/src/Requests/Event/SlotIndexRequest.php new file mode 100644 index 0000000..2ae7baa --- /dev/null +++ b/src/Requests/Event/SlotIndexRequest.php @@ -0,0 +1,58 @@ +eventId = $id; + } + + /** + * Get the endpoint of the request. + * + * @return string + */ + public function getEndpoint(): string + { + return 'events/' . $this->eventId . '/slots'; + } + + /** + * Get the data for the request. + * + * @return Collection|EventSlot[] + * + * @throws ApiErrorException + * @throws ClientExceptionInterface + */ + public function get(): Collection + { + return (new Collection($this->send()['response'])) + ->map(fn (array $slot) => new EventSlot($this->client, $slot)); + } +} diff --git a/src/Requests/EventRequest.php b/src/Requests/EventRequest.php index 3a4360d..e20ffa2 100644 --- a/src/Requests/EventRequest.php +++ b/src/Requests/EventRequest.php @@ -6,6 +6,7 @@ use TruckersMP\APIClient\Client; use TruckersMP\APIClient\Exceptions\ApiErrorException; use TruckersMP\APIClient\Models\Event; +use TruckersMP\APIClient\Requests\Event\SlotIndexRequest; class EventRequest extends Request { @@ -55,4 +56,17 @@ public function get(): Event $this->send()['response'] ); } + + /** + * Get the slots of the event. + * + * @return SlotIndexRequest + */ + public function slots(): SlotIndexRequest + { + return new SlotIndexRequest( + $this->client, + $this->id, + ); + } } diff --git a/tests/Unit/Models/CompanyMemberTest.php b/tests/Unit/Models/CompanyMemberTest.php index f3d5cc5..ac8b17e 100644 --- a/tests/Unit/Models/CompanyMemberTest.php +++ b/tests/Unit/Models/CompanyMemberTest.php @@ -2,9 +2,11 @@ namespace Tests\Unit\Models; +use Illuminate\Support\Collection; use Tests\TestCase; use Tests\Unit\MockModelData; use TruckersMP\APIClient\Models\CompanyMember; +use TruckersMP\APIClient\Models\CompanyRole; class CompanyMemberTest extends TestCase { @@ -41,12 +43,30 @@ public function testItHasAUser() $this->assertSame('76561198083585955', $this->member->getSteamId()); } + public function testItHasAnAvatar() + { + $this->assertSame('https://static.truckersmp.com/avatarsN/avatar.png', $this->member->getAvatar()); + } + public function testItHasARole() { $this->assertSame(25, $this->member->getRoleId()); $this->assertSame('Role', $this->member->getRole()); } + public function testItHasRoles() + { + $roles = $this->member->getRoles(); + + $this->assertInstanceOf(Collection::class, $roles); + $this->assertCount(1, $roles); + + $role = $roles->first(); + + $this->assertInstanceOf(CompanyRole::class, $role); + $this->assertSame(25, $role->getId()); + } + public function testItHasOwnerPermissions() { $this->assertTrue($this->member->isOwner()); diff --git a/tests/Unit/Models/CompanyPartnershipTest.php b/tests/Unit/Models/CompanyPartnershipTest.php new file mode 100644 index 0000000..82b0915 --- /dev/null +++ b/tests/Unit/Models/CompanyPartnershipTest.php @@ -0,0 +1,70 @@ +getFixtureData('company.partnership.json'); + + $this->partnership = new CompanyPartnership($this->client, $data); + } + + public function testItHasAnId() + { + $this->assertSame(21, $this->partnership->getId()); + } + + public function testItHasAStatus() + { + $this->assertSame('Accepted', $this->partnership->getStatus()); + } + + public function testItHasACreationDate() + { + $this->assertDate('2025-03-08 17:30:06', $this->partnership->getCreatedAt()); + } + + public function testItHasAnUpdateDate() + { + $this->assertDate('2025-03-10 20:39:08', $this->partnership->getUpdatedAt()); + } + + public function testItHasASender() + { + $sender = $this->partnership->getSender(); + + $this->assertInstanceOf(Company::class, $sender); + $this->assertSame(1, $sender->getId()); + $this->assertSame('TruckersMP Developers', $sender->getName()); + } + + public function testItHasAReceiver() + { + $receiver = $this->partnership->getReceiver(); + + $this->assertInstanceOf(Company::class, $receiver); + $this->assertSame(2, $receiver->getId()); + $this->assertSame('TruckersMP Team', $receiver->getName()); + } +} diff --git a/tests/Unit/Models/CompanyRoleTest.php b/tests/Unit/Models/CompanyRoleTest.php index 26fef6c..dc65965 100644 --- a/tests/Unit/Models/CompanyRoleTest.php +++ b/tests/Unit/Models/CompanyRoleTest.php @@ -44,6 +44,11 @@ public function testItHasAnOrder() $this->assertSame(2, $this->role->getOrder()); } + public function testItHasAColor() + { + $this->assertSame('#67a6a8', $this->role->getColor()); + } + public function testItIsAnOwner() { $this->assertTrue($this->role->isOwner()); diff --git a/tests/Unit/Models/CompanyTest.php b/tests/Unit/Models/CompanyTest.php index 2662057..37dd247 100644 --- a/tests/Unit/Models/CompanyTest.php +++ b/tests/Unit/Models/CompanyTest.php @@ -2,9 +2,11 @@ namespace Tests\Unit\Models; +use Illuminate\Support\Collection; use Tests\TestCase; use Tests\Unit\MockModelData; use TruckersMP\APIClient\Models\Company; +use TruckersMP\APIClient\Models\Dlc; use TruckersMP\APIClient\Models\Game; use TruckersMP\APIClient\Models\Social; @@ -110,6 +112,20 @@ public function testItHasGames() $this->assertTrue($games->isEts()); } + public function testItHasDlcs() + { + $dlcs = $this->company->getDlcs(); + + $this->assertInstanceOf(Collection::class, $dlcs); + $this->assertCount(1, $dlcs); + + $dlc = $dlcs->first(); + + $this->assertInstanceOf(Dlc::class, $dlc); + $this->assertSame(304212, $dlc->getId()); + $this->assertSame('Scandinavia', $dlc->getName()); + } + public function testItHasAMemberCount() { $this->assertSame(5, $this->company->getMembersCount()); diff --git a/tests/Unit/Models/EventSlotTest.php b/tests/Unit/Models/EventSlotTest.php new file mode 100644 index 0000000..3a11e1f --- /dev/null +++ b/tests/Unit/Models/EventSlotTest.php @@ -0,0 +1,87 @@ +getFixtureData('event.slot.json'); + + $this->slot = new EventSlot($this->client, $data); + } + + public function testItHasANumber() + { + $this->assertSame(1, $this->slot->getNumber()); + } + + public function testItHasAName() + { + $this->assertSame('Slot A1', $this->slot->getName()); + } + + public function testItHasAnImage() + { + $this->assertSame('https://static.truckersmp.com/images/event/slot/slot.png', $this->slot->getImageUrl()); + } + + public function testItHasTotalSpaces() + { + $this->assertSame(10, $this->slot->getTotalSpaces()); + } + + public function testItIsAvailable() + { + $this->assertTrue($this->slot->isAvailable()); + } + + public function testItHasAnEligibility() + { + $this->assertSame('all', $this->slot->getEligibility()); + } + + public function testItHasRequesters() + { + $requesters = $this->slot->getRequesters(); + + $this->assertInstanceOf(Collection::class, $requesters); + $this->assertCount(2, $requesters); + + $requester = $requesters->first(); + + $this->assertInstanceOf(EventSlotRequester::class, $requester); + $this->assertSame(1, $requester->getId()); + $this->assertSame('TruckersMP Developers', $requester->getName()); + $this->assertSame('https://static.truckersmp.com/images/vtc/logo/logo.png', $requester->getLogoUrl()); + $this->assertSame(8, $requester->getExpectedAttendees()); + } + + public function testItCanHaveADirectlyAllocatedRequester() + { + $requester = $this->slot->getRequesters()->last(); + + $this->assertInstanceOf(EventSlotRequester::class, $requester); + $this->assertSame(0, $requester->getExpectedAttendees()); + } +} diff --git a/tests/Unit/Models/EventTest.php b/tests/Unit/Models/EventTest.php index 593f3d4..d6b156c 100644 --- a/tests/Unit/Models/EventTest.php +++ b/tests/Unit/Models/EventTest.php @@ -5,6 +5,7 @@ use Illuminate\Support\Collection; use Tests\TestCase; use Tests\Unit\MockModelData; +use TruckersMP\APIClient\Models\Dlc; use TruckersMP\APIClient\Models\Event; use TruckersMP\APIClient\Models\EventAttendance; use TruckersMP\APIClient\Models\EventCompany; @@ -179,6 +180,20 @@ public function testItHasAnAttendance() $this->assertCount(1, $attendance->getUnsureUsers()); } + public function testItHasDlcs() + { + $dlcs = $this->event->getDlcs(); + + $this->assertInstanceOf(Collection::class, $dlcs); + $this->assertCount(2, $dlcs); + + $dlc = $dlcs->first(); + + $this->assertInstanceOf(Dlc::class, $dlc); + $this->assertSame(304212, $dlc->getId()); + $this->assertSame('Scandinavia', $dlc->getName()); + } + public function testItHasAnUrl() { $this->assertSame('/events/45-convoy', $this->event->getUrl()); diff --git a/tests/Unit/Models/PlayerTest.php b/tests/Unit/Models/PlayerTest.php index e8d3f87..ee7ffb2 100644 --- a/tests/Unit/Models/PlayerTest.php +++ b/tests/Unit/Models/PlayerTest.php @@ -102,6 +102,7 @@ public function testItHasPatreonInformation() public function testItHasPermissions() { $this->assertTrue($this->player->isStaff()); + $this->assertTrue($this->player->isManagement()); $this->assertTrue($this->player->isUpperStaff()); $this->assertTrue($this->player->isAdmin()); } diff --git a/tests/Unit/Models/ServerEventRequestTest.php b/tests/Unit/Models/ServerEventRequestTest.php new file mode 100644 index 0000000..e7ac67b --- /dev/null +++ b/tests/Unit/Models/ServerEventRequestTest.php @@ -0,0 +1,87 @@ +getFixtureData('server.event.json'); + + $server = new Server($this->client, $data); + + $this->eventRequest = $server->getEventRequest(); + } + + public function testItHasAnId() + { + $this->assertSame(7504, $this->eventRequest->getId()); + } + + public function testItHasAnEventId() + { + $this->assertSame(33198, $this->eventRequest->getEventId()); + } + + public function testItHasAUserId() + { + $this->assertSame(33, $this->eventRequest->getUserId()); + } + + public function testItHasInformation() + { + $this->assertSame('Information about the event request.', $this->eventRequest->getInfo()); + } + + public function testItHasRules() + { + $this->assertSame('Temporary rules for the server.', $this->eventRequest->getRules()); + } + + public function testItHasAStartDate() + { + $this->assertDate('2026-07-14 17:00:00', $this->eventRequest->getStartAt()); + } + + public function testItHasAnEndDate() + { + $this->assertDate('2026-07-14 23:00:00', $this->eventRequest->getEndAt()); + } + + public function testItHasAHeaderImage() + { + $this->assertSame( + 'https://static.truckersmp.com/images/event/cover/cover.png', + $this->eventRequest->getHeaderImage() + ); + } + + public function testItHasAnEventLink() + { + $this->assertSame('https://truckersmp.com/events/33198', $this->eventRequest->getEventLink()); + } + + public function testItDoesNotHaveAForumLink() + { + $this->assertNull($this->eventRequest->getForumLink()); + } +} diff --git a/tests/Unit/Models/ServerTest.php b/tests/Unit/Models/ServerTest.php index 4f13de0..83b26d0 100644 --- a/tests/Unit/Models/ServerTest.php +++ b/tests/Unit/Models/ServerTest.php @@ -134,4 +134,9 @@ public function testItHasASyncDelay() { $this->assertSame(250, $this->server->getSyncDelay()); } + + public function testItDoesNotHaveAnEventRequest() + { + $this->assertNull($this->server->getEventRequest()); + } } diff --git a/tests/Unit/Models/fixtures/company.json b/tests/Unit/Models/fixtures/company.json index 2c7d909..b0cdd4a 100644 --- a/tests/Unit/Models/fixtures/company.json +++ b/tests/Unit/Models/fixtures/company.json @@ -22,6 +22,9 @@ "ats": true, "ets": true }, + "dlcs": { + "304212": "Scandinavia" + }, "members_count": 5, "recruitment": "Close", "language": "English", diff --git a/tests/Unit/Models/fixtures/company.member.json b/tests/Unit/Models/fixtures/company.member.json index 884366b..e2ac126 100644 --- a/tests/Unit/Models/fixtures/company.member.json +++ b/tests/Unit/Models/fixtures/company.member.json @@ -2,7 +2,19 @@ "id": 123, "user_id": 1, "username": "User", + "avatar": "https://static.truckersmp.com/avatarsN/avatar.png", "steam_id": 76561198083585955, + "roles": [ + { + "id": 25, + "name": "Role", + "order": 1, + "color": "#67a6a8", + "owner": true, + "created_at": "2023-01-04 11:35:05", + "updated_at": "2023-01-04 11:35:05" + } + ], "role_id": 25, "role": "Role", "is_owner": true, diff --git a/tests/Unit/Models/fixtures/company.partnership.json b/tests/Unit/Models/fixtures/company.partnership.json new file mode 100644 index 0000000..c269187 --- /dev/null +++ b/tests/Unit/Models/fixtures/company.partnership.json @@ -0,0 +1,71 @@ +{ + "id": 21, + "status": "Accepted", + "created_at": "2025-03-08T17:30:06.000000Z", + "updated_at": "2025-03-10T20:39:08.000000Z", + "sender": { + "id": 1, + "name": "TruckersMP Developers", + "owner_id": 1287455, + "owner_username": "Owner", + "slogan": "$company->create();", + "tag": "TMP-DEV", + "logo": "https://static.truckersmp.com/images/vtc/logo/logo.png", + "cover": "https://static.truckersmp.com/images/vtc/cover/cover.jpeg", + "information": "Information", + "rules": "Rules", + "requirements": "Requirements", + "website": "https://truckersmp.com", + "socials": { + "twitter": "https://twitter.com/truckersmp", + "facebook": "https://www.facebook.com/truckersmpofficial/", + "twitch": "https://www.twitch.tv/truckersmp_official", + "discord": "https://discord.gg/truckersmp", + "youtube": "https://www.youtube.com/c/TruckersMPOfficial/" + }, + "games": { + "ats": true, + "ets": true + }, + "dlcs": { + "304212": "Scandinavia" + }, + "members_count": 5, + "recruitment": "Close", + "language": "English", + "verified": true, + "validated": false, + "created": "2019-07-13 14:26:49" + }, + "receiver": { + "id": 2, + "name": "TruckersMP Team", + "owner_id": 42, + "owner_username": "Owner", + "slogan": "Slogan", + "tag": "TMP", + "logo": "https://static.truckersmp.com/images/vtc/logo/logo.png", + "cover": "https://static.truckersmp.com/images/vtc/cover/cover.jpeg", + "information": "Information", + "rules": "Rules", + "requirements": "Requirements", + "website": null, + "socials": { + "twitter": null, + "facebook": null, + "twitch": null, + "discord": null, + "youtube": null + }, + "games": { + "ats": false, + "ets": true + }, + "members_count": 3, + "recruitment": "Open", + "language": "English", + "verified": false, + "validated": false, + "created": "2019-07-13 15:39:58" + } +} diff --git a/tests/Unit/Models/fixtures/company.role.json b/tests/Unit/Models/fixtures/company.role.json index 8a54735..d1d9ce0 100644 --- a/tests/Unit/Models/fixtures/company.role.json +++ b/tests/Unit/Models/fixtures/company.role.json @@ -2,6 +2,7 @@ "id": 1, "name": "Name", "order": 2, + "color": "#67a6a8", "owner": true, "created_at": "2023-01-04 15:34:05", "updated_at": "2023-01-04 15:34:07" diff --git a/tests/Unit/Models/fixtures/event.slot.json b/tests/Unit/Models/fixtures/event.slot.json new file mode 100644 index 0000000..73c676e --- /dev/null +++ b/tests/Unit/Models/fixtures/event.slot.json @@ -0,0 +1,22 @@ +{ + "number": 1, + "name": "Slot A1", + "image_url": "https://static.truckersmp.com/images/event/slot/slot.png", + "total_spaces": 10, + "available": true, + "eligibility": "all", + "requesters": [ + { + "id": 1, + "name": "TruckersMP Developers", + "logo_url": "https://static.truckersmp.com/images/vtc/logo/logo.png", + "expected_attendees": 8 + }, + { + "id": 2, + "name": "TruckersMP Team", + "logo_url": "https://static.truckersmp.com/images/vtc/logo/logo.png", + "expected_attendees": 0 + } + ] +} diff --git a/tests/Unit/Models/fixtures/player.json b/tests/Unit/Models/fixtures/player.json index 719e878..92cd7a1 100644 --- a/tests/Unit/Models/fixtures/player.json +++ b/tests/Unit/Models/fixtures/player.json @@ -26,7 +26,7 @@ }, "permissions": { "isStaff": true, - "isUpperStaff": true, + "isManagement": true, "isGameAdmin": true, "showDetailedOnWebMaps": false }, diff --git a/tests/Unit/Models/fixtures/server.event.json b/tests/Unit/Models/fixtures/server.event.json new file mode 100644 index 0000000..97f79b7 --- /dev/null +++ b/tests/Unit/Models/fixtures/server.event.json @@ -0,0 +1,36 @@ +{ + "id": 30, + "game": "ETS2", + "ip": "127.0.0.1", + "port": 12345, + "name": "Event Server", + "shortname": "EVENT", + "idprefix": null, + "online": true, + "players": 250, + "queue": 0, + "maxplayers": 500, + "mapid": 12, + "displayorder": 20, + "speedlimiter": 0, + "collisions": true, + "carsforplayers": false, + "policecarsforplayers": false, + "afkenabled": false, + "event": true, + "specialEvent": false, + "promods": false, + "syncdelay": 250, + "event_request": { + "id": 7504, + "event_id": 33198, + "user_id": 33, + "info": "Information about the event request.", + "rules": "Temporary rules for the server.", + "start_at": "2026-07-14 17:00:00", + "end_at": "2026-07-14 23:00:00", + "header_image": "https://static.truckersmp.com/images/event/cover/cover.png", + "event_link": "https://truckersmp.com/events/33198", + "forum_link": null + } +} diff --git a/tests/Unit/Requests/CompanyPartnerRequestTest.php b/tests/Unit/Requests/CompanyPartnerRequestTest.php new file mode 100644 index 0000000..1e09c5d --- /dev/null +++ b/tests/Unit/Requests/CompanyPartnerRequestTest.php @@ -0,0 +1,35 @@ +mockRequest('company.partner.index.json', 'vtc/1/partners'); + + $index = $this->client->company(1)->partners()->get(); + + $this->assertInstanceOf(CompanyPartnershipIndex::class, $index); + $this->assertSame(1, $index->getPendingRequestsCount()); + + $partners = $index->getPartners(); + + $this->assertInstanceOf(Collection::class, $partners); + $this->assertCount(1, $partners); + + $partnership = $partners->first(); + + $this->assertInstanceOf(CompanyPartnership::class, $partnership); + $this->assertSame(1, $partnership->getSender()->getId()); + $this->assertSame(22, $partnership->getReceiver()->getId()); + } +} diff --git a/tests/Unit/Requests/EventRequestTest.php b/tests/Unit/Requests/EventRequestTest.php index 5b55408..79e64aa 100644 --- a/tests/Unit/Requests/EventRequestTest.php +++ b/tests/Unit/Requests/EventRequestTest.php @@ -2,10 +2,12 @@ namespace Tests\Unit\Requests; +use Illuminate\Support\Collection; use Tests\TestCase; use Tests\Unit\MockAPIRequests; use TruckersMP\APIClient\Models\Event; use TruckersMP\APIClient\Models\EventIndex; +use TruckersMP\APIClient\Models\EventSlot; class EventRequestTest extends TestCase { @@ -28,4 +30,16 @@ public function testItCanGetASpecificEvent() $this->assertInstanceOf(Event::class, $event); } + + public function testItCanGetEventSlots() + { + $this->mockRequest('event.slot.index.json', 'events/45/slots'); + + $slots = $this->client->event(45)->slots()->get(); + + $this->assertInstanceOf(Collection::class, $slots); + $this->assertCount(2, $slots); + + $this->assertInstanceOf(EventSlot::class, $slots->first()); + } } diff --git a/tests/Unit/Requests/fixtures/company.ban.json b/tests/Unit/Requests/fixtures/company.ban.json index 725190d..7eedab8 100644 --- a/tests/Unit/Requests/fixtures/company.ban.json +++ b/tests/Unit/Requests/fixtures/company.ban.json @@ -6,7 +6,19 @@ "id": 123, "user_id": 1, "username": "User", + "avatar": "https://static.truckersmp.com/avatarsN/avatar.png", "steam_id": 76561198083585955, + "roles": [ + { + "id": 25, + "name": "Role", + "order": 1, + "color": "#67a6a8", + "owner": true, + "created_at": "2023-01-04 11:35:05", + "updated_at": "2023-01-04 11:35:05" + } + ], "role_id": 25, "role": "Role", "is_owner": true, diff --git a/tests/Unit/Requests/fixtures/company.json b/tests/Unit/Requests/fixtures/company.json index a352851..7a0c89e 100644 --- a/tests/Unit/Requests/fixtures/company.json +++ b/tests/Unit/Requests/fixtures/company.json @@ -24,6 +24,9 @@ "ats": true, "ets": true }, + "dlcs": { + "304212": "Scandinavia" + }, "members_count": 5, "recruitment": "Close", "language": "English", diff --git a/tests/Unit/Requests/fixtures/company.member.index.json b/tests/Unit/Requests/fixtures/company.member.index.json index 3d65ab6..3d97cfb 100644 --- a/tests/Unit/Requests/fixtures/company.member.index.json +++ b/tests/Unit/Requests/fixtures/company.member.index.json @@ -6,7 +6,19 @@ "id": 123, "user_id": 1, "username": "User", + "avatar": "https://static.truckersmp.com/avatarsN/avatar.png", "steam_id": 76561198083585955, + "roles": [ + { + "id": 25, + "name": "Role", + "order": 1, + "color": "#67a6a8", + "owner": true, + "created_at": "2023-01-04 11:35:05", + "updated_at": "2023-01-04 11:35:05" + } + ], "role_id": 25, "role": "Role", "is_owner": true, diff --git a/tests/Unit/Requests/fixtures/company.member.json b/tests/Unit/Requests/fixtures/company.member.json index e98d2de..c1627fc 100644 --- a/tests/Unit/Requests/fixtures/company.member.json +++ b/tests/Unit/Requests/fixtures/company.member.json @@ -4,7 +4,19 @@ "id": 123, "user_id": 1, "username": "User", + "avatar": "https://static.truckersmp.com/avatarsN/avatar.png", "steam_id": 76561198083585955, + "roles": [ + { + "id": 25, + "name": "Role", + "order": 1, + "color": "#67a6a8", + "owner": true, + "created_at": "2023-01-04 11:35:05", + "updated_at": "2023-01-04 11:35:05" + } + ], "role_id": 25, "role": "Role", "is_owner": true, diff --git a/tests/Unit/Requests/fixtures/company.partner.index.json b/tests/Unit/Requests/fixtures/company.partner.index.json new file mode 100644 index 0000000..1860cf6 --- /dev/null +++ b/tests/Unit/Requests/fixtures/company.partner.index.json @@ -0,0 +1,79 @@ +{ + "error": false, + "response": { + "partners": [ + { + "id": 21, + "status": "Accepted", + "created_at": "2025-03-08T17:30:06.000000Z", + "updated_at": "2025-03-10T20:39:08.000000Z", + "sender": { + "id": 1, + "name": "TruckersMP Developers", + "owner_id": 1287455, + "owner_username": "Owner", + "slogan": "$company->create();", + "tag": "TMP-DEV", + "logo": "https://static.truckersmp.com/images/vtc/logo/logo.png", + "cover": "https://static.truckersmp.com/images/vtc/cover/cover.jpeg", + "information": "Information", + "rules": "Rules", + "requirements": "Requirements", + "website": "https://truckersmp.com", + "socials": { + "twitter": "https://twitter.com/truckersmp", + "facebook": "https://www.facebook.com/truckersmpofficial/", + "twitch": "https://www.twitch.tv/truckersmp_official", + "discord": "https://discord.gg/truckersmp", + "youtube": "https://www.youtube.com/c/TruckersMPOfficial/" + }, + "games": { + "ats": true, + "ets": true + }, + "dlcs": { + "304212": "Scandinavia" + }, + "members_count": 5, + "recruitment": "Close", + "language": "English", + "verified": true, + "validated": false, + "created": "2019-07-13 14:26:49" + }, + "receiver": { + "id": 22, + "name": "TruckersMP Team", + "owner_id": 42, + "owner_username": "Owner", + "slogan": "Slogan", + "tag": "TMP", + "logo": "https://static.truckersmp.com/images/vtc/logo/logo.png", + "cover": "https://static.truckersmp.com/images/vtc/cover/cover.jpeg", + "information": "Information", + "rules": "Rules", + "requirements": "Requirements", + "website": null, + "socials": { + "twitter": null, + "facebook": null, + "twitch": null, + "discord": null, + "youtube": null + }, + "games": { + "ats": false, + "ets": true + }, + "members_count": 3, + "recruitment": "Open", + "language": "English", + "verified": false, + "validated": false, + "created": "2019-07-13 15:39:58" + } + } + ], + "pending_requests_count": 1 + } +} diff --git a/tests/Unit/Requests/fixtures/company.role.index.json b/tests/Unit/Requests/fixtures/company.role.index.json index 5aa91f5..e065270 100644 --- a/tests/Unit/Requests/fixtures/company.role.index.json +++ b/tests/Unit/Requests/fixtures/company.role.index.json @@ -6,6 +6,7 @@ "id": 1, "name": "Name", "order": 2, + "color": "#67a6a8", "owner": true, "created_at": "2023-01-04 15:34:05", "updated_at": "2023-01-04 15:34:07" diff --git a/tests/Unit/Requests/fixtures/company.role.json b/tests/Unit/Requests/fixtures/company.role.json index a510b64..0a7d72b 100644 --- a/tests/Unit/Requests/fixtures/company.role.json +++ b/tests/Unit/Requests/fixtures/company.role.json @@ -4,6 +4,7 @@ "id": 1, "name": "Name", "order": 2, + "color": "#67a6a8", "owner": true, "created_at": "2023-01-04 15:34:05", "updated_at": "2023-01-04 15:34:07" diff --git a/tests/Unit/Requests/fixtures/event.slot.index.json b/tests/Unit/Requests/fixtures/event.slot.index.json new file mode 100644 index 0000000..56774e6 --- /dev/null +++ b/tests/Unit/Requests/fixtures/event.slot.index.json @@ -0,0 +1,30 @@ +{ + "error": false, + "response": [ + { + "number": 1, + "name": "Slot A1", + "image_url": "https://static.truckersmp.com/images/event/slot/slot.png", + "total_spaces": 10, + "available": true, + "eligibility": "all", + "requesters": [ + { + "id": 1, + "name": "TruckersMP Developers", + "logo_url": "https://static.truckersmp.com/images/vtc/logo/logo.png", + "expected_attendees": 8 + } + ] + }, + { + "number": 2, + "name": "Slot A2", + "image_url": "https://static.truckersmp.com/images/event/slot/slot.png", + "total_spaces": 5, + "available": false, + "eligibility": "partners", + "requesters": [] + } + ] +} diff --git a/tests/Unit/Requests/fixtures/player.json b/tests/Unit/Requests/fixtures/player.json index cb5f690..0ec524d 100644 --- a/tests/Unit/Requests/fixtures/player.json +++ b/tests/Unit/Requests/fixtures/player.json @@ -29,7 +29,7 @@ }, "permissions": { "isStaff": true, - "isUpperStaff": true, + "isManagement": true, "isGameAdmin": true, "showDetailedOnWebMaps": false },