2026-10-28 18:17:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use App\Actions\JoinWorld;
|
|
|
|
|
use App\Actions\ListWorlds;
|
|
|
|
|
use App\Actions\ShowVillage;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\World;
|
|
|
|
|
|
|
|
|
|
it('starts a village with HQ, storage and farm at level 0', function () {
|
|
|
|
|
$village = startVillage();
|
|
|
|
|
|
2026-10-28 18:45:02 +00:00
|
|
|
expect($village->only('x', 'y', 'space', 'points'))->toBe(['x' => 500, 'y' => 500, 'space' => 50, 'points' => 21])
|
2026-10-28 18:17:34 +00:00
|
|
|
->and($village->resources())->toBe(['wood' => 500.0, 'clay' => 500.0, 'iron' => 500.0, 'food' => 300.0])
|
2026-10-28 18:45:02 +00:00
|
|
|
->and($village->buildings->map->only('type', 'level')->all())->toBe([
|
|
|
|
|
['type' => 'headquarters', 'level' => 0],
|
|
|
|
|
['type' => 'storage', 'level' => 0],
|
|
|
|
|
['type' => 'farm', 'level' => 0],
|
2026-10-28 18:17:34 +00:00
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('returns the same village when joining again', function () {
|
|
|
|
|
$village = startVillage();
|
|
|
|
|
|
|
|
|
|
expect(app(JoinWorld::class)(owner($village), $village->world_id)->id)->toBe($village->id);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('spawns the next player on a free coordinate', function () {
|
|
|
|
|
$first = startVillage();
|
|
|
|
|
$second = startVillage(User::factory()->create());
|
|
|
|
|
|
|
|
|
|
expect([$second->x, $second->y])->not->toBe([$first->x, $first->y]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('lists worlds with their speed and the player village', function () {
|
|
|
|
|
$village = startVillage();
|
|
|
|
|
$dev = World::where('slug', 'dev')->first();
|
|
|
|
|
|
|
|
|
|
expect(app(ListWorlds::class)(owner($village)))->toBe([
|
|
|
|
|
['id' => $village->world_id, 'name' => 'World 1', 'slug' => 'w1', 'speed' => 1.0, 'village_id' => $village->id],
|
|
|
|
|
['id' => $dev->id, 'name' => 'Dev world', 'slug' => 'dev', 'speed' => 100.0, 'village_id' => null],
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows a start village to its owner only', function () {
|
|
|
|
|
$village = startVillage();
|
|
|
|
|
$state = shown($village);
|
|
|
|
|
|
2026-10-28 18:45:02 +00:00
|
|
|
expect($state['space'])->toBe(['used' => 17, 'max' => 50])
|
|
|
|
|
->and($state['continent'])->toBe('K55')
|
|
|
|
|
->and($state['rates'])->toBe(['wood' => 5.0, 'clay' => 5.0, 'iron' => 5.0, 'food' => 0.0])
|
2026-10-28 18:17:34 +00:00
|
|
|
->and($state['storage_cap'])->toEqual(1000)
|
|
|
|
|
->and($state['population'])->toEqual(['food_budget' => 30, 'upkeep' => 30, 'villagers' => 30, 'workers' => 5, 'soldiers' => 0])
|
|
|
|
|
->and($state['builders'])->toBe(2)
|
|
|
|
|
->and(collect($state['buildable'])->firstWhere('type', 'headquarters')['blocked'])->toBe('max_per_village')
|
2026-10-28 19:58:35 +00:00
|
|
|
->and(collect($state['buildable'])->firstWhere('type', 'wall')['blocked'])->toBeNull()
|
2026-10-28 18:17:34 +00:00
|
|
|
->and(rule(fn () => app(ShowVillage::class)(User::factory()->create(), $village->id)))->toBe('not_found');
|
|
|
|
|
});
|