From e3fff4b9a84c3615d394fedb57583baa2dc14437 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Wed, 9 Aug 2017 20:59:22 +0100 Subject: [PATCH] Squashed commit of the following: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit 41ab44ed1d86a1d0788089cf2d79e3c9ab8e2ba6 Author: Jonny Barnes Date: Wed Aug 9 20:58:13 2017 +0100 Add a test for a swarm checkin with no text commit b4986ba3207374d11438e00d05a6f1ae1720bd49 Author: Jonny Barnes Date: Wed Aug 9 20:57:44 2017 +0100 A migration that makes the note column of the notes table nullable commit 80ac4d38c992e59733f60e844f376e36507fb8ee Author: Jonny Barnes Date: Wed Aug 9 20:57:04 2017 +0100 Don’t fail when the text content of a note is empty commit 874acdd3b31028c06d19cdbe9ef34bbc9660a704 Author: Jonny Barnes Date: Wed Aug 9 20:55:12 2017 +0100 Allow no content for the actual note, maybe its just a picture. Also provide some context for swarm checkins --- app/Jobs/SendWebMentions.php | 3 ++ app/Services/NoteService.php | 5 ++- ..._08_09_181357_allow_empty_note_content.php | 34 +++++++++++++++++++ tests/Feature/SwarmTest.php | 34 +++++++++++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2017_08_09_181357_allow_empty_note_content.php diff --git a/app/Jobs/SendWebMentions.php b/app/Jobs/SendWebMentions.php index dd4e2835..5bcbda58 100644 --- a/app/Jobs/SendWebMentions.php +++ b/app/Jobs/SendWebMentions.php @@ -104,6 +104,9 @@ class SendWebMentions implements ShouldQueue */ public function getLinks($html) { + if ($html == '' || is_null($html)) { + return []; + } $urls = []; $dom = new \DOMDocument(); $dom->loadHTML($html); diff --git a/app/Services/NoteService.php b/app/Services/NoteService.php index e653c6c6..e2b91773 100644 --- a/app/Services/NoteService.php +++ b/app/Services/NoteService.php @@ -20,7 +20,7 @@ class NoteService //check the input if (array_key_exists('content', $data) === false) { - throw new \Exception('No content defined'); //we can’t fudge the data + $data['content'] = null; } if (array_key_exists('in-reply-to', $data) === false) { $data['in-reply-to'] = null; @@ -64,6 +64,9 @@ class NoteService if ($place !== null) { $note->place()->associate($place); $note->swarm_url = $data['swarm-url']; + if ($note->note === null || $note->note == '') { + $note->note = 'I’ve just checked in with Swarm'; + } } } diff --git a/database/migrations/2017_08_09_181357_allow_empty_note_content.php b/database/migrations/2017_08_09_181357_allow_empty_note_content.php new file mode 100644 index 00000000..49de8b84 --- /dev/null +++ b/database/migrations/2017_08_09_181357_allow_empty_note_content.php @@ -0,0 +1,34 @@ +json( + 'POST', + 'api/post', + [ + 'type' => ['h-entry'], + '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'], + ], + ]], + ], + ], + ['HTTP_Authorization' => 'Bearer ' . $this->getToken()] + ); + $response + ->assertStatus(201) + ->assertJson(['response' => 'created']); + $this->assertDatabaseHas('places', [ + 'external_urls' => '{"foursquare": "https://foursquare.com/v/654321"}' + ]); + $this->assertDatabaseHas('notes', [ + 'swarm_url' => 'https://www.swarmapp.com/checkin/def' + ]); + } + /** * Generate a valid token to be used in the tests. *