Add comprehensive test coverage and update notes
This commit is contained in:
@@ -90,3 +90,73 @@ it('lists thanks received for a user', function (): void {
|
||||
'thanker_name' => 'ThanksGiver',
|
||||
]);
|
||||
});
|
||||
|
||||
it('requires auth to thank and unthank posts', function (): void {
|
||||
$thread = makeThanksThread();
|
||||
$post = Post::create([
|
||||
'thread_id' => $thread->id,
|
||||
'user_id' => null,
|
||||
'body' => 'Post',
|
||||
]);
|
||||
|
||||
$this->app['auth']->forgetGuards();
|
||||
$response = $this->postJson("/api/posts/{$post->id}/thanks");
|
||||
$response->assertStatus(401);
|
||||
|
||||
$this->app['auth']->forgetGuards();
|
||||
$response = $this->deleteJson("/api/posts/{$post->id}/thanks");
|
||||
$response->assertStatus(401);
|
||||
});
|
||||
|
||||
it('creates and deletes thanks for a post', function (): void {
|
||||
$thread = makeThanksThread();
|
||||
$user = User::factory()->create();
|
||||
$post = Post::create([
|
||||
'thread_id' => $thread->id,
|
||||
'user_id' => $user->id,
|
||||
'body' => 'Post',
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
$response = $this->postJson("/api/posts/{$post->id}/thanks");
|
||||
$response->assertStatus(201);
|
||||
|
||||
$response = $this->deleteJson("/api/posts/{$post->id}/thanks");
|
||||
$response->assertStatus(204);
|
||||
});
|
||||
|
||||
it('serializes group colors for thanks', function (): void {
|
||||
$thread = makeThanksThread();
|
||||
$authorRole = \App\Models\Role::create(['name' => 'ROLE_AUTHOR', 'color' => '#ff0000']);
|
||||
$thankerRole = \App\Models\Role::create(['name' => 'ROLE_THANKER', 'color' => '#00ff00']);
|
||||
|
||||
$author = User::factory()->create(['name' => 'Author']);
|
||||
$author->roles()->attach($authorRole);
|
||||
$author->load('roles');
|
||||
$thanker = User::factory()->create(['name' => 'ThanksGiver']);
|
||||
$thanker->roles()->attach($thankerRole);
|
||||
$thanker->load('roles');
|
||||
|
||||
$post = Post::create([
|
||||
'thread_id' => $thread->id,
|
||||
'user_id' => $author->id,
|
||||
'body' => 'Helpful post',
|
||||
]);
|
||||
|
||||
PostThank::create([
|
||||
'post_id' => $post->id,
|
||||
'user_id' => $thanker->id,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($thanker);
|
||||
$response = $this->getJson("/api/user/{$thanker->id}/thanks/given");
|
||||
$response->assertOk();
|
||||
$payload = $response->getData(true);
|
||||
expect($payload[0]['post_author_group_color'])->toBe('#ff0000');
|
||||
|
||||
Sanctum::actingAs($author);
|
||||
$response = $this->getJson("/api/user/{$author->id}/thanks/received");
|
||||
$response->assertOk();
|
||||
$payload = $response->getData(true);
|
||||
expect($payload[0]['thanker_group_color'])->toBe('#00ff00');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user