From 68f4c384cc3bc558c6aa668f5e47202717e9029b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lup=C4=8D=C3=ADk?= Date: Tue, 21 Jan 2025 12:10:40 +0100 Subject: [PATCH] Add a request for events that a company is attending. --- .../Company/EventAttendingRequest.php | 58 +++++++++++++++++++ src/Requests/Company/EventIndexRequest.php | 13 +++++ src/Requests/CompanyRequest.php | 4 +- .../Unit/Requests/CompanyEventRequestTest.php | 20 +++++-- .../fixtures/company.event.attending.json | 56 ++++++++++++++++++ .../fixtures/company.event.index.json | 1 + 6 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 src/Requests/Company/EventAttendingRequest.php create mode 100644 tests/Unit/Requests/fixtures/company.event.attending.json diff --git a/src/Requests/Company/EventAttendingRequest.php b/src/Requests/Company/EventAttendingRequest.php new file mode 100644 index 0000000..6d52ba2 --- /dev/null +++ b/src/Requests/Company/EventAttendingRequest.php @@ -0,0 +1,58 @@ +companyId = $id; + } + + /** + * Get the endpoint of the request. + * + * @return string + */ + public function getEndpoint(): string + { + return 'vtc/' . $this->companyId . '/events/attending'; + } + + /** + * Get the data for the request. + * + * @return Collection|Event[] + * + * @throws ApiErrorException + * @throws ClientExceptionInterface + */ + public function get(): Collection + { + return (new Collection($this->send()['response'])) + ->map(fn (array $event) => new Event($this->client, $event)); + } +} diff --git a/src/Requests/Company/EventIndexRequest.php b/src/Requests/Company/EventIndexRequest.php index 4d96870..e799c26 100644 --- a/src/Requests/Company/EventIndexRequest.php +++ b/src/Requests/Company/EventIndexRequest.php @@ -56,4 +56,17 @@ public function get(): CompanyEventIndex $this->send()['response'] ); } + + /** + * Get all events that the company is attending. + * + * @return EventAttendingRequest + */ + public function attending(): EventAttendingRequest + { + return new EventAttendingRequest( + $this->client, + $this->companyId, + ); + } } diff --git a/src/Requests/CompanyRequest.php b/src/Requests/CompanyRequest.php index b698548..7837b3c 100644 --- a/src/Requests/CompanyRequest.php +++ b/src/Requests/CompanyRequest.php @@ -149,7 +149,7 @@ public function member(int $id): MemberRequest } /** - * Get the events for the company. + * Get the events created by the company. * * @return EventIndexRequest */ @@ -162,7 +162,7 @@ public function events(): EventIndexRequest } /** - * Get the event for the company with the specified ID. + * Get the event created by the company with the specified ID. * * @param int $id * @return EventRequest diff --git a/tests/Unit/Requests/CompanyEventRequestTest.php b/tests/Unit/Requests/CompanyEventRequestTest.php index 1d85a01..6434c39 100644 --- a/tests/Unit/Requests/CompanyEventRequestTest.php +++ b/tests/Unit/Requests/CompanyEventRequestTest.php @@ -14,9 +14,9 @@ class CompanyEventRequestTest extends TestCase public function testItCanGetAllCompanyEvents() { - $this->mockRequest('company.event.index.json', 'vtc/258/events'); + $this->mockRequest('company.event.index.json', 'vtc/22/events'); - $index = $this->client->company(258)->events()->get(); + $index = $this->client->company(22)->events()->get(); $this->assertInstanceOf(CompanyEventIndex::class, $index); @@ -30,10 +30,22 @@ public function testItCanGetAllCompanyEvents() public function testItCanGetASpecificCompanyEvent() { - $this->mockRequest('event.json', 'vtc/258/events/45'); + $this->mockRequest('event.json', 'vtc/22/events/45'); - $event = $this->client->company(258)->event(45)->get(); + $event = $this->client->company(22)->event(45)->get(); $this->assertInstanceOf(Event::class, $event); } + + public function testItCanGetEventsThatACompanyIsAttending() + { + $this->mockRequest('company.event.attending.json', 'vtc/22/events/attending'); + + $events = $this->client->company(22)->events()->attending()->get(); + + $this->assertInstanceOf(Collection::class, $events); + $this->assertCount(1, $events); + + $this->assertInstanceOf(Event::class, $events->first()); + } } diff --git a/tests/Unit/Requests/fixtures/company.event.attending.json b/tests/Unit/Requests/fixtures/company.event.attending.json new file mode 100644 index 0000000..e5d59e5 --- /dev/null +++ b/tests/Unit/Requests/fixtures/company.event.attending.json @@ -0,0 +1,56 @@ +{ + "error": false, + "response": [ + { + "id": 2, + "event_type": { + "key": "convoy", + "name": "Convoy" + }, + "name": "Today's Convoy", + "slug": "2-todays-convoy", + "game": "ETS2", + "server": { + "id": 4, + "name": "Server" + }, + "language": "English", + "departure": { + "location": "Hotel", + "city": "Prague" + }, + "arrive": { + "location": "Quarry", + "city": "Stuttgart" + }, + "start_at": "2023-01-04 17:00:00", + "meetup_at": "2023-01-04 16:00:00", + "banner": "https://static.truckersmp.com/images/event/cover/cover.png", + "map": "https://static.truckersmp.com/images/event/map/map.jpeg", + "description": "", + "rule": null, + "voice_link": null, + "external_link": null, + "featured": "", + "vtc": { + "id": 789, + "name": "Example Logistics" + }, + "user": { + "id": 33, + "username": "Organizer" + }, + "attendances": { + "confirmed": 11, + "unsure": 5, + "vtcs": 4 + }, + "dlcs": { + "304212": "Scandinavia" + }, + "url": "/events/2-todays-convoy", + "created_at": "2022-01-04 17:04:58", + "updated_at": "2022-01-04 17:13:15" + } + ] +} diff --git a/tests/Unit/Requests/fixtures/company.event.index.json b/tests/Unit/Requests/fixtures/company.event.index.json index 859a6b3..1a2687b 100644 --- a/tests/Unit/Requests/fixtures/company.event.index.json +++ b/tests/Unit/Requests/fixtures/company.event.index.json @@ -24,6 +24,7 @@ "city": "Stuttgart" }, "start_at": "2023-01-04 14:32:28", + "meetup_at": "2023-01-04 14:02:28", "banner": "https://static.truckersmp.com/images/event/cover/cover.png", "map": "https://static.truckersmp.com/images/event/map/map.png", "description": "Description",