From 1d45e0df7952b1ec9c4ca36c9a968ef96b814c70 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 5 Jul 2024 03:20:54 +0100 Subject: [PATCH] Added model create test Signed-off-by: snipe --- .../AssetModels/Api/CreateAssetModelsTest.php | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/Feature/AssetModels/Api/CreateAssetModelsTest.php diff --git a/tests/Feature/AssetModels/Api/CreateAssetModelsTest.php b/tests/Feature/AssetModels/Api/CreateAssetModelsTest.php new file mode 100644 index 0000000000..a0b1c27b73 --- /dev/null +++ b/tests/Feature/AssetModels/Api/CreateAssetModelsTest.php @@ -0,0 +1,61 @@ +actingAsForApi(User::factory()->create()) + ->postJson(route('api.models.store')) + ->assertForbidden(); + } + + public function testCanCreateAssetModelWithAssetModelType() + { + $response = $this->actingAsForApi(User::factory()->superuser()->create()) + ->postJson(route('api.models.store'), [ + 'name' => 'Test AssetModel', + 'category_id' => Category::factory()->create()->id + ]) + ->assertOk() + ->assertStatusMessageIs('success') + ->assertStatus(200) + ->json(); + + $this->assertTrue(AssetModel::where('name', 'Test AssetModel')->exists()); + + $model = AssetModel::find($response['payload']['id']); + $this->assertEquals('Test AssetModel', $model->name); + } + + public function testCannotCreateAssetModelWithoutCategory() + { + $response = $this->actingAsForApi(User::factory()->superuser()->create()) + ->postJson(route('api.models.store'), [ + 'name' => 'Test AssetModel', + ]) + ->assertStatus(200) + ->assertOk() + ->assertStatusMessageIs('error') + ->assertJson([ + 'messages' => [ + 'category_id' => ['The category id field is required.'], + ], + ]) + ->json(); + + // dd($response); + $this->assertFalse(AssetModel::where('name', 'Test AssetModel')->exists()); + + } + +}