create(); $author->refresh(); $sharer = User::factory()->create(); $sharer->refresh(); $status = Status::factory()->create([ 'profile_id' => $author->profile_id, 'type' => 'photo', 'scope' => 'public', 'visibility' => 'public', 'reblogs_count' => 0, ]); Passport::actingAs($sharer, ['write', 'read']); $this->postJson("/api/v1/statuses/{$status->id}/reblog")->assertOk(); $this->postJson("/api/v1/statuses/{$status->id}/reblog")->assertOk(); // Exactly one share row for this user/status. expect(Status::where('reblog_of_id', $status->id) ->where('profile_id', $sharer->profile_id) ->where('type', 'share') ->count())->toBe(1); // Counter reflects a single reblog. expect($status->fresh()->reblogs_count)->toBe(1); }); it('does not re-dispatch SharePipeline for an already-existing share', function () { Bus::fake(); $author = User::factory()->create(); $author->refresh(); $sharer = User::factory()->create(); $sharer->refresh(); $status = Status::factory()->create([ 'profile_id' => $author->profile_id, 'type' => 'photo', 'scope' => 'public', 'visibility' => 'public', 'reblogs_count' => 0, ]); Passport::actingAs($sharer, ['write', 'read']); $this->postJson("/api/v1/statuses/{$status->id}/reblog")->assertOk(); $this->postJson("/api/v1/statuses/{$status->id}/reblog")->assertOk(); // SharePipeline dispatched exactly once (only for the newly-created share). Bus::assertDispatchedTimes(SharePipeline::class, 1); });