test: ItemMaster API 전체 테스트 완료 (35 tests, 32 APIs)

- ItemPage CRUD 테스트 4개 추가
- ItemSection CRUD + Reorder 테스트 4개 추가
- ItemField CRUD + Reorder 테스트 4개 추가
- ItemBomItem CRUD 테스트 3개 추가
- SectionTemplate CRUD 테스트 4개 추가
- ItemMasterField CRUD 테스트 4개 추가

주요 수정:
- item_section_id → section_id 필드명 수정
- item_type enum 값 수정 (PRODUCT→FG, MATERIAL→RM)
- 모든 테스트 통과 (35 tests, 207 assertions)
This commit is contained in:
2025-11-20 20:50:59 +09:00
parent 688548ba2a
commit 03619abe6d
2 changed files with 868 additions and 1 deletions

View File

@@ -3,6 +3,12 @@
namespace Tests\Feature\ItemMaster;
use App\Models\ItemMaster\CustomTab;
use App\Models\ItemMaster\ItemBomItem;
use App\Models\ItemMaster\ItemField;
use App\Models\ItemMaster\ItemMasterField;
use App\Models\ItemMaster\ItemPage;
use App\Models\ItemMaster\ItemSection;
use App\Models\ItemMaster\SectionTemplate;
use App\Models\ItemMaster\UnitOption;
use App\Models\Members\User;
use App\Models\Members\UserTenant;
@@ -368,4 +374,743 @@ public function test_cannot_access_without_api_key(): void
// 테스트 환경 특성상 이 테스트는 스킵하거나 다르게 작성 필요
$this->assertTrue(true, 'API Key validation works in production');
}
// ==================== ItemPage Tests ====================
public function test_can_list_item_pages(): void
{
ItemPage::create([
'page_name' => 'Test Page 1',
'item_type' => 'FG',
'order_no' => 1,
'is_active' => true,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('get', '/api/v1/item-master/pages');
$response->assertStatus(200)
->assertJsonStructure([
'success',
'message',
'data' => [
'*' => [
'id',
'page_name',
'item_type',
'is_active',
],
],
]);
}
public function test_can_create_item_page(): void
{
$response = $this->authenticatedRequest('post', '/api/v1/item-master/pages', [
'page_name' => 'New Test Page',
'item_type' => 'FG',
'order_no' => 1,
'is_active' => true,
]);
$response->assertStatus(200)
->assertJsonStructure([
'success',
'message',
'data' => [
'id',
'page_name',
'item_type',
],
]);
$this->assertDatabaseHas('item_pages', [
'page_name' => 'New Test Page',
'item_type' => 'FG',
'tenant_id' => $this->tenant->id,
]);
}
public function test_can_update_item_page(): void
{
$page = ItemPage::create([
'page_name' => 'Original Page',
'item_type' => 'FG',
'order_no' => 1,
'is_active' => true,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('put', "/api/v1/item-master/pages/{$page->id}", [
'page_name' => 'Updated Page',
]);
$response->assertStatus(200);
$this->assertDatabaseHas('item_pages', [
'id' => $page->id,
'page_name' => 'Updated Page',
]);
}
public function test_can_delete_item_page(): void
{
$page = ItemPage::create([
'page_name' => 'Page to Delete',
'item_type' => 'FG',
'order_no' => 1,
'is_active' => true,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('delete', "/api/v1/item-master/pages/{$page->id}");
$response->assertStatus(200);
$this->assertSoftDeleted('item_pages', [
'id' => $page->id,
]);
}
// ==================== ItemSection Tests ====================
public function test_can_create_item_section(): void
{
$page = ItemPage::create([
'page_name' => 'Test Page',
'item_type' => 'FG',
'order_no' => 1,
'is_active' => true,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('post', "/api/v1/item-master/pages/{$page->id}/sections", [
'title' => 'Test Section',
'type' => 'fields',
]);
$response->assertStatus(200)
->assertJsonStructure([
'success',
'message',
'data' => [
'id',
'title',
'type',
],
]);
$this->assertDatabaseHas('item_sections', [
'title' => 'Test Section',
'page_id' => $page->id,
'tenant_id' => $this->tenant->id,
]);
}
public function test_can_update_item_section(): void
{
$page = ItemPage::create([
'page_name' => 'Test Page',
'item_type' => 'FG',
'order_no' => 1,
'is_active' => true,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$section = ItemSection::create([
'page_id' => $page->id,
'title' => 'Original Section',
'type' => 'fields',
'order_no' => 1,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('put', "/api/v1/item-master/sections/{$section->id}", [
'title' => 'Updated Section',
]);
$response->assertStatus(200);
$this->assertDatabaseHas('item_sections', [
'id' => $section->id,
'title' => 'Updated Section',
]);
}
public function test_can_delete_item_section(): void
{
$page = ItemPage::create([
'page_name' => 'Test Page',
'item_type' => 'FG',
'order_no' => 1,
'is_active' => true,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$section = ItemSection::create([
'page_id' => $page->id,
'title' => 'Section to Delete',
'type' => 'fields',
'order_no' => 1,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('delete', "/api/v1/item-master/sections/{$section->id}");
$response->assertStatus(200);
$this->assertSoftDeleted('item_sections', [
'id' => $section->id,
]);
}
public function test_can_reorder_item_sections(): void
{
$page = ItemPage::create([
'page_name' => 'Test Page',
'item_type' => 'FG',
'order_no' => 1,
'is_active' => true,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$section1 = ItemSection::create([
'page_id' => $page->id,
'title' => 'Section 1',
'type' => 'fields',
'order_no' => 1,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$section2 = ItemSection::create([
'page_id' => $page->id,
'title' => 'Section 2',
'type' => 'fields',
'order_no' => 2,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('put', "/api/v1/item-master/pages/{$page->id}/sections/reorder", [
'items' => [
['id' => $section2->id, 'order_no' => 1],
['id' => $section1->id, 'order_no' => 2],
],
]);
$response->assertStatus(200);
$this->assertDatabaseHas('item_sections', [
'id' => $section1->id,
'order_no' => 2,
]);
$this->assertDatabaseHas('item_sections', [
'id' => $section2->id,
'order_no' => 1,
]);
}
// ==================== ItemField Tests ====================
public function test_can_create_item_field(): void
{
$page = ItemPage::create([
'page_name' => 'Test Page',
'item_type' => 'FG',
'order_no' => 1,
'is_active' => true,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$section = ItemSection::create([
'page_id' => $page->id,
'title' => 'Test Section',
'type' => 'fields',
'order_no' => 1,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('post', "/api/v1/item-master/sections/{$section->id}/fields", [
'field_name' => 'test_field',
'field_type' => 'textbox',
]);
$response->assertStatus(200)
->assertJsonStructure([
'success',
'message',
'data' => [
'id',
'field_name',
'field_type',
],
]);
$this->assertDatabaseHas('item_fields', [
'field_name' => 'test_field',
'field_type' => 'textbox',
'section_id' => $section->id,
'tenant_id' => $this->tenant->id,
]);
}
public function test_can_update_item_field(): void
{
$page = ItemPage::create([
'page_name' => 'Test Page',
'item_type' => 'FG',
'order_no' => 1,
'is_active' => true,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$section = ItemSection::create([
'page_id' => $page->id,
'title' => 'Test Section',
'type' => 'fields',
'order_no' => 1,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$field = ItemField::create([
'section_id' => $section->id,
'field_name' => 'original_field',
'field_type' => 'textbox',
'order_no' => 1,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('put', "/api/v1/item-master/fields/{$field->id}", [
'field_name' => 'Updated Field',
'field_type' => 'number',
]);
$response->assertStatus(200);
$this->assertDatabaseHas('item_fields', [
'id' => $field->id,
'field_name' => 'Updated Field',
'field_type' => 'number',
]);
}
public function test_can_delete_item_field(): void
{
$page = ItemPage::create([
'page_name' => 'Test Page',
'item_type' => 'FG',
'order_no' => 1,
'is_active' => true,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$section = ItemSection::create([
'page_id' => $page->id,
'title' => 'Test Section',
'type' => 'fields',
'order_no' => 1,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$field = ItemField::create([
'section_id' => $section->id,
'field_name' => 'field_to_delete',
'field_type' => 'textbox',
'order_no' => 1,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('delete', "/api/v1/item-master/fields/{$field->id}");
$response->assertStatus(200);
$this->assertSoftDeleted('item_fields', [
'id' => $field->id,
]);
}
public function test_can_reorder_item_fields(): void
{
$page = ItemPage::create([
'page_name' => 'Test Page',
'item_type' => 'FG',
'order_no' => 1,
'is_active' => true,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$section = ItemSection::create([
'page_id' => $page->id,
'title' => 'Test Section',
'type' => 'fields',
'order_no' => 1,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$field1 = ItemField::create([
'section_id' => $section->id,
'field_name' => 'field_1',
'field_type' => 'textbox',
'order_no' => 1,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$field2 = ItemField::create([
'section_id' => $section->id,
'field_name' => 'field_2',
'field_type' => 'textbox',
'order_no' => 2,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('put', "/api/v1/item-master/sections/{$section->id}/fields/reorder", [
'items' => [
['id' => $field2->id, 'order_no' => 1],
['id' => $field1->id, 'order_no' => 2],
],
]);
$response->assertStatus(200);
$this->assertDatabaseHas('item_fields', [
'id' => $field1->id,
'order_no' => 2,
]);
$this->assertDatabaseHas('item_fields', [
'id' => $field2->id,
'order_no' => 1,
]);
}
// ==================== ItemBomItem Tests ====================
public function test_can_create_item_bom_item(): void
{
$page = ItemPage::create([
'page_name' => 'Test Page',
'item_type' => 'FG',
'order_no' => 1,
'is_active' => true,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$section = ItemSection::create([
'page_id' => $page->id,
'title' => 'Test Section',
'type' => 'bom',
'order_no' => 1,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('post', "/api/v1/item-master/sections/{$section->id}/bom-items", [
'item_name' => 'Test BOM Item',
]);
$response->assertStatus(200)
->assertJsonStructure([
'success',
'message',
'data' => [
'id',
'item_name',
],
]);
$this->assertDatabaseHas('item_bom_items', [
'item_name' => 'Test BOM Item',
'section_id' => $section->id,
'tenant_id' => $this->tenant->id,
]);
}
public function test_can_update_item_bom_item(): void
{
$page = ItemPage::create([
'page_name' => 'Test Page',
'item_type' => 'FG',
'order_no' => 1,
'is_active' => true,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$section = ItemSection::create([
'page_id' => $page->id,
'title' => 'Test Section',
'type' => 'bom',
'order_no' => 1,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$bomItem = ItemBomItem::create([
'section_id' => $section->id,
'item_name' => 'Original BOM Item',
'quantity' => 10,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('put', "/api/v1/item-master/bom-items/{$bomItem->id}", [
'item_name' => 'Updated BOM Item',
'quantity' => 20,
]);
$response->assertStatus(200);
$this->assertDatabaseHas('item_bom_items', [
'id' => $bomItem->id,
'item_name' => 'Updated BOM Item',
'quantity' => 20,
]);
}
public function test_can_delete_item_bom_item(): void
{
$page = ItemPage::create([
'page_name' => 'Test Page',
'item_type' => 'FG',
'order_no' => 1,
'is_active' => true,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$section = ItemSection::create([
'page_id' => $page->id,
'title' => 'Test Section',
'type' => 'bom',
'order_no' => 1,
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$bomItem = ItemBomItem::create([
'section_id' => $section->id,
'item_name' => 'BOM Item to Delete',
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('delete', "/api/v1/item-master/bom-items/{$bomItem->id}");
$response->assertStatus(200);
$this->assertSoftDeleted('item_bom_items', [
'id' => $bomItem->id,
]);
}
// ==================== SectionTemplate Tests ====================
public function test_can_list_section_templates(): void
{
SectionTemplate::create([
'title' => 'Test Template 1', 'type' => 'fields',
'description' => 'Test Description',
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('get', '/api/v1/item-master/section-templates');
$response->assertStatus(200)
->assertJsonStructure([
'success',
'message',
'data' => [
'*' => [
'id',
'title',
'description',
],
],
]);
}
public function test_can_create_section_template(): void
{
$response = $this->authenticatedRequest('post', '/api/v1/item-master/section-templates', [
'title' => 'New Template', 'type' => 'fields',
'description' => 'New Template Description',
]);
$response->assertStatus(200)
->assertJsonStructure([
'success',
'message',
'data' => [
'id',
'title',
'description',
],
]);
$this->assertDatabaseHas('section_templates', [
'title' => 'New Template', 'type' => 'fields',
'tenant_id' => $this->tenant->id,
]);
}
public function test_can_update_section_template(): void
{
$template = SectionTemplate::create([
'title' => 'Original Template', 'type' => 'fields',
'description' => 'Original Description',
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('put', "/api/v1/item-master/section-templates/{$template->id}", [
'title' => 'Updated Template',
'description' => 'Updated Description',
]);
$response->assertStatus(200);
$this->assertDatabaseHas('section_templates', [
'id' => $template->id,
'title' => 'Updated Template',
]);
}
public function test_can_delete_section_template(): void
{
$template = SectionTemplate::create([
'title' => 'Template to Delete', 'type' => 'fields',
'description' => 'Description',
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('delete', "/api/v1/item-master/section-templates/{$template->id}");
$response->assertStatus(200);
$this->assertSoftDeleted('section_templates', [
'id' => $template->id,
]);
}
// ==================== ItemMasterField Tests ====================
public function test_can_list_item_master_fields(): void
{
ItemMasterField::create([
'field_name' => 'test_field',
'field_type' => 'textbox',
'category' => 'general',
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('get', '/api/v1/item-master/master-fields');
$response->assertStatus(200)
->assertJsonStructure([
'success',
'message',
'data' => [
'*' => [
'id',
'field_name',
'field_type',
],
],
]);
}
public function test_can_create_item_master_field(): void
{
$response = $this->authenticatedRequest('post', '/api/v1/item-master/master-fields', [
'field_name' => 'new_field',
'field_type' => 'textbox',
]);
$response->assertStatus(200)
->assertJsonStructure([
'success',
'message',
'data' => [
'id',
'field_name',
'field_type',
],
]);
$this->assertDatabaseHas('item_master_fields', [
'field_name' => 'new_field',
'field_type' => 'textbox',
'tenant_id' => $this->tenant->id,
]);
}
public function test_can_update_item_master_field(): void
{
$field = ItemMasterField::create([
'field_name' => 'original_field',
'field_type' => 'textbox',
'category' => 'general',
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('put', "/api/v1/item-master/master-fields/{$field->id}", [
'field_name' => 'Updated Field',
'field_type' => 'number',
]);
$response->assertStatus(200);
$this->assertDatabaseHas('item_master_fields', [
'id' => $field->id,
'field_name' => 'Updated Field',
'field_type' => 'number',
]);
}
public function test_can_delete_item_master_field(): void
{
$field = ItemMasterField::create([
'field_name' => 'field_to_delete',
'field_type' => 'textbox',
'category' => 'general',
'tenant_id' => $this->tenant->id,
'created_by' => $this->user->id,
]);
$response = $this->authenticatedRequest('delete', "/api/v1/item-master/master-fields/{$field->id}");
$response->assertStatus(200);
$this->assertSoftDeleted('item_master_fields', [
'id' => $field->id,
]);
}
}