Upload beautify
This commit is contained in:
48
tests/Feature/Discovery/DiscoveryEventIngestionTest.php
Normal file
48
tests/Feature/Discovery/DiscoveryEventIngestionTest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Jobs\IngestUserDiscoveryEventJob;
|
||||
use App\Models\Artwork;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('queues discovery event ingestion asynchronously', function () {
|
||||
Queue::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
$artwork = Artwork::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->postJson('/api/discovery/events', [
|
||||
'event_type' => 'view',
|
||||
'artwork_id' => $artwork->id,
|
||||
'meta' => ['source' => 'artwork_show'],
|
||||
]);
|
||||
|
||||
$response
|
||||
->assertStatus(202)
|
||||
->assertJsonPath('queued', true)
|
||||
->assertJsonPath('algo_version', (string) config('discovery.algo_version'));
|
||||
|
||||
Queue::assertPushed(IngestUserDiscoveryEventJob::class, function (IngestUserDiscoveryEventJob $job) use ($user, $artwork): bool {
|
||||
return $job->userId === $user->id
|
||||
&& $job->artworkId === $artwork->id
|
||||
&& $job->eventType === 'view';
|
||||
});
|
||||
});
|
||||
|
||||
it('validates discovery event payload', function () {
|
||||
$user = User::factory()->create();
|
||||
$artwork = Artwork::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->postJson('/api/discovery/events', [
|
||||
'event_type' => 'impression',
|
||||
'artwork_id' => $artwork->id,
|
||||
]);
|
||||
|
||||
$response->assertStatus(422);
|
||||
$response->assertJsonValidationErrors(['event_type']);
|
||||
});
|
||||
Reference in New Issue
Block a user