feat: L'Ami Fiduciaire V1.0.0 — full codebase with Story 0.1 complete
Initial commit of the L'Ami Fiduciaire SaaS platform built on Laravel 12, Vue 3, Inertia.js 2, and Tailwind CSS 4. Story 0.1 (rename folders to declarations in database) is implemented and code-reviewed: migration, rollback, and 6 Pest tests all passing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
152
tests/Feature/Client/ClientContactTest.php
Normal file
152
tests/Feature/Client/ClientContactTest.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\User;
|
||||
use App\Models\Workspace;
|
||||
|
||||
function createWorkspaceWithUser(): array
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$workspace = Workspace::factory()->create();
|
||||
$workspace->users()->attach($user, ['role' => 'owner']);
|
||||
|
||||
return [$user, $workspace];
|
||||
}
|
||||
|
||||
test('can store a client with a single contact', function () {
|
||||
[$user, $workspace] = createWorkspaceWithUser();
|
||||
session(['current_workspace_id' => $workspace->id]);
|
||||
|
||||
$response = $this->actingAs($user)->post(route('clients.store'), [
|
||||
'company_name' => 'Test SARL',
|
||||
'legal_form' => 'sarl',
|
||||
'contacts' => [
|
||||
[
|
||||
'full_name' => 'Ahmed Bennani',
|
||||
'job_title' => 'Gérant',
|
||||
'email' => 'ahmed@test.com',
|
||||
'phone' => '0612345678',
|
||||
'is_principal' => true,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertRedirect();
|
||||
$client = Client::query()->where('company_name', 'Test SARL')->first();
|
||||
expect($client)->not->toBeNull();
|
||||
expect($client->contacts)->toHaveCount(1);
|
||||
expect($client->contacts->first()->full_name)->toBe('Ahmed Bennani');
|
||||
expect($client->contacts->first()->is_principal)->toBeTrue();
|
||||
});
|
||||
|
||||
test('can store a client with multiple contacts', function () {
|
||||
[$user, $workspace] = createWorkspaceWithUser();
|
||||
session(['current_workspace_id' => $workspace->id]);
|
||||
|
||||
$response = $this->actingAs($user)->post(route('clients.store'), [
|
||||
'company_name' => 'Multi Contact SARL',
|
||||
'legal_form' => 'sarl',
|
||||
'contacts' => [
|
||||
[
|
||||
'full_name' => 'Contact A',
|
||||
'email' => 'a@test.com',
|
||||
'is_principal' => false,
|
||||
],
|
||||
[
|
||||
'full_name' => 'Contact B',
|
||||
'email' => 'b@test.com',
|
||||
'is_principal' => true,
|
||||
],
|
||||
[
|
||||
'full_name' => 'Contact C',
|
||||
'email' => 'c@test.com',
|
||||
'is_principal' => false,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertRedirect();
|
||||
$client = Client::query()->where('company_name', 'Multi Contact SARL')->first();
|
||||
expect($client->contacts)->toHaveCount(3);
|
||||
|
||||
$principal = $client->contacts->firstWhere('is_principal', true);
|
||||
expect($principal->full_name)->toBe('Contact B');
|
||||
});
|
||||
|
||||
test('store validation fails with no contacts', function () {
|
||||
[$user, $workspace] = createWorkspaceWithUser();
|
||||
session(['current_workspace_id' => $workspace->id]);
|
||||
|
||||
$response = $this->actingAs($user)->post(route('clients.store'), [
|
||||
'company_name' => 'No Contact SARL',
|
||||
'legal_form' => 'sarl',
|
||||
'contacts' => [],
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors('contacts');
|
||||
});
|
||||
|
||||
test('store validation fails with no principal contact', function () {
|
||||
[$user, $workspace] = createWorkspaceWithUser();
|
||||
session(['current_workspace_id' => $workspace->id]);
|
||||
|
||||
$response = $this->actingAs($user)->post(route('clients.store'), [
|
||||
'company_name' => 'No Principal SARL',
|
||||
'legal_form' => 'sarl',
|
||||
'contacts' => [
|
||||
['full_name' => 'Test', 'email' => 't@t.com', 'is_principal' => false],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors('contacts');
|
||||
});
|
||||
|
||||
test('store validation fails with multiple principal contacts', function () {
|
||||
[$user, $workspace] = createWorkspaceWithUser();
|
||||
session(['current_workspace_id' => $workspace->id]);
|
||||
|
||||
$response = $this->actingAs($user)->post(route('clients.store'), [
|
||||
'company_name' => 'Multi Principal SARL',
|
||||
'legal_form' => 'sarl',
|
||||
'contacts' => [
|
||||
['full_name' => 'A', 'email' => 'a@t.com', 'is_principal' => true],
|
||||
['full_name' => 'B', 'email' => 'b@t.com', 'is_principal' => true],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors('contacts');
|
||||
});
|
||||
|
||||
test('update can add and remove contacts', function () {
|
||||
[$user, $workspace] = createWorkspaceWithUser();
|
||||
session(['current_workspace_id' => $workspace->id]);
|
||||
|
||||
$client = Client::factory()->create(['workspace_id' => $workspace->id]);
|
||||
$existingContact = $client->contacts->first();
|
||||
|
||||
$response = $this->actingAs($user)->put(route('clients.update', $client), [
|
||||
'company_name' => $client->company_name,
|
||||
'legal_form' => $client->legal_form->value,
|
||||
'contacts' => [
|
||||
[
|
||||
'full_name' => 'New Contact',
|
||||
'email' => 'new@test.com',
|
||||
'is_principal' => true,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertRedirect();
|
||||
$client->refresh();
|
||||
expect($client->contacts)->toHaveCount(1);
|
||||
expect($client->contacts->first()->full_name)->toBe('New Contact');
|
||||
expect(ClientContact::find($existingContact->id))->toBeNull();
|
||||
});
|
||||
|
||||
test('primary contact email accessor returns principal contact email', function () {
|
||||
$client = Client::factory()->create();
|
||||
$principal = $client->contacts->firstWhere('is_principal', true);
|
||||
|
||||
expect($client->primary_contact_email)->toBe($principal->email);
|
||||
});
|
||||
34
tests/Feature/Client/ClientEmailTest.php
Normal file
34
tests/Feature/Client/ClientEmailTest.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
|
||||
test('primary_contact_email returns principal contact email', function () {
|
||||
$client = Client::factory()->create();
|
||||
$principal = $client->contacts->firstWhere('is_principal', true);
|
||||
|
||||
expect($client->primary_contact_email)->toBe($principal->email);
|
||||
});
|
||||
|
||||
test('primary_contact_email falls back to old contact_email column', function () {
|
||||
$client = Client::factory()->create([
|
||||
'contact_email' => 'fallback@test.com',
|
||||
]);
|
||||
|
||||
// Remove all contacts to force fallback
|
||||
$client->contacts()->delete();
|
||||
$client->unsetRelation('primaryContact');
|
||||
|
||||
expect($client->primary_contact_email)->toBe('fallback@test.com');
|
||||
});
|
||||
|
||||
test('primary_contact_email returns null when no contact exists', function () {
|
||||
$client = Client::factory()->create([
|
||||
'contact_email' => null,
|
||||
]);
|
||||
|
||||
$client->contacts()->delete();
|
||||
$client->unsetRelation('primaryContact');
|
||||
|
||||
expect($client->primary_contact_email)->toBeNull();
|
||||
});
|
||||
Reference in New Issue
Block a user