From acbb04f5a9dd81ced6fa6b7db5152e02d70b36d0 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sat, 26 Jan 2019 15:38:18 +0000 Subject: [PATCH] Fix ownyourswarm checkins (closes issue #93) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Squashed commit of the following: commit b9716fc406664a58ce506aa419f978853d698eff Author: Jonny Barnes Date: Sat Jan 26 15:30:43 2019 +0000 Location and checkin aren’t part of the properties anymore --- app/Services/NoteService.php | 28 ++-- tests/Feature/MicropubControllerTest.php | 16 +-- tests/Feature/SwarmTest.php | 166 +++++++++++++++-------- 3 files changed, 130 insertions(+), 80 deletions(-) diff --git a/app/Services/NoteService.php b/app/Services/NoteService.php index 476c5b2b..fc589a75 100644 --- a/app/Services/NoteService.php +++ b/app/Services/NoteService.php @@ -139,18 +139,7 @@ class NoteService */ private function getCheckin(array $request): ?Place { - $location = array_get($request, 'properties.location.0'); - if (array_get($location, 'type.0') === 'h-card') { - try { - $place = resolve(PlaceService::class)->createPlaceFromCheckin( - $location - ); - } catch (\InvalidArgumentException $e) { - return null; - } - - return $place; - } + $location = array_get($request, 'location'); if (is_string($location) && starts_with($location, config('app.url'))) { return Place::where( 'slug', @@ -162,10 +151,21 @@ class NoteService ) )->first(); } - if (array_get($request, 'properties.checkin')) { + if (array_get($request, 'checkin')) { try { $place = resolve(PlaceService::class)->createPlaceFromCheckin( - array_get($request, 'properties.checkin.0') + array_get($request, 'checkin') + ); + } catch (\InvalidArgumentException $e) { + return null; + } + + return $place; + } + if (array_get($location, 'type.0') === 'h-card') { + try { + $place = resolve(PlaceService::class)->createPlaceFromCheckin( + $location ); } catch (\InvalidArgumentException $e) { return null; diff --git a/tests/Feature/MicropubControllerTest.php b/tests/Feature/MicropubControllerTest.php index 2c138e10..27f0757f 100644 --- a/tests/Feature/MicropubControllerTest.php +++ b/tests/Feature/MicropubControllerTest.php @@ -353,14 +353,14 @@ class MicropubControllerTest extends TestCase 'type' => ['h-entry'], 'properties' => [ 'content' => [$note], - 'location' => [[ - 'type' => ['h-card'], - 'properties' => [ - 'name' => ['Awesome Venue'], - 'latitude' => ['1.23'], - 'longitude' => ['4.56'], - ], - ]], + ], + 'location' => [ + 'type' => ['h-card'], + 'properties' => [ + 'name' => ['Awesome Venue'], + 'latitude' => ['1.23'], + 'longitude' => ['4.56'], + ], ], ], ['HTTP_Authorization' => 'Bearer ' . $this->getToken()] diff --git a/tests/Feature/SwarmTest.php b/tests/Feature/SwarmTest.php index 8f92c4f3..ad4c5530 100644 --- a/tests/Feature/SwarmTest.php +++ b/tests/Feature/SwarmTest.php @@ -26,15 +26,15 @@ class SwarmTest extends TestCase 'value' => 'My first #checkin using Example Product', 'html' => 'My first #checkin using Example Product', ]], - 'checkin' => [[ - 'type' => ['h-card'], - 'properties' => [ - 'name' => ['Awesome Venue'], - 'url' => ['https://foursquare.com/v/123456'], - 'latitude' => ['1.23'], - 'longitude' => ['4.56'], - ], - ]], + ], + 'checkin' => [ + 'type' => ['h-card'], + 'properties' => [ + 'name' => ['Awesome Venue'], + 'url' => ['https://foursquare.com/v/123456'], + 'latitude' => ['1.23'], + 'longitude' => ['4.56'], + ], ], ], ['HTTP_Authorization' => 'Bearer ' . $this->getToken()] @@ -64,15 +64,15 @@ class SwarmTest extends TestCase 'value' => 'My first #checkin using Example Product', 'html' => 'My first #checkin using Example Product', ]], - 'checkin' => [[ - 'type' => ['h-card'], - 'properties' => [ - 'name' => ['Awesome Venue'], - 'url' => ['https://www.openstreetmap.org/way/123456'], - 'latitude' => ['1.23'], - 'longitude' => ['4.56'], - ], - ]], + ], + 'checkin' => [ + 'type' => ['h-card'], + 'properties' => [ + 'name' => ['Awesome Venue'], + 'url' => ['https://www.openstreetmap.org/way/123456'], + 'latitude' => ['1.23'], + 'longitude' => ['4.56'], + ], ], ], ['HTTP_Authorization' => 'Bearer ' . $this->getToken()] @@ -99,15 +99,15 @@ class SwarmTest extends TestCase 'value' => 'My first #checkin using Example Product', 'html' => 'My first #checkin using Example Product', ]], - 'checkin' => [[ - 'type' => ['h-card'], - 'properties' => [ - 'name' => ['Awesome Venue'], - 'url' => ['https://www.example.org/way/123456'], - 'latitude' => ['1.23'], - 'longitude' => ['4.56'], - ], - ]], + ], + 'checkin' => [ + 'type' => ['h-card'], + 'properties' => [ + 'name' => ['Awesome Venue'], + 'url' => ['https://www.example.org/way/123456'], + 'latitude' => ['1.23'], + 'longitude' => ['4.56'], + ], ], ], ['HTTP_Authorization' => 'Bearer ' . $this->getToken()] @@ -130,15 +130,15 @@ class SwarmTest extends TestCase 'properties' => [ 'published' => [\Carbon\Carbon::now()->toDateTimeString()], 'syndication' => ['https://www.swarmapp.com/checkin/def'], - 'checkin' => [[ - 'type' => ['h-card'], - 'properties' => [ - 'name' => ['Awesomer Venue'], - 'url' => ['https://foursquare.com/v/654321'], - 'latitude' => ['3.21'], - 'longitude' => ['6.54'], - ], - ]], + ], + 'checkin' => [ + 'type' => ['h-card'], + 'properties' => [ + 'name' => ['Awesomer Venue'], + 'url' => ['https://foursquare.com/v/654321'], + 'latitude' => ['3.21'], + 'longitude' => ['6.54'], + ], ], ], ['HTTP_Authorization' => 'Bearer ' . $this->getToken()] @@ -169,13 +169,13 @@ class SwarmTest extends TestCase 'value' => 'My first #checkin using Example Product', 'html' => 'My first #checkin using Example Product', ]], - 'checkin' => [[ - 'type' => ['h-card'], - 'properties' => [ - 'name' => ['Awesome Venue'], - 'url' => ['https://foursquare.com/v/123456'], - ], - ]], + ], + 'checkin' => [ + 'type' => ['h-card'], + 'properties' => [ + 'name' => ['Awesome Venue'], + 'url' => ['https://foursquare.com/v/123456'], + ], ], ], ['HTTP_Authorization' => 'Bearer ' . $this->getToken()] @@ -202,21 +202,21 @@ class SwarmTest extends TestCase 'value' => 'My first #checkin using Example Product', 'html' => 'My first #checkin using Example Product', ]], - 'location' => [[ - 'type' => ['h-adr'], - 'properties' => [ - 'latitude' => ['1.23'], - 'longitude' => ['4.56'], - 'street-address' => ['Awesome Street'], - ], - ]], - 'checkin' => [[ - 'type' => ['h-card'], - 'properties' => [ - 'name' => ['Awesome Venue'], - 'url' => ['https://foursquare.com/v/123456'], - ], - ]], + ], + 'location' => [ + 'type' => ['h-adr'], + 'properties' => [ + 'latitude' => ['1.23'], + 'longitude' => ['4.56'], + 'street-address' => ['Awesome Street'], + ], + ], + 'checkin' => [ + 'type' => ['h-card'], + 'properties' => [ + 'name' => ['Awesome Venue'], + 'url' => ['https://foursquare.com/v/123456'], + ], ], ], ['HTTP_Authorization' => 'Bearer ' . $this->getToken()] @@ -228,4 +228,54 @@ class SwarmTest extends TestCase 'name' => 'Awesome Venue', ]); } + + /** @test */ + public function a_real_ownyourswarm_checkin() + { + $response = $this->json( + 'POST', + 'api/post', + [ + 'type' => ['h-entry'], + 'properties' =>[ + 'published' => [\Carbon\Carbon::now()->toDateTimeString()] + ], + 'syndication' => [ + 'https://www.swarmapp.com/user/199841/checkin/5c4b1ac56dcf04002c0a4f58' + ], + 'checkin' => [ + 'type' => ['h-card'], + 'properties' => [ + 'name' => ['Forbidden Planet'], + 'url' => ['https://foursquare.com/v/4ade0e46f964a520bf6f21e3'], + 'latitude' => [53.483153021713], + 'longitude' => [-2.2350297792539], + 'street-address' => ['65 Oldham St.'], + 'locality' => ['Manchester'], + 'country-name' => ['United Kingdom'], + 'postal-code' => ['M1 1JR'] + ], + 'value' => 'https://foursquare.com/v/4ade0e46f964a520bf6f21e3' + ], + 'location' => [ + 'type' => ['h-adr'], + 'properties' => [ + 'latitude' => [53.483153021713], + 'longitude' => [-2.2350297792539], + 'street-address' => ['65 Oldham St.'], + 'locality' => ['Manchester'], + 'country-name' => ['United Kingdom'], + 'postal-code' => ['M1 1JR'] + ] + ], + ], + ['HTTP_Authorization' => 'Bearer ' . $this->getToken()] + ); + $this->assertDatabaseHas('places', [ + 'name' => 'Forbidden Planet', + ]); + $response + ->assertStatus(201) + ->assertJson(['response' => 'created']); + } }