only('x', 'y', 'space', 'points'))->toBe(['x' => 500, 'y' => 500, 'space' => 50, 'points' => 21]) ->and($village->resources())->toBe(['wood' => 500.0, 'clay' => 500.0, 'iron' => 500.0, 'food' => 300.0]) ->and($village->buildings->map->only('type', 'level')->all())->toBe([ ['type' => 'headquarters', 'level' => 0], ['type' => 'storage', 'level' => 0], ['type' => 'farm', 'level' => 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['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]) ->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'])->toBeNull() ->and(rule(fn () => app(ShowVillage::class)(User::factory()->create(), $village->id)))->toBe('not_found'); });