only('x', 'y', 'grid_w', 'grid_h'))->toBe(['x' => 500, 'y' => 500, 'grid_w' => 10, 'grid_h' => 5]) ->and($village->resources())->toBe(['wood' => 500.0, 'clay' => 500.0, 'iron' => 500.0, 'food' => 300.0]) ->and($village->buildings->map->only('type', 'level', 'x', 'y')->all())->toBe([ ['type' => 'headquarters', 'level' => 0, 'x' => 0, 'y' => 0], ['type' => 'storage', 'level' => 0, 'x' => 3, 'y' => 0], ['type' => 'farm', 'level' => 0, 'x' => 5, 'y' => 0], ]); }); 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); expect($state['rates'])->toBe(['wood' => 5.0, 'clay' => 5.0, 'iron' => 5.0, 'food' => 0.0]) ->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') ->and(collect($state['buildable'])->firstWhere('type', 'wall')['blocked'])->toBe('requires') ->and(rule(fn () => app(ShowVillage::class)(User::factory()->create(), $village->id)))->toBe('not_found'); });