ldc-crm/tests/Client/CrmClientClaimTest.php

79 lines
2.1 KiB
PHP
Raw Permalink Normal View History

2025-08-26 09:34:58 +02:00
<?php
namespace Tests\Client;
2026-03-31 15:01:10 +02:00
use App\Lib\Helpers\FileHelper;
2025-08-26 09:34:58 +02:00
use App\Models\Claim as ModelsClaim;
use Illuminate\Http\UploadedFile;
2025-08-28 11:07:31 +02:00
use Illuminate\Support\Facades\Storage;
2025-08-26 09:34:58 +02:00
use LDC\LDCCRM\Exceptions\ValidationException;
2025-08-28 11:07:31 +02:00
use LDC\LDCCRM\Models\Claim;
2025-08-26 09:34:58 +02:00
class CrmClientClaimTest extends CrmClientTester
{
/**
* Create new claim.
*
* @return void
*/
public function testCreateClaim(): void
{
2025-08-28 11:07:31 +02:00
$image = UploadedFile::fake()->image('photo.jpg');
$base64 = base64_encode(file_get_contents($image->getRealPath()));
2025-08-26 09:34:58 +02:00
$this->assertTrue(Claim::setClaim(
'Jean',
'Bond',
'claim@hotmail.fr',
'Ceci est un message.',
1,
'10 rue des totos',
'Le Mans',
'72100',
2025-08-28 11:07:31 +02:00
$base64,
2025-08-26 09:34:58 +02:00
));
$this->assertTrue(ModelsClaim::query()->where('email', 'claim@hotmail.fr')->exists());
2025-08-28 11:07:31 +02:00
$claimModel = ModelsClaim::query()->where('email', 'claim@hotmail.fr')->firstOrFail();
$this->assertNotEmpty($claimModel->file, 'The "file" field is empty on the Claim model.');
$this->assertTrue(
2026-03-31 15:01:10 +02:00
Storage::disk('private')->exists(FileHelper::getPrivateFilePath($claimModel->file)),
2025-08-28 11:07:31 +02:00
"The file does not exist: {$claimModel->file}"
);
2025-08-26 09:34:58 +02:00
}
/**
* Create new claim without optionnal fields.
*
* @return void
*/
public function testCreateClaimWithoutOptionnalFields(): void
{
$this->assertTrue(Claim::setClaim(
'Jean',
'Bond',
'claim@hotmail.fr',
'Ceci est un message.',
1,
));
$this->assertTrue(ModelsClaim::query()->where('email', 'claim@hotmail.fr')->exists());
}
/**
* Create new claim should fail.
*
* @return void
*/
public function testCreateClaimShouldFail(): void
{
$this->expectException(ValidationException::class);
Claim::setClaim(
'Jean',
'Bond',
'claim@hotmail.fr',
'Ceci est un message.',
0,
);
$this->assertSame(0, ModelsClaim::count());
}
}