77 lines
2.4 KiB
PHP
77 lines
2.4 KiB
PHP
<?php
|
|
|
|
use App\Models\Dynamic;
|
|
use App\Models\User;
|
|
|
|
test('user displayNameFor returns user name by default', function () {
|
|
$user = User::factory()->create(['name' => 'Alice']);
|
|
$dynamic = Dynamic::factory()->create();
|
|
$dynamic->participants()->attach($user->id, ['role' => 'participant']);
|
|
|
|
expect($user->displayNameFor($dynamic))->toBe('Alice');
|
|
});
|
|
|
|
test('user displayNameFor returns custom display name when set', function () {
|
|
$user = User::factory()->create(['name' => 'Alice']);
|
|
$dynamic = Dynamic::factory()->create();
|
|
$dynamic->participants()->attach($user->id, [
|
|
'role' => 'participant',
|
|
'display_name' => 'Ally',
|
|
]);
|
|
|
|
expect($user->displayNameFor($dynamic))->toBe('Ally');
|
|
});
|
|
|
|
test('participant can update their display name', function () {
|
|
$user = User::factory()->create(['name' => 'Alice']);
|
|
$dynamic = Dynamic::factory()->create();
|
|
$dynamic->participants()->attach($user->id, ['role' => 'participant']);
|
|
|
|
$this->actingAs($user);
|
|
|
|
$response = $this->put(route('dynamics.participant.update', $dynamic->uuid), [
|
|
'display_name' => 'Ally',
|
|
]);
|
|
|
|
$response->assertRedirect();
|
|
|
|
// Check database
|
|
$this->assertDatabaseHas('participants', [
|
|
'user_id' => $user->id,
|
|
'dynamic_id' => $dynamic->id,
|
|
'display_name' => 'Ally',
|
|
]);
|
|
|
|
// Check display name method
|
|
expect($user->displayNameFor($dynamic))->toBe('Ally');
|
|
});
|
|
|
|
test('display name update requires display_name parameter', function () {
|
|
$user = User::factory()->create(['name' => 'Alice']);
|
|
$dynamic = Dynamic::factory()->create();
|
|
$dynamic->participants()->attach($user->id, ['role' => 'participant']);
|
|
|
|
$this->actingAs($user);
|
|
|
|
$response = $this->put(route('dynamics.participant.update', $dynamic->uuid), [
|
|
'display_name' => '',
|
|
]);
|
|
|
|
$response->assertSessionHasErrors(['display_name']);
|
|
});
|
|
|
|
test('non participant cannot update display name', function () {
|
|
$user = User::factory()->create(['name' => 'Alice']);
|
|
$nonParticipant = User::factory()->create(['name' => 'Bob']);
|
|
$dynamic = Dynamic::factory()->create();
|
|
$dynamic->participants()->attach($user->id, ['role' => 'participant']);
|
|
|
|
$this->actingAs($nonParticipant);
|
|
|
|
$response = $this->put(route('dynamics.participant.update', $dynamic->uuid), [
|
|
'display_name' => 'Bobby',
|
|
]);
|
|
|
|
$response->assertStatus(404);
|
|
});
|