*/ function slugs(string $egg): array { return Egg::query()->where('name', $egg)->sole()->tags()->pluck('tags.slug')->sort()->values()->all(); } test('created eggs carry the built-in tags of their directory', function (): void { DB::table('taggables')->delete(); Tag::query()->whereIn('slug', ['minecraft', 'srcds', 'garrysmod', 'voice', 'rust'])->delete(); Egg::query()->delete(); $this->seed(EggSeeder::class); expect(slugs('Paper'))->toBe(['minecraft']) ->and(slugs('Garrys Mod'))->toBe(['garrysmod', 'srcds']) ->and(slugs('Insurgency'))->toBe(['srcds']) ->and(slugs('Teamspeak3 Server'))->toBe(['voice']) ->and(slugs('Rust'))->toBe(['rust']) ->and(Tag::query()->where('slug', 'srcds')->sole()->name)->toBe('Source Engine'); }); test('reseeding leaves the tags of existing eggs alone, even when an egg file replaces them', function (): void { $paper = Egg::query()->where('name', 'Paper')->sole(); $paper->tags()->sync(Tag::factory()->create(['slug' => 'admin-added'])); Egg::query()->where('name', 'Rust')->sole()->tags()->detach(); $this->app->extend(UpdatesEggsFromImports::class, fn (UpdatesEggsFromImports $updater): UpdatesEggsFromImports => new readonly class($updater) implements UpdatesEggsFromImports { public function __construct(private UpdatesEggsFromImports $updater) {} public function update(Egg $egg, UploadedFile $file): Egg { $egg = $this->updater->update($egg, $file); $egg->tags()->sync(Tag::findOrCreateFromSlugs(['from-file'])); return $egg; } }); $this->seed(EggSeeder::class); expect(slugs('Paper'))->toBe(['admin-added']) ->and(slugs('Rust'))->toBe([]) ->and(slugs('Insurgency'))->toBe(['srcds']); });