diff --git a/tests/Feature/Categories/Api/CreateCategoriesTest.php b/tests/Feature/Categories/Api/CreateCategoriesTest.php new file mode 100644 index 0000000000..db5810cf14 --- /dev/null +++ b/tests/Feature/Categories/Api/CreateCategoriesTest.php @@ -0,0 +1,60 @@ +actingAsForApi(User::factory()->create()) + ->postJson(route('api.categories.store')) + ->assertForbidden(); + } + + public function testCanCreateCategoryWithCategoryType() + { + $response = $this->actingAsForApi(User::factory()->superuser()->create()) + ->postJson(route('api.categories.store'), [ + 'name' => 'Test Category', + 'eula_text' => 'Test EULA', + 'category_type' => 'accessory', + ]) + ->assertOk() + ->assertStatusMessageIs('success') + ->assertStatus(200) + ->json(); + + $this->assertTrue(Category::where('name', 'Test Category')->exists()); + + $category = Category::find($response['payload']['id']); + $this->assertEquals('Test Category', $category->name); + $this->assertEquals('Test EULA', $category->eula_text); + $this->assertEquals('accessory', $category->category_type); + } + + public function testCannotCreateCategoryWithoutCategoryType() + { + $this->actingAsForApi(User::factory()->superuser()->create()) + ->postJson(route('api.categories.store'), [ + 'name' => 'Test Category', + 'eula_text' => 'Test EULA', + ]) + ->assertOk() + ->assertStatusMessageIs('error') + ->assertStatus(200) + ->json(); + + $this->assertFalse(Category::where('name', 'Test Category')->exists()); + + } + +} diff --git a/tests/Feature/Categories/Api/UpdateCategoryTest.php b/tests/Feature/Categories/Api/UpdateCategoryTest.php new file mode 100644 index 0000000000..5c67ea76e5 --- /dev/null +++ b/tests/Feature/Categories/Api/UpdateCategoryTest.php @@ -0,0 +1,56 @@ +create(); + + $this->actingAsForApi(User::factory()->superuser()->create()) + ->patchJson(route('api.categories.update', $category), [ + 'name' => 'Test Category', + 'eula_text' => 'Test EULA', + ]) + ->assertOk() + ->assertStatusMessageIs('success') + ->assertStatus(200) + ->json(); + + //dd($response); + $category->refresh(); + $this->assertEquals('Test Category', $category->name, 'Name was not updated'); + $this->assertEquals('Test EULA', $category->eula_text, 'EULA was not updated'); + + } + + public function testCannotUpdateCategoryViaPatchWithCategoryType() + { + $category = Category::factory()->create(); + + $this->actingAsForApi(User::factory()->superuser()->create()) + ->patchJson(route('api.categories.update', $category), [ + 'name' => 'Test Category', + 'eula_text' => 'Test EULA', + 'category_type' => 'accessory', + ]) + ->assertOk() + ->assertStatusMessageIs('error') + ->assertStatus(200) + ->json(); + + //dd($response); + $category->refresh(); + $this->assertNotEquals('Test Category', $category->name, 'Name was not updated'); + $this->assertNotEquals('Test EULA', $category->eula_text, 'EULA was not updated'); + $this->assertNotEquals('accessory', $category->category_type, 'EULA was not updated'); + + } + +}