Skip to content
Closed

fix: ci #1175

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/Http/Requests/ListApiSuggestedUsersRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

namespace App\Http\Requests;

use App\Enums\ProfileType;
use App\Models\Commit;
use App\Models\User;
use App\Rules\VisibleCommit;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\Exists;

/**
* Who to follow may be asked for the page it shows on, as the web asks for it beside a profile or a commit. The commit
Expand All @@ -17,7 +20,7 @@
final class ListApiSuggestedUsersRequest extends FormRequest
{
/**
* @return array<string, list<string|ValidationRule>>
* @return array<string, list<string|ValidationRule|Exists>>
*/
public function rules(): array
{
Expand All @@ -26,7 +29,7 @@ public function rules(): array

return [
'round' => ['nullable', 'integer', 'min:0'],
'username' => ['nullable', 'string', 'exists:users,username'],
'username' => ['nullable', 'string', Rule::exists('profiles', 'handle')->where('type', ProfileType::User->value)],
'commit_id' => ['bail', 'nullable', 'uuid', 'prohibits:username', new VisibleCommit($user, __('That commit is no longer available.'))],
];
}
Expand All @@ -37,7 +40,7 @@ public function context(): User|Commit|null
assert($user instanceof User);

return match (true) {
$this->filled('username') => User::query()->where('username', $this->string('username')->value())->firstOrFail(),
$this->filled('username') => User::query()->whereRelation('profile', 'handle', $this->string('username')->value())->firstOrFail(),
$this->filled('commit_id') => Commit::query()->visibleTo($user)->findOrFail($this->string('commit_id')->value()),
default => null,
};
Expand Down
2 changes: 1 addition & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@

// Who to Follow...
Route::get('me/suggested-users', [SuggestedUserController::class, 'index'])->name('api-suggested-user.index');
Route::post('users/{user:username}/dismiss', [SuggestionDismissalController::class, 'store'])->name('api-suggestion-dismissal.store');
Route::post('users/{user:handle}/dismiss', [SuggestionDismissalController::class, 'store'])->name('api-suggestion-dismissal.store');

// User Mute...
Route::get('me/muted', [UserMuteController::class, 'index'])->name('api-user-mute.index');
Expand Down
10 changes: 5 additions & 5 deletions tests/Feature/Controllers/Api/SuggestedUserControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

it('suggests people to follow, with why and whether they follow the user', function (): void {
$friend = User::factory()->create();
$vouched = User::factory()->has(Commit::factory())->create(['username' => 'octocat']);
$vouched = User::factory()->has(Commit::factory())->create(['handle' => 'octocat']);

$this->user->following()->attach($friend);
$friend->following()->attach($vouched);
Expand Down Expand Up @@ -108,7 +108,7 @@

$profile->following()->attach($followed);

signedApiRequest($this->keyPair, 'GET', route('api-suggested-user.index', ['username' => $profile->username]))
signedApiRequest($this->keyPair, 'GET', route('api-suggested-user.index', ['username' => $profile->handle]))
->assertOk()
->assertJsonPath('data.*.id', [$followed->id, $regular->id]);
});
Expand Down Expand Up @@ -144,7 +144,7 @@
$people->last()->followers()->attach($people->take(3));

[$webRoute, $context] = $page === 'profile'
? [route('user.show', $author), ['username' => $author->username]]
? [route('user.show', $author), ['username' => $author->handle]]
: [route('commit.show', [$author, $root]), ['commit_id' => $root->id]];

$web = null;
Expand Down Expand Up @@ -188,7 +188,7 @@

$regular = signedApiRequest($this->keyPair, 'GET', route('api-suggested-user.index'))->json('data.*.id');

signedApiRequest($this->keyPair, 'GET', route('api-suggested-user.index', ['username' => $profile->username]))
signedApiRequest($this->keyPair, 'GET', route('api-suggested-user.index', ['username' => $profile->handle]))
->assertOk()
->assertJsonPath('data.*.id', $regular);
})->with([
Expand Down Expand Up @@ -247,7 +247,7 @@
'an unknown username' => fn (): array => [['username' => 'nobody-here'], 'username'],
'an unknown commit' => fn (): array => [['commit_id' => '01a16c57-e371-73fb-a4d7-6ad455c9dd57'], 'commit_id'],
'a commit id that is not one' => fn (): array => [['commit_id' => 'latest'], 'commit_id'],
'a profile and a commit' => fn (): array => [['username' => User::factory()->create()->username, 'commit_id' => Commit::factory()->create()->id], 'commit_id'],
'a profile and a commit' => fn (): array => [['username' => User::factory()->create()->handle, 'commit_id' => Commit::factory()->create()->id], 'commit_id'],
]);

it('refuses a round that is not a whole number from zero', function (mixed $round): void {
Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/Controllers/UserControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@
});

it('shows the github profile readme on the readme tab, without looking for commits', function (): void {
$user = User::factory()->create(['username' => 'octocat']);
$user = User::factory()->create(['handle' => 'octocat']);
Commit::factory()->for($user)->create();

Http::fake([
Expand All @@ -720,7 +720,7 @@
});

it('tells the readme tab when github did not answer', function (): void {
$user = User::factory()->create(['username' => 'octocat']);
$user = User::factory()->create(['handle' => 'octocat']);

Http::fake(["api.github.com/user/{$user->github_id}" => Http::response(status: 502)]);

Expand All @@ -730,7 +730,7 @@

it('does not ask github for the readme on the other tabs', function (string $tab): void {
Http::preventStrayRequests();
$user = User::factory()->create(['username' => 'octocat']);
$user = User::factory()->create(['handle' => 'octocat']);

$this->get(route('user.show', ['user' => $user, 'tab' => $tab]))->assertOk()->assertInertia(fn ($page) => $page
->where('readme', null));
Expand Down