#4-merge-with-master-conflict-resolve

This commit is contained in:
2026-05-12 11:00:22 +08:00
19 changed files with 819 additions and 79 deletions

View File

@@ -0,0 +1,96 @@
<?php
use App\Models\Category;
use App\Models\User;
test('category pages require authentication', function () {
$category = Category::factory()->create();
$this->get('/category')->assertRedirect('/login');
$this->get("/category/{$category->id}/edit")->assertRedirect('/login');
});
test('authenticated users can view categories', function () {
Category::factory()->create([
'name' => 'Design',
'slug' => 'design',
'description' => 'Visual work',
'color' => '#ec4899',
]);
$response = $this
->actingAs(User::factory()->create())
->get('/category');
$response
->assertSuccessful()
->assertSee('Categories')
->assertSee('Design')
->assertSee('design')
->assertSee('Visual work');
});
test('authenticated users can create a category', function () {
$response = $this
->actingAs(User::factory()->create())
->post('/category', [
'name' => 'Operations',
'slug' => '',
'description' => 'Internal workflows',
'color' => '#10b981',
]);
$response->assertRedirect('/category');
$this->assertDatabaseHas('categories', [
'name' => 'Operations',
'slug' => 'operations',
'description' => 'Internal workflows',
'color' => '#10b981',
]);
});
test('authenticated users can update a category', function () {
$category = Category::factory()->create([
'name' => 'Legacy',
'slug' => 'legacy',
'color' => '#4f46e5',
]);
$response = $this
->actingAs(User::factory()->create())
->patch("/category/{$category->id}", [
'name' => 'Marketing',
'slug' => 'marketing',
'description' => 'Campaign planning',
'color' => '#f59e0b',
]);
$response->assertRedirect("/category/{$category->id}/edit");
$this->assertDatabaseHas('categories', [
'id' => $category->id,
'name' => 'Marketing',
'slug' => 'marketing',
'description' => 'Campaign planning',
'color' => '#f59e0b',
]);
});
test('authenticated users can delete a category', function () {
$category = Category::factory()->create([
'name' => 'Archive',
'slug' => 'archive',
'color' => '#64748b',
]);
$response = $this
->actingAs(User::factory()->create())
->delete("/category/{$category->id}");
$response->assertRedirect('/category');
$this->assertDatabaseMissing('categories', [
'id' => $category->id,
]);
});

View File

@@ -3,5 +3,10 @@
it('returns a successful response', function () {
$response = $this->get('/');
$response->assertStatus(200);
$response
->assertSuccessful()
->assertSee('Taman Melawati News')
->assertSee('Community Garden Harvest Day Set for Saturday')
->assertSee('Login')
->assertSee('Register');
});