TenantAtlas/apps/platform/database/factories/SupportRequestFactory.php
ahmido 6e3736a53f
Some checks failed
Main Confidence / confidence (push) Failing after 1m29s
Add in-app support request with context (#285)
## Summary
- add the first in-app support request flow with an immutable `SupportRequest` record, canonical context builder, submission service, and generated internal reference
- expose contextual support-request actions from the tenant dashboard and operation run surfaces, including audit logging and support-safe diagnostic capture rules
- add Pest coverage plus the `specs/246-support-request-context` artifacts for the new support-request slice

## Testing
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/SupportRequests/OperationRunSupportRequestActionTest.php tests/Feature/SupportRequests/SupportRequestAuditTest.php tests/Feature/SupportRequests/SupportRequestAuthorizationTest.php tests/Feature/SupportRequests/TenantSupportRequestActionTest.php tests/Unit/Support/SupportRequests/SupportRequestContextBuilderTest.php tests/Unit/Support/SupportRequests/SupportRequestReferenceTest.php`

## Notes
- this PR supersedes the earlier session-branch PR opened from `246-support-request-context-session-1777289015`

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #285
2026-04-27 12:51:39 +00:00

99 lines
3.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Database\Factories;
use App\Models\OperationRun;
use App\Models\SupportRequest;
use App\Models\Tenant;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\SupportRequest>
*/
class SupportRequestFactory extends Factory
{
protected $model = SupportRequest::class;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'tenant_id' => Tenant::factory(),
'initiated_by_user_id' => User::factory(),
'internal_reference' => 'SR-'.strtoupper((string) Str::ulid()),
'primary_context_type' => SupportRequest::PRIMARY_CONTEXT_TENANT,
'attachment_mode' => SupportRequest::ATTACHMENT_MODE_DIAGNOSTIC_SNAPSHOT_ATTACHED,
'severity' => SupportRequest::SEVERITY_NORMAL,
'summary' => fake()->sentence(),
'reproduction_notes' => fake()->optional()->paragraph(),
'contact_name' => fake()->name(),
'contact_email' => fake()->safeEmail(),
'context_envelope' => [
'schema_version' => 1,
'generated_from' => 'factory',
'attachment_mode' => SupportRequest::ATTACHMENT_MODE_DIAGNOSTIC_SNAPSHOT_ATTACHED,
'primary_context' => [
'type' => SupportRequest::PRIMARY_CONTEXT_TENANT,
],
'canonical_context' => [
'sections' => [],
],
'diagnostic_snapshot' => [
'sections' => [],
],
'omissions' => [],
],
];
}
public function canonicalContextOnly(): static
{
return $this->state(fn (array $attributes): array => [
'attachment_mode' => SupportRequest::ATTACHMENT_MODE_CANONICAL_CONTEXT_ONLY,
'context_envelope' => array_replace_recursive($attributes['context_envelope'] ?? [], [
'attachment_mode' => SupportRequest::ATTACHMENT_MODE_CANONICAL_CONTEXT_ONLY,
'diagnostic_snapshot' => null,
'omissions' => [[
'type' => 'diagnostic_snapshot',
'reason' => 'omitted_without_support_diagnostics_view',
]],
]),
]);
}
public function forOperationRun(OperationRun $operationRun): static
{
return $this->state(fn (): array => [
'tenant_id' => (int) $operationRun->tenant_id,
'workspace_id' => (int) $operationRun->workspace_id,
'operation_run_id' => (int) $operationRun->getKey(),
'primary_context_type' => SupportRequest::PRIMARY_CONTEXT_OPERATION_RUN,
'context_envelope' => [
'schema_version' => 1,
'generated_from' => 'factory',
'attachment_mode' => SupportRequest::ATTACHMENT_MODE_DIAGNOSTIC_SNAPSHOT_ATTACHED,
'primary_context' => [
'type' => SupportRequest::PRIMARY_CONTEXT_OPERATION_RUN,
'tenant_id' => (int) $operationRun->tenant_id,
'operation_run_id' => (int) $operationRun->getKey(),
],
'canonical_context' => [
'sections' => [],
],
'diagnostic_snapshot' => [
'sections' => [],
],
'omissions' => [],
],
]);
}
}