Skip to content
Open
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
15 changes: 13 additions & 2 deletions app-modules/event-importer/tests/Feature/EventBriteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
use App\Models\Org;
use App\Models\Venue;
use HackGreenville\EventImporter\Console\Commands\ImportEventsCommand;
use HackGreenville\EventImporter\Services\EventBriteHandler;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Http;
use Tests\DatabaseTestCase;
use Tests\AbstractEventHandlerTestCase;

class EventBriteTest extends DatabaseTestCase
class EventBriteTest extends AbstractEventHandlerTestCase
{
protected function setUp(): void
{
Expand Down Expand Up @@ -116,4 +117,14 @@ protected function apiResponse(string $file): string
{
return file_get_contents(__DIR__ . '/../fixtures/eventbrite/' . $file);
}

protected function getEventService(): EventServices
{
return EventServices::EventBrite;
}

protected function getHandlerClass(): string
{
return EventBriteHandler::class;
}
}
14 changes: 12 additions & 2 deletions app-modules/event-importer/tests/Feature/LumaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
use HackGreenville\EventImporter\Services\LumaHandler;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Http;
use Tests\DatabaseTestCase;
use Tests\AbstractEventHandlerTestCase;

class LumaTest extends DatabaseTestCase
class LumaTest extends AbstractEventHandlerTestCase
{
protected function setUp(): void
{
Expand Down Expand Up @@ -126,4 +126,14 @@ protected function apiResponse(string $file): string
{
return file_get_contents(__DIR__ . '/../fixtures/luma/' . $file);
}

protected function getEventService(): EventServices
{
return EventServices::Luma;
}

protected function getHandlerClass(): string
{
return LumaHandler::class;
}
}
28 changes: 15 additions & 13 deletions app-modules/event-importer/tests/Feature/MeetupGraphqlExtTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use HackGreenville\EventImporter\Services\MeetupGraphqlExtHandler;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Http;
use Tests\DatabaseTestCase;
use Tests\AbstractEventHandlerTestCase;

class MeetupGraphqlExtTest extends DatabaseTestCase
class MeetupGraphqlExtTest extends AbstractEventHandlerTestCase
{
protected function setUp(): void
{
Expand All @@ -27,14 +27,6 @@ protected function setUp(): void
config()->set('event-import-handlers.meetup_graphql_member_id', 'bar');
config()->set('event-import-handlers.meetup_graphql_private_key_id', 'abc123');

config()->set('event-import-handlers.handlers', [
EventServices::MeetupGraphql->value => MeetupGraphqlExtHandler::class,
]);

config()->set('event-import-handlers.active_services', [
EventServices::MeetupGraphql->value,
]);

Org::factory()->create([
'service' => EventServices::MeetupGraphql,
'service_api_key' => 'defcon864',
Expand Down Expand Up @@ -163,7 +155,7 @@ public function test_null_group_data_is_not_imported(): void
200
),
'https://api.meetup.com/gql-ext' => Http::response(
$this->apiResponse('responses/groupByUrlName/v2/example-group-null.json'),
$this->apiResponse('responses/groupByUrlName/example-group-null.json'),
200
),
]);
Expand Down Expand Up @@ -223,7 +215,17 @@ public function test_file_path_validation_fails_when_private_key_path_does_not_e

protected function apiResponse(string $file): string
{
return file_get_contents(__DIR__ . '/../fixtures/meetup-graphql/' . $file);
return file_get_contents(__DIR__ . '/../fixtures/meetup-graphql-ext/' . $file);
}

protected function getEventService(): EventServices
{
return EventServices::MeetupGraphql;
}

protected function getHandlerClass(): string
{
return MeetupGraphqlExtHandler::class;
}

private function runImportCommand(): void
Expand Down Expand Up @@ -258,7 +260,7 @@ private function fakeHttpCalls(): void

Http::fake([
'https://api.meetup.com/gql-ext' => Http::response(
$this->apiResponse('responses/groupByUrlName/v2/example-group.json'), // Example response from /gql-ext endpoint
$this->apiResponse('responses/groupByUrlName/example-group.json'), // Example response from /gql-ext endpoint
200
),
]);
Expand Down
19 changes: 13 additions & 6 deletions app-modules/event-importer/tests/Feature/MeetupGraphqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use HackGreenville\EventImporter\Services\MeetupGraphqlHandler;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Http;
use Tests\DatabaseTestCase;
use Tests\AbstractEventHandlerTestCase;

class MeetupGraphqlTest extends DatabaseTestCase
class MeetupGraphqlTest extends AbstractEventHandlerTestCase
{
protected function setUp(): void
{
Expand All @@ -25,9 +25,6 @@ protected function setUp(): void
config()->set('event-import-handlers.meetup_graphql_client_id', 'foo');
config()->set('event-import-handlers.meetup_graphql_member_id', 'bar');
config()->set('event-import-handlers.meetup_graphql_private_key_id', 'abc123');
config()->set('event-import-handlers.handlers', [
EventServices::MeetupGraphql->value => MeetupGraphqlHandler::class,
]);

Org::factory()->create([
'service' => EventServices::MeetupGraphql,
Expand Down Expand Up @@ -196,6 +193,16 @@ protected function apiResponse(string $file): string
return file_get_contents(__DIR__ . '/../fixtures/meetup-graphql/' . $file);
}

protected function getEventService(): EventServices
{
return EventServices::MeetupGraphql;
}

protected function getHandlerClass(): string
{
return MeetupGraphqlHandler::class;
}

private function runImportCommand(): void
{
$this->artisan(ImportEventsCommand::class);
Expand Down Expand Up @@ -228,7 +235,7 @@ private function fakeHttpCalls(): void

Http::fake([
'https://api.meetup.com/gql' => Http::response(
$this->apiResponse('responses/groupByUrlName/v1/example-group.json'), // Example response from /gql-ext endpoint
$this->apiResponse('responses/groupByUrlName/example-group.json'), // Example response from /gql-ext endpoint
200
),
]);
Expand Down
22 changes: 12 additions & 10 deletions app-modules/event-importer/tests/Feature/MeetupRestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,13 @@
use HackGreenville\EventImporter\Services\MeetupRestHandler;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Http;
use Tests\DatabaseTestCase;
use Tests\AbstractEventHandlerTestCase;

class MeetupRestTest extends DatabaseTestCase
class MeetupRestTest extends AbstractEventHandlerTestCase
{
protected function setUp(): void
{
parent::setUp();

config()->set('event-import-handlers.handlers', [
EventServices::MeetupRest->value => MeetupRestHandler::class,
]);

config()->set('event-import-handlers.active_services', [
EventServices::MeetupRest->value
]);
}

public function test_active_meetup_event_is_imported_correctly(): void
Expand Down Expand Up @@ -96,4 +88,14 @@ protected function apiResponse(string $file): string
{
return file_get_contents(__DIR__ . '/../fixtures/meetup-rest/' . $file);
}

protected function getEventService(): EventServices
{
return EventServices::MeetupRest;
}

protected function getHandlerClass(): string
{
return MeetupRestHandler::class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"access_token":"fake_access_token",
"refresh_token":"fake_refresh_token",
"expires_in":3600,
"token_type":"bearer"
}
38 changes: 38 additions & 0 deletions tests/AbstractEventHandlerTestCase.php
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't particularly care for this file's placement under tests/ directory, as I'd rather have it under the app-modules/event-importer/tests/Feature/Concerns directory (for separation of concerns reasons) but I could not get PHPUnit to cooperate with this file unless it was under this directory... So I'm picking and choosing my battles here. 😆

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Tests;

use App\Enums\EventServices;

abstract class AbstractEventHandlerTestCase extends DatabaseTestCase
{
protected function setUp(): void
{
parent::setUp();

$eventService = $this->getEventService();
$handlerClass = $this->getHandlerClass();

// Set the handler mapping
config([
'event-import-handlers.handlers.' . $eventService->value => $handlerClass,
]);

// Set the active service if not already set
$activeServices = config('event-import-handlers.active_services', []);
if ( ! in_array($eventService->value, $activeServices)) {
$activeServices[] = $eventService->value;
config(['event-import-handlers.active_services' => $activeServices]);
}
}

/**
* Get the event service enum for this test class
*/
abstract protected function getEventService(): EventServices;

/**
* Get the handler class for this test
*/
abstract protected function getHandlerClass(): string;
}