70 lines
2.5 KiB
PHP
70 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Modules\Helpdesk\Tests\Feature;
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Modules\Helpdesk\Models\Attachment;
|
|
use Modules\Helpdesk\Models\GitCommit;
|
|
use Modules\Helpdesk\Services\AttachmentService;
|
|
use Modules\Helpdesk\Tests\Concerns\BuildsHelpdeskFixtures;
|
|
use Tests\TestCase;
|
|
|
|
final class GitAndAttachmentTest extends TestCase
|
|
{
|
|
use BuildsHelpdeskFixtures;
|
|
use RefreshDatabase;
|
|
|
|
public function test_git_commit_can_be_tracked_against_repository_and_ticket(): void
|
|
{
|
|
$fixtures = $this->seedLookupData();
|
|
$repository = $this->repository(['project_id' => $fixtures['project']->id]);
|
|
$ticket = $this->ticket(['project_id' => $fixtures['project']->id]);
|
|
|
|
GitCommit::query()->create([
|
|
'repository_id' => $repository->id,
|
|
'ticket_id' => $ticket->id,
|
|
'hash' => str_repeat('b', 40),
|
|
'short_hash' => 'bbbbbbb',
|
|
'branch' => 'develop',
|
|
'author_name' => 'Mark Gregory',
|
|
'author_email' => 'mark@example.com',
|
|
'message' => 'Resolve '.$ticket->reference.' ticket save redirect',
|
|
'url' => 'https://example.com/commit/b',
|
|
'committed_at' => now(),
|
|
]);
|
|
|
|
$this->assertDatabaseHas('helpdesk_git_commits', [
|
|
'repository_id' => $repository->id,
|
|
'ticket_id' => $ticket->id,
|
|
'short_hash' => 'bbbbbbb',
|
|
]);
|
|
|
|
self::assertSame($ticket->id, $repository->commits()->firstOrFail()->ticket_id);
|
|
}
|
|
|
|
public function test_attachment_service_stores_and_deletes_ticket_files(): void
|
|
{
|
|
Storage::fake('local');
|
|
config()->set('helpdesk.disk', 'local');
|
|
|
|
$user = $this->user();
|
|
$ticket = $this->ticket(['owner' => $user]);
|
|
$file = UploadedFile::fake()->create('evidence.pdf', 32, 'application/pdf');
|
|
|
|
app(AttachmentService::class)->storeMany($ticket, [$file], $user->id);
|
|
|
|
$attachment = Attachment::query()->where('ticket_id', $ticket->id)->firstOrFail();
|
|
Storage::disk('local')->assertExists($attachment->path);
|
|
self::assertSame('evidence.pdf', $attachment->original_name);
|
|
|
|
app(AttachmentService::class)->delete($attachment);
|
|
|
|
Storage::disk('local')->assertMissing($attachment->path);
|
|
$this->assertDatabaseMissing('helpdesk_attachments', ['id' => $attachment->id]);
|
|
}
|
|
}
|