ldc-crm/tests/Client/CrmClientClaimTest.php
2025-10-07 11:32:02 +02:00

80 lines
2.1 KiB
PHP

<?php
namespace Tests\Client;
use App\Models\Claim as ModelsClaim;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use LDC\LDCCRM\Exceptions\ValidationException;
use LDC\LDCCRM\Models\Claim;
class CrmClientClaimTest extends CrmClientTester
{
/**
* Create new claim.
*
* @return void
*/
public function testCreateClaim(): void
{
$image = UploadedFile::fake()->image('photo.jpg');
$base64 = base64_encode(file_get_contents($image->getRealPath()));
$this->assertTrue(Claim::setClaim(
'Jean',
'Bond',
'claim@hotmail.fr',
'Ceci est un message.',
1,
1,
'10 rue des totos',
'Le Mans',
'72100',
$base64,
));
$this->assertTrue(ModelsClaim::query()->where('email', 'claim@hotmail.fr')->exists());
$claimModel = ModelsClaim::query()->where('email', 'claim@hotmail.fr')->firstOrFail();
$this->assertNotEmpty($claimModel->file, 'The "file" field is empty on the Claim model.');
$this->assertTrue(
Storage::disk('public')->exists(str_replace('storage/', '', $claimModel->file)),
"The file does not exist: {$claimModel->file}"
);
}
/**
* 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,
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,
0,
);
$this->assertSame(0, ModelsClaim::count());
}
}