feat(mcp) : add business tools — search, history, comments, custom fields, documents, model types
- search_inventory: global search across all 6 entity types - get_entity_history + get_activity_log: audit trail access - 4 comment tools: list, create, resolve, unresolved count - 3 custom field tools: list values, upsert, delete - 2 document tools: list, delete (upload via REST only) - 6 model type tools: list, get, create, update, delete, sync - 69 MCP tests pass total Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
101
tests/Mcp/Tool/CustomField/CustomFieldToolsTest.php
Normal file
101
tests/Mcp/Tool/CustomField/CustomFieldToolsTest.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Mcp\Tool\CustomField;
|
||||
|
||||
use App\Tests\AbstractApiTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class CustomFieldToolsTest extends AbstractApiTestCase
|
||||
{
|
||||
public function testListCustomFieldValues(): void
|
||||
{
|
||||
$machine = $this->createMachine(name: 'Machine CF');
|
||||
$customField = $this->createCustomField(name: 'Serial Number', type: 'text', machine: $machine);
|
||||
$this->createCustomFieldValue(customField: $customField, value: 'SN-12345', machine: $machine);
|
||||
|
||||
$session = $this->createMcpClient('ROLE_VIEWER');
|
||||
|
||||
$data = $this->callMcpTool($session, 'list_custom_field_values', [
|
||||
'entityType' => 'machine',
|
||||
'entityId' => $machine->getId(),
|
||||
]);
|
||||
|
||||
$this->assertArrayHasKey('_parsed', $data);
|
||||
$parsed = $data['_parsed'];
|
||||
$this->assertSame('machine', $parsed['entityType']);
|
||||
$this->assertSame($machine->getId(), $parsed['entityId']);
|
||||
$this->assertSame(1, $parsed['total']);
|
||||
$this->assertSame('SN-12345', $parsed['values'][0]['value']);
|
||||
$this->assertSame('Serial Number', $parsed['values'][0]['customFieldName']);
|
||||
$this->assertSame('text', $parsed['values'][0]['customFieldType']);
|
||||
}
|
||||
|
||||
public function testUpsertCustomFieldValues(): void
|
||||
{
|
||||
$machine = $this->createMachine(name: 'Machine Upsert');
|
||||
$customField = $this->createCustomField(name: 'Voltage', type: 'text', machine: $machine);
|
||||
|
||||
$session = $this->createMcpClient('ROLE_GESTIONNAIRE');
|
||||
|
||||
// Create
|
||||
$data = $this->callMcpTool($session, 'upsert_custom_field_values', [
|
||||
'entityType' => 'machine',
|
||||
'entityId' => $machine->getId(),
|
||||
'fields' => [
|
||||
['customFieldId' => $customField->getId(), 'value' => '220V'],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertArrayHasKey('_parsed', $data);
|
||||
$parsed = $data['_parsed'];
|
||||
$this->assertSame(1, $parsed['total']);
|
||||
$this->assertSame('created', $parsed['results'][0]['action']);
|
||||
$this->assertSame('220V', $parsed['results'][0]['value']);
|
||||
|
||||
$createdId = $parsed['results'][0]['id'];
|
||||
|
||||
// Update (upsert same field)
|
||||
$data = $this->callMcpTool($session, 'upsert_custom_field_values', [
|
||||
'entityType' => 'machine',
|
||||
'entityId' => $machine->getId(),
|
||||
'fields' => [
|
||||
['customFieldId' => $customField->getId(), 'value' => '380V'],
|
||||
],
|
||||
]);
|
||||
|
||||
$parsed = $data['_parsed'];
|
||||
$this->assertSame('updated', $parsed['results'][0]['action']);
|
||||
$this->assertSame('380V', $parsed['results'][0]['value']);
|
||||
$this->assertSame($createdId, $parsed['results'][0]['id']);
|
||||
}
|
||||
|
||||
public function testDeleteCustomFieldValue(): void
|
||||
{
|
||||
$machine = $this->createMachine(name: 'Machine Delete CF');
|
||||
$customField = $this->createCustomField(name: 'Weight', type: 'text', machine: $machine);
|
||||
$cfv = $this->createCustomFieldValue(customField: $customField, value: '150kg', machine: $machine);
|
||||
|
||||
$session = $this->createMcpClient('ROLE_GESTIONNAIRE');
|
||||
|
||||
$data = $this->callMcpTool($session, 'delete_custom_field_value', [
|
||||
'customFieldValueId' => $cfv->getId(),
|
||||
]);
|
||||
|
||||
$this->assertArrayHasKey('_parsed', $data);
|
||||
$parsed = $data['_parsed'];
|
||||
$this->assertTrue($parsed['deleted']);
|
||||
$this->assertSame($cfv->getId(), $parsed['id']);
|
||||
|
||||
// Verify it's gone
|
||||
$listData = $this->callMcpTool($session, 'list_custom_field_values', [
|
||||
'entityType' => 'machine',
|
||||
'entityId' => $machine->getId(),
|
||||
]);
|
||||
|
||||
$this->assertSame(0, $listData['_parsed']['total']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user