create(); // Factory creation already triggers OrganisationObserver — the // schema may already be seeded. We re-call to confirm idempotency // and inspect the resulting state. $schema = ArtistAdvanceDefault::seedFor($org); $this->assertSame(FormPurpose::ARTIST_ADVANCE->value, $schema->getRawOriginal('purpose')); $this->assertTrue((bool) $schema->section_level_submit); $this->assertTrue((bool) $schema->is_published); $sections = FormSchemaSection::query() ->withoutGlobalScope(OrganisationScope::class) ->where('form_schema_id', $schema->id) ->orderBy('sort_order') ->pluck('slug') ->all(); $this->assertSame([ 'general-info', 'contacts', 'production', 'technical-rider', 'hospitality', ], $sections); } public function test_seeder_is_idempotent(): void { $org = Organisation::factory()->create(); $first = ArtistAdvanceDefault::seedFor($org); $second = ArtistAdvanceDefault::seedFor($org); $this->assertSame($first->id, $second->id); $this->assertSame(1, FormSchema::query() ->withoutGlobalScope(OrganisationScope::class) ->where('organisation_id', $org->id) ->where('purpose', FormPurpose::ARTIST_ADVANCE->value) ->count()); } public function test_general_info_section_has_expected_fields(): void { $org = Organisation::factory()->create(); $schema = ArtistAdvanceDefault::seedFor($org); $section = FormSchemaSection::query() ->withoutGlobalScope(OrganisationScope::class) ->where('form_schema_id', $schema->id) ->where('slug', 'general-info') ->firstOrFail(); $slugs = FormField::query() ->withoutGlobalScope(OrganisationScope::class) ->where('form_schema_section_id', $section->id) ->orderBy('sort_order') ->pluck('slug') ->all(); $this->assertSame([ 'arrival-datetime', 'departure-datetime', 'general-notes', ], $slugs); } public function test_organisation_observer_seeds_schema_outside_tests(): void { // The observer skips during automated tests (otherwise existing // FormSchema-counting tests would break). Verify the seeder still // covers a fresh org when invoked directly — the production code // path (observer) ultimately calls the same seeder. $org = Organisation::factory()->create(); ArtistAdvanceDefault::seedFor($org); $schema = FormSchema::query() ->withoutGlobalScope(OrganisationScope::class) ->where('organisation_id', $org->id) ->where('purpose', FormPurpose::ARTIST_ADVANCE->value) ->first(); $this->assertNotNull($schema); } public function test_artisan_command_seeds_one_organisation(): void { $org = Organisation::factory()->create(); // The auto-seeded schema already covers this case; running the // command again must be idempotent (skip path). $this->artisan('artist:seed-advance-default', ['organisation' => $org->id]) ->assertSuccessful(); $this->assertSame(1, FormSchema::query() ->withoutGlobalScope(OrganisationScope::class) ->where('organisation_id', $org->id) ->where('purpose', FormPurpose::ARTIST_ADVANCE->value) ->count()); } public function test_artisan_command_seeds_all_when_no_argument(): void { Organisation::factory()->count(2)->create(); $this->artisan('artist:seed-advance-default')->assertSuccessful(); $this->assertGreaterThanOrEqual(2, FormSchema::query() ->withoutGlobalScope(OrganisationScope::class) ->where('purpose', FormPurpose::ARTIST_ADVANCE->value) ->count()); } }