Repository navigation
Add venue_name filter to Events API v1 #781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
oliviasculley
wants to merge
9
commits into
hackgvl:develop
Choose a base branch
from
oliviasculley:feat/api-filter-venue-name
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1097dbc
Add venue_name filter to Events API v1
oliviasculley d2b695f
Fix API docs
oliviasculley 807909f
Add venue slug for Events API v1 filtering
oliviasculley ebed0d7
Fix styling
oliviasculley 5cba5e5
Note that Str::slug sanitizes LIKE wildcards on venue_slug
oliviasculley d4c1515
Match imported venues by name or slug
oliviasculley e7ad6e5
Reuse Venue::normalizeSlug in the venue slug backfill
oliviasculley 13b2ab4
Fix styling
oliviasculley 5618d3f
Merge branch 'develop' into feat/api-filter-venue-name
oliviasculley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
irby marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
app-modules/event-importer/tests/Feature/VenueDataTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| <?php | ||
|
|
||
| namespace HackGreenville\EventImporter\Tests\Feature; | ||
|
|
||
| use App\Models\Venue; | ||
| use HackGreenville\EventImporter\Data\VenueData; | ||
| use Tests\DatabaseTestCase; | ||
|
|
||
| class VenueDataTest extends DatabaseTestCase | ||
| { | ||
| public function test_same_name_with_different_coordinates_reuses_the_venue(): void | ||
| { | ||
| $original = Venue::factory()->create([ | ||
| 'name' => 'Fireforge Crafted Beer', | ||
| 'slug' => 'fireforge-crafted-beer', | ||
| 'address' => '1 Main St', | ||
| 'lat' => 34.1, | ||
| 'lng' => -82.1, | ||
| ]); | ||
|
|
||
| $resolved = $this->venueData( | ||
| 'Fireforge Crafted Beer', | ||
| '1 Main Street', | ||
| 34.10001, | ||
| -82.10001, | ||
| )->resolveVenue(); | ||
|
|
||
| $this->assertTrue($original->is($resolved)); | ||
| $this->assertSame('1 Main St', $resolved->fresh()->address); | ||
| $this->assertSame('fireforge-crafted-beer', $resolved->fresh()->slug); | ||
| $this->assertSame(1, Venue::query()->count()); | ||
| } | ||
|
|
||
| public function test_custom_slug_is_reused_when_the_name_matches(): void | ||
| { | ||
| $original = Venue::factory()->create([ | ||
| 'name' => 'Open Works', | ||
| 'slug' => 'openworks', | ||
| 'address' => '101 N Main St', | ||
| ]); | ||
|
|
||
| $resolved = $this->venueData('Open Works', '101 North Main Street')->resolveVenue(); | ||
|
|
||
| $this->assertTrue($original->is($resolved)); | ||
| $this->assertSame('openworks', $resolved->fresh()->slug); | ||
| $this->assertSame('101 N Main St', $resolved->fresh()->address); | ||
| $this->assertSame(1, Venue::query()->count()); | ||
| } | ||
|
|
||
| public function test_slug_match_reuses_a_venue_whose_name_was_edited(): void | ||
| { | ||
| $original = Venue::factory()->create([ | ||
| 'name' => 'Open Works Downtown', | ||
| 'slug' => 'open-works', | ||
| 'address' => '101 N Main St', | ||
| ]); | ||
|
|
||
| $resolved = $this->venueData('Open Works', 'Elsewhere')->resolveVenue(); | ||
|
|
||
| $this->assertTrue($original->is($resolved)); | ||
| $this->assertSame('Open Works Downtown', $resolved->fresh()->name); | ||
| $this->assertSame('101 N Main St', $resolved->fresh()->address); | ||
| } | ||
|
|
||
| public function test_name_match_wins_over_an_older_slug_match(): void | ||
| { | ||
| Venue::factory()->create([ | ||
| 'name' => 'Other Place', | ||
| 'slug' => 'open-works', | ||
| ]); | ||
| $custom = Venue::factory()->create([ | ||
| 'name' => 'Open Works', | ||
| 'slug' => 'openworks', | ||
| ]); | ||
|
|
||
| $resolved = $this->venueData('Open Works')->resolveVenue(); | ||
|
|
||
| $this->assertTrue($custom->is($resolved)); | ||
| $this->assertSame(2, Venue::query()->count()); | ||
| } | ||
|
|
||
| public function test_new_name_creates_one_venue_with_a_slug(): void | ||
| { | ||
| $resolved = $this->venueData('Zen Greenville', '5 Court St')->resolveVenue(); | ||
|
|
||
| $this->assertSame('Zen Greenville', $resolved->name); | ||
| $this->assertSame('zen-greenville', $resolved->slug); | ||
| $this->assertSame('5 Court St', $resolved->address); | ||
| $this->assertSame('Greenville', $resolved->city); | ||
| $this->assertSame('SC', $resolved->state); | ||
| $this->assertSame(1, Venue::query()->count()); | ||
|
|
||
| $again = $this->venueData('Zen Greenville', '500 Court Street', 1.0, 2.0)->resolveVenue(); | ||
|
|
||
| $this->assertTrue($resolved->is($again)); | ||
| $this->assertSame('5 Court St', $again->fresh()->address); | ||
| $this->assertSame(1, Venue::query()->count()); | ||
| } | ||
|
|
||
| public function test_unslugable_names_do_not_share_a_blank_slug(): void | ||
| { | ||
| $first = $this->venueData('!!!')->resolveVenue(); | ||
| $second = $this->venueData('???')->resolveVenue(); | ||
| $repeat = $this->venueData('!!!', 'Different address')->resolveVenue(); | ||
|
|
||
| $this->assertNull($first->slug); | ||
| $this->assertNull($second->slug); | ||
| $this->assertFalse($first->is($second)); | ||
| $this->assertTrue($first->is($repeat)); | ||
| $this->assertSame(2, Venue::query()->count()); | ||
| } | ||
|
|
||
| public function test_soft_deleted_venue_is_not_reused(): void | ||
| { | ||
| $deleted = Venue::factory()->create([ | ||
| 'name' => 'Fireforge Crafted Beer', | ||
| 'slug' => 'fireforge-crafted-beer', | ||
| ]); | ||
| $deleted->delete(); | ||
|
|
||
| $resolved = $this->venueData('Fireforge Crafted Beer')->resolveVenue(); | ||
|
|
||
| $this->assertFalse($deleted->is($resolved)); | ||
| $this->assertSame(1, Venue::query()->count()); | ||
| $this->assertSame(2, Venue::withTrashed()->count()); | ||
| } | ||
|
|
||
| private function venueData( | ||
| string $name, | ||
| string $address = '100 Main St', | ||
| float $lat = 34.8, | ||
| float $lon = -82.4, | ||
| ): VenueData { | ||
| return VenueData::from([ | ||
| 'id' => 'venue-1', | ||
| 'name' => $name, | ||
| 'address' => $address, | ||
| 'city' => 'Greenville', | ||
| 'state' => 'SC', | ||
| 'zip' => '29601', | ||
| 'country' => 'US', | ||
| 'lat' => $lat, | ||
| 'lon' => $lon, | ||
| ]); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.