Finish re-working tests to run on test database

This commit is contained in:
Jonny Barnes 2021-08-31 12:28:00 +01:00
parent 09fc211623
commit 1abca77bdc
50 changed files with 535 additions and 265 deletions

View file

@ -19,7 +19,7 @@ class ProcessBookmarkJobTest extends TestCase
/** @test */
public function screenshotAndArchiveLinkAreSavedByJob(): void
{
$bookmark = Bookmark::find(1);
$bookmark = Bookmark::factory()->create();
$uuid = Uuid::uuid4();
$service = $this->createMock(BookmarkService::class);
$service->method('saveScreenshot')
@ -40,7 +40,7 @@ class ProcessBookmarkJobTest extends TestCase
/** @test */
public function archiveLinkSavedAsNullWhenExceptionThrown(): void
{
$bookmark = Bookmark::find(1);
$bookmark = Bookmark::factory()->create();
$uuid = Uuid::uuid4();
$service = $this->createMock(BookmarkService::class);
$service->method('saveScreenshot')

View file

@ -44,7 +44,7 @@ class ProcessWebMentionJobTest extends TestCase
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$note = Note::find(1);
$note = Note::factory()->create();
$source = 'https://example.org/mention/1/';
$job = new ProcessWebMention($note, $source);
@ -70,7 +70,7 @@ class ProcessWebMentionJobTest extends TestCase
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$note = Note::find(1);
$note = Note::factory()->create();
$source = 'https://example.org/mention/1/';
$job = new ProcessWebMention($note, $source);
@ -103,7 +103,7 @@ class ProcessWebMentionJobTest extends TestCase
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$note = Note::find(14);
$note = Note::factory()->create();
$source = 'https://aaronpk.localhost/reply/1';
$job = new ProcessWebMention($note, $source);
@ -135,7 +135,7 @@ class ProcessWebMentionJobTest extends TestCase
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$note = Note::find(14);
$note = Note::factory()->create();
$source = 'https://example.org/reply/1';
$webmention = new WebMention();
$webmention->source = $source;
@ -172,7 +172,7 @@ class ProcessWebMentionJobTest extends TestCase
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$note = Note::find(14);
$note = Note::factory()->create();
$source = 'https://example.org/reply/1';
$webmention = new WebMention();
$webmention->source = $source;
@ -209,7 +209,7 @@ class ProcessWebMentionJobTest extends TestCase
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$note = Note::find(14);
$note = Note::factory()->create();
$source = 'https://example.org/reply/1';
$webmention = new WebMention();
$webmention->source = $source;

View file

@ -10,18 +10,20 @@ use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class SyndicateBookmarkToTwitterJobTest extends TestCase
{
use DatabaseTransactions;
use RefreshDatabase;
/** @test */
public function weSendBookmarksToTwitter(): void
{
$faker = \Faker\Factory::create();
$randomNumber = $faker->randomNumber();
$json = json_encode([
'url' => 'https://twitter.com/123'
'url' => 'https://twitter.com/' . $randomNumber
]);
$mock = new MockHandler([
new Response(201, ['Content-Type' => 'application/json'], $json),
@ -29,13 +31,12 @@ class SyndicateBookmarkToTwitterJobTest extends TestCase
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$bookmark = Bookmark::find(1);
$bookmark = Bookmark::factory()->create();
$job = new SyndicateBookmarkToTwitter($bookmark);
$job->handle($client);
$this->assertDatabaseHas('bookmarks', [
'id' => 1,
'syndicates' => '{"twitter": "https://twitter.com/123"}',
'syndicates' => '{"twitter": "https://twitter.com/' . $randomNumber . '"}',
]);
}
}

View file

@ -8,18 +8,20 @@ use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class SyndicateNoteToTwitterJobTest extends TestCase
{
use DatabaseTransactions;
use RefreshDatabase;
/** @test */
public function weSyndicateNotesToTwitter(): void
{
$faker = \Faker\Factory::create();
$randomNumber = $faker->randomNumber();
$json = json_encode([
'url' => 'https://twitter.com/i/web/status/123'
'url' => 'https://twitter.com/i/web/status/' . $randomNumber,
]);
$mock = new MockHandler([
new Response(201, ['Content-Type' => 'application/json'], $json),
@ -27,13 +29,12 @@ class SyndicateNoteToTwitterJobTest extends TestCase
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$note = Note::find(1);
$note = Note::factory()->create();
$job = new SyndicateNoteToTwitter($note);
$job->handle($client);
$this->assertDatabaseHas('notes', [
'id' => 1,
'tweet_id' => '123',
'tweet_id' => $randomNumber,
]);
}
}