-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathSupportRoleRequestResolverTest.php
More file actions
80 lines (68 loc) · 3.07 KB
/
Copy pathSupportRoleRequestResolverTest.php
File metadata and controls
80 lines (68 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
namespace Tests\Unit\Support;
use App\Models\Support\SupportCase;
use App\Services\Support\SupportRoleRequestResolver;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
final class SupportRoleRequestResolverTest extends TestCase
{
use RefreshDatabase;
public function test_prefers_ai_triage_role_and_case_emails(): void
{
config(['support_ai.enabled' => true, 'support_ai.triage.enabled' => true]);
$case = SupportCase::create([
'source_channel' => 'gmail',
'processing_mode' => 'automated',
'subject' => 'add leading teachers',
'raw_message' => 'Please grant the role to the people below.',
'normalized_message' => 'Please grant the role to the people below.',
'target_email' => 'a@example.com',
'secondary_emails' => ['b@example.com', 'c@example.com'],
'case_type' => 'role_add',
'status' => 'diagnosed',
'risk_level' => 'low',
'correlation_id' => 'cid-ai',
]);
$case->actions()->create([
'action_name' => 'triage',
'action_type' => 'classification',
'input_json' => [],
'output_json' => [
'case_type' => 'role_add',
'role_name' => 'leading teacher',
'role_operation' => 'add',
],
'succeeded' => true,
'executed_by' => 'agent',
]);
$resolved = app(SupportRoleRequestResolver::class)->resolve($case);
$this->assertSame('leading teacher', $resolved['role']);
$this->assertSame('add', $resolved['operation']);
$this->assertSame(['a@example.com', 'b@example.com', 'c@example.com'], $resolved['emails']);
$this->assertSame('ai', $resolved['source']['mode']);
$this->assertSame('ai', $resolved['source']['role']);
$this->assertSame('ai', $resolved['source']['emails']);
}
public function test_uses_deterministic_parser_when_ai_disabled(): void
{
config(['support_ai.enabled' => false]);
$case = SupportCase::create([
'source_channel' => 'gmail',
'processing_mode' => 'automated',
'subject' => 'add leading teachers',
'raw_message' => "add role: leading teacher\nx@example.com\ny@example.com",
'normalized_message' => "add role: leading teacher\nx@example.com\ny@example.com",
'case_type' => 'role_add',
'status' => 'diagnosed',
'risk_level' => 'low',
'correlation_id' => 'cid-fallback',
]);
$resolved = app(SupportRoleRequestResolver::class)->resolve($case);
$this->assertSame('leading teacher', $resolved['role']);
$this->assertSame('add', $resolved['operation']);
$this->assertSame(['x@example.com', 'y@example.com'], $resolved['emails']);
$this->assertSame('deterministic', $resolved['source']['mode']);
$this->assertSame('parser', $resolved['source']['role']);
$this->assertSame('parser', $resolved['source']['emails']);
}
}