seed(RoleSeeder::class); $this->org = Organisation::factory()->create(); $this->event = Event::factory()->create(['organisation_id' => $this->org->id]); $this->artist = Artist::factory()->create(['organisation_id' => $this->org->id]); } public function test_expired_option_demoted_to_draft(): void { $eng = ArtistEngagement::factory()->create([ 'artist_id' => $this->artist->id, 'event_id' => $this->event->id, 'booking_status' => ArtistEngagementStatus::Option, 'option_expires_at' => now()->subMinute(), ]); $this->artisan('artist:demote-expired-options')->assertSuccessful(); $this->assertSame( ArtistEngagementStatus::Draft, $eng->refresh()->booking_status, ); $this->assertTrue( Activity::query() ->where('subject_type', $eng->getMorphClass()) ->where('subject_id', $eng->id) ->where('event', 'option_expired') ->exists(), ); } public function test_future_option_untouched(): void { $eng = ArtistEngagement::factory()->create([ 'artist_id' => $this->artist->id, 'event_id' => $this->event->id, 'booking_status' => ArtistEngagementStatus::Option, 'option_expires_at' => now()->addHour(), ]); $this->artisan('artist:demote-expired-options')->assertSuccessful(); $this->assertSame( ArtistEngagementStatus::Option, $eng->refresh()->booking_status, ); } public function test_non_option_status_untouched(): void { $eng = ArtistEngagement::factory()->create([ 'artist_id' => $this->artist->id, 'event_id' => $this->event->id, 'booking_status' => ArtistEngagementStatus::Confirmed, 'option_expires_at' => now()->subDay(), ]); $this->artisan('artist:demote-expired-options')->assertSuccessful(); $this->assertSame( ArtistEngagementStatus::Confirmed, $eng->refresh()->booking_status, ); } public function test_running_twice_writes_only_one_option_expired_entry(): void { $eng = ArtistEngagement::factory()->create([ 'artist_id' => $this->artist->id, 'event_id' => $this->event->id, 'booking_status' => ArtistEngagementStatus::Option, 'option_expires_at' => now()->subMinute(), ]); $this->artisan('artist:demote-expired-options')->assertSuccessful(); $this->artisan('artist:demote-expired-options')->assertSuccessful(); $count = Activity::query() ->where('subject_type', $eng->getMorphClass()) ->where('subject_id', $eng->id) ->where('event', 'option_expired') ->count(); $this->assertSame(1, $count); } }