diff --git a/tests/Feature/WebMentionsControllerTest.php b/tests/Feature/WebMentionsControllerTest.php new file mode 100644 index 00000000..163eb4ce --- /dev/null +++ b/tests/Feature/WebMentionsControllerTest.php @@ -0,0 +1,84 @@ +call('POST', '/webmention', ['source' => 'https://example.org/post/123']); + $response->assertStatus(400); + } + + /** + * Test invalid target gets a 400 response. + * + * @return void + */ + public function test_invalid_target_returns_400_response() + { + $response = $this->call('POST', '/webmention', [ + 'source' => 'https://example.org/post/123', + 'target' => config('app.url') . '/invalid/target' + ]); + $response->assertStatus(400); + } + + /** + * Test blog target gets a 501 response due to me not supporting it. + * + * @return void + */ + public function test_blog_target_returns_501_response() + { + $response = $this->call('POST', '/webmention', [ + 'source' => 'https://example.org/post/123', + 'target' => config('app.url') . '/blog/target' + ]); + $response->assertStatus(501); + } + + /** + * Test that a non-existant note gives a 400 response. + * + * @return void + */ + public function test_nonexistant_note_returns_400_response() + { + $response = $this->call('POST', '/webmention', [ + 'source' => 'https://example.org/post/123', + 'target' => config('app.url') . '/notes/ZZZZZ' + ]); + $response->assertStatus(400); + } + + /** + * Test a legit webmention triggers the ProcessWebMention job. + * + * @return void + */ + public function test_legitimate_webmnetion_triggers_processwebmention_job() + { + Queue::fake(); + + $response = $this->call('POST', '/webmention', [ + 'source' => 'https://example.org/post/123', + 'target' => config('app.url') . '/notes/B' + ]); + $response->assertStatus(202); + + Queue::assertPushed(ProcessWebMention::class); + } +}