refactor: replace custom CRM with Monica fork
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s

This commit is contained in:
Kroonk
2026-05-22 16:19:55 +02:00
parent 38cc4c09ca
commit a213a1dba0
2215 changed files with 242567 additions and 6015 deletions

View File

@@ -0,0 +1,163 @@
<?php
namespace Tests\Unit\Services\Contact\Relationship;
use Tests\TestCase;
use App\Models\Account\Account;
use App\Models\Contact\Contact;
use App\Models\Relationship\RelationshipType;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use App\Services\Contact\Relationship\CreateRelationship;
class CreateRelationshipTest extends TestCase
{
use DatabaseTransactions;
/** @test */
public function it_stores_a_relationship()
{
$account = factory(Account::class)->create();
$contact = factory(Contact::class)->create([
'account_id' => $account->id,
]);
$otherContact = factory(Contact::class)->create([
'account_id' => $account->id,
]);
$relationshipType = factory(RelationshipType::class)->create([
'account_id' => $account->id,
]);
$request = [
'contact_is' => $contact->id,
'of_contact' => $otherContact->id,
'account_id' => $account->id,
'relationship_type_id' => $relationshipType->id,
];
$relationship = app(CreateRelationship::class)->execute($request);
$this->assertDatabaseHas('relationships', [
'id' => $relationship->id,
'account_id' => $account->id,
'relationship_type_id' => $relationshipType->id,
'contact_is' => $contact->id,
'of_contact' => $otherContact->id,
]);
}
/** @test */
public function it_fails_adding_relationship_when_relationship_type_is_unknown()
{
$account = factory(Account::class)->create();
$contact = factory(Contact::class)->create([
'account_id' => $account->id,
]);
$otherContact = factory(Contact::class)->create([
'account_id' => $account->id,
]);
$relationshipType = factory(RelationshipType::class)->create();
$request = [
'contact_is' => $contact->id,
'of_contact' => $otherContact->id,
'account_id' => $account->id,
'relationship_type_id' => $relationshipType->id,
];
$this->expectException(ModelNotFoundException::class);
app(CreateRelationship::class)->execute($request);
}
/** @test */
public function it_throws_an_exception_if_contact_is_not_linked_to_account()
{
$account = factory(Account::class)->create();
$contact = factory(Contact::class)->create();
$otherContact = factory(Contact::class)->create([
'account_id' => $account->id,
]);
$relationshipType = factory(RelationshipType::class)->create([
'account_id' => $account->id,
]);
$request = [
'contact_is' => $contact->id,
'of_contact' => $otherContact->id,
'account_id' => $account->id,
'relationship_type_id' => $relationshipType->id,
];
$this->expectException(ModelNotFoundException::class);
app(CreateRelationship::class)->execute($request);
}
/** @test */
public function it_throws_an_exception_if_other_contact_is_not_linked_to_account()
{
$account = factory(Account::class)->create();
$contact = factory(Contact::class)->create([
'account_id' => $account->id,
]);
$otherContact = factory(Contact::class)->create();
$relationshipType = factory(RelationshipType::class)->create([
'account_id' => $account->id,
]);
$request = [
'contact_is' => $contact->id,
'of_contact' => $otherContact->id,
'account_id' => $account->id,
'relationship_type_id' => $relationshipType->id,
];
$this->expectException(ModelNotFoundException::class);
app(CreateRelationship::class)->execute($request);
}
/** @test */
public function it_creates_a_relationship_and_reverse()
{
$account = factory(Account::class)->create();
$contactA = factory(Contact::class)->create([
'account_id' => $account->id,
]);
$contactB = factory(Contact::class)->create([
'account_id' => $account->id,
]);
$relationshipTypeA = factory(RelationshipType::class)->create([
'account_id' => $account->id,
'name' => 'uncle',
'name_reverse_relationship' => 'nephew',
]);
$relationshipTypeB = factory(RelationshipType::class)->create([
'account_id' => $account->id,
'name' => 'nephew',
'name_reverse_relationship' => 'uncle',
]);
$request = [
'account_id' => $account->id,
'contact_is' => $contactA->id,
'of_contact' => $contactB->id,
'relationship_type_id' => $relationshipTypeA->id,
];
app(CreateRelationship::class)->execute($request);
$this->assertDatabaseHas('relationships', [
'account_id' => $account->id,
'contact_is' => $contactA->id,
'of_contact' => $contactB->id,
'relationship_type_id' => $relationshipTypeA->id,
]);
$this->assertDatabaseHas('relationships', [
'account_id' => $account->id,
'contact_is' => $contactB->id,
'of_contact' => $contactA->id,
'relationship_type_id' => $relationshipTypeB->id,
]);
}
}

View File

@@ -0,0 +1,262 @@
<?php
namespace Tests\Unit\Services\Contact\Relationship;
use Tests\TestCase;
use App\Models\Account\Account;
use App\Models\Contact\Contact;
use App\Models\Relationship\Relationship;
use App\Models\Relationship\RelationshipType;
use Illuminate\Validation\ValidationException;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use App\Services\Contact\Relationship\DestroyRelationship;
class DestroyRelationshipTest extends TestCase
{
use DatabaseTransactions;
/** @test */
public function it_destroys_a_relationship()
{
$contactA = factory(Contact::class)->create([]);
$contactB = factory(Contact::class)->create([
'account_id' => $contactA->account_id,
]);
$relationship = factory(Relationship::class)->create([
'account_id' => $contactA->account_id,
'contact_is' => $contactA,
'of_contact' => $contactB,
]);
$request = [
'account_id' => $contactA->account_id,
'relationship_id' => $relationship->id,
];
app(DestroyRelationship::class)->execute($request);
$this->assertDatabaseMissing('relationships', [
'id' => $relationship->id,
]);
}
/** @test */
public function it_destroys_a_relationship_and_reverse()
{
$contactA = factory(Contact::class)->create([]);
$contactB = factory(Contact::class)->create([
'account_id' => $contactA->account_id,
]);
$relationshipTypeA = factory(RelationshipType::class)->create([
'account_id' => $contactA->account_id,
'name' => 'uncle',
'name_reverse_relationship' => 'nephew',
]);
$relationshipA = factory(Relationship::class)->create([
'account_id' => $contactA->account_id,
'contact_is' => $contactA,
'of_contact' => $contactB,
'relationship_type_id' => $relationshipTypeA->id,
]);
$relationshipTypeB = factory(RelationshipType::class)->create([
'account_id' => $contactA->account_id,
'name' => 'nephew',
'name_reverse_relationship' => 'uncle',
]);
$relationshipB = factory(Relationship::class)->create([
'account_id' => $contactA->account_id,
'contact_is' => $contactB,
'of_contact' => $contactA,
'relationship_type_id' => $relationshipTypeB->id,
]);
$request = [
'account_id' => $contactA->account_id,
'relationship_id' => $relationshipA->id,
];
$this->assertDatabaseHas('relationships', [
'id' => $relationshipA->id,
]);
$this->assertDatabaseHas('relationships', [
'id' => $relationshipB->id,
]);
app(DestroyRelationship::class)->execute($request);
$this->assertDatabaseMissing('relationships', [
'id' => $relationshipA->id,
]);
$this->assertDatabaseMissing('relationships', [
'id' => $relationshipB->id,
]);
}
/** @test */
public function it_destroys_a_relationship_and_reverse_and_partial_contact()
{
$contactA = factory(Contact::class)->create([]);
$contactB = factory(Contact::class)->create([
'account_id' => $contactA->account_id,
'is_partial' => true,
]);
$relationshipTypeA = factory(RelationshipType::class)->create([
'account_id' => $contactA->account_id,
'name' => 'uncle',
'name_reverse_relationship' => 'nephew',
]);
$relationshipA = factory(Relationship::class)->create([
'account_id' => $contactA->account_id,
'contact_is' => $contactA,
'of_contact' => $contactB,
'relationship_type_id' => $relationshipTypeA->id,
]);
$relationshipTypeB = factory(RelationshipType::class)->create([
'account_id' => $contactA->account_id,
'name' => 'nephew',
'name_reverse_relationship' => 'uncle',
]);
$relationshipB = factory(Relationship::class)->create([
'account_id' => $contactA->account_id,
'contact_is' => $contactB,
'of_contact' => $contactA,
'relationship_type_id' => $relationshipTypeB->id,
]);
$request = [
'account_id' => $contactA->account_id,
'relationship_id' => $relationshipA->id,
];
$this->assertDatabaseHas('relationships', [
'id' => $relationshipA->id,
]);
$this->assertDatabaseHas('relationships', [
'id' => $relationshipB->id,
]);
app(DestroyRelationship::class)->execute($request);
$this->assertDatabaseMissing('relationships', [
'id' => $relationshipA->id,
]);
$this->assertDatabaseMissing('relationships', [
'id' => $relationshipB->id,
]);
$this->assertDatabaseMissing('contacts', [
'id' => $contactB->id,
'deleted_at' => null,
]);
}
/** @test */
public function it_fails_if_wrong_parameters_are_given()
{
$account = factory(Account::class)->create([]);
$request = [
'account_id' => $account->id,
];
$this->expectException(ValidationException::class);
app(DestroyRelationship::class)->execute($request);
}
/** @test */
public function it_throws_an_exception_if_relationship_is_not_linked_to_account()
{
$account = factory(Account::class)->create();
$relationship = factory(Relationship::class)->create([]);
$request = [
'account_id' => $account->id,
'relationship_id' => $relationship->id,
];
$this->expectException(ModelNotFoundException::class);
app(DestroyRelationship::class)->execute($request);
}
/** @test */
public function it_deletes_relationship_between_two_contacts_and_deletes_the_contact()
{
$account = factory(Account::class)->create([]);
$contact = factory(Contact::class)->create(['account_id' => $account->id]);
$partner = factory(Contact::class)->create([
'account_id' => $account->id,
'is_partial' => true,
]);
$relationshipType = factory(RelationshipType::class)->create([
'account_id' => $account->id,
]);
$relationship = factory(Relationship::class)->create([
'account_id' => $account->id,
'contact_is' => $contact->id,
'of_contact' => $partner->id,
'relationship_type_id' => $relationshipType->id,
]);
app(DestroyRelationship::class)->execute([
'account_id' => $account->id,
'relationship_id' => $relationship->id,
]);
$this->assertDatabaseMissing(
'relationships',
[
'contact_is' => $contact->id,
'of_contact' => $partner->id,
'relationship_type_id' => $relationshipType->id,
]
);
}
/** @test */
public function it_deletes_relationship_between_two_contacts_and_doesnt_delete_the_contact()
{
$account = factory(Account::class)->create([]);
$contact = factory(Contact::class)->create(['account_id' => $account->id]);
$partner = factory(Contact::class)->create([
'account_id' => $account->id,
'is_partial' => false,
]);
$relationshipType = factory(RelationshipType::class)->create([
'account_id' => $account->id,
]);
$relationship = factory(Relationship::class)->create([
'account_id' => $account->id,
'contact_is' => $contact->id,
'of_contact' => $partner->id,
'relationship_type_id' => $relationshipType->id,
]);
app(DestroyRelationship::class)->execute([
'account_id' => $account->id,
'relationship_id' => $relationship->id,
]);
$this->assertDatabaseMissing(
'relationships',
[
'contact_is' => $contact->id,
'of_contact' => $partner->id,
'relationship_type_id' => $relationshipType->id,
]
);
$this->assertDatabaseHas(
'contacts',
[
'id' => $partner->id,
]
);
}
}

View File

@@ -0,0 +1,157 @@
<?php
namespace Tests\Unit\Services\Contact\Relationship;
use Tests\TestCase;
use App\Models\Account\Account;
use App\Models\Contact\Contact;
use App\Models\Relationship\Relationship;
use App\Models\Relationship\RelationshipType;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use App\Services\Contact\Relationship\CreateRelationship;
use App\Services\Contact\Relationship\UpdateRelationship;
class UpdateRelationshipTest extends TestCase
{
use DatabaseTransactions;
/** @test */
public function it_updates_a_relationship()
{
$account = factory(Account::class)->create();
$contact = factory(Contact::class)->create([
'account_id' => $account->id,
]);
$otherContact = factory(Contact::class)->create([
'account_id' => $account->id,
]);
$relationshipType0 = factory(RelationshipType::class)->create([
'account_id' => $account->id,
'name' => 'son',
'name_reverse_relationship' => 'father',
]);
$relationshipType = factory(RelationshipType::class)->create([
'account_id' => $account->id,
'name' => $relationshipType0->name_reverse_relationship,
'name_reverse_relationship' => $relationshipType0->name,
]);
$request = [
'contact_is' => $contact->id,
'of_contact' => $otherContact->id,
'account_id' => $account->id,
'relationship_type_id' => $relationshipType->id,
];
$relationship = app(CreateRelationship::class)->execute($request);
$relationshipType0 = factory(RelationshipType::class)->create([
'account_id' => $account->id,
'name' => 'uncle',
'name_reverse_relationship' => 'nephew',
]);
$relationshipType = factory(RelationshipType::class)->create([
'account_id' => $account->id,
'name' => $relationshipType0->name_reverse_relationship,
'name_reverse_relationship' => $relationshipType0->name,
]);
$request = [
'account_id' => $account->id,
'relationship_id' => $relationship->id,
'relationship_type_id' => $relationshipType->id,
];
$newRelationship = app(UpdateRelationship::class)->execute($request);
$this->assertDatabaseHas('relationships', [
'id' => $newRelationship->id,
'account_id' => $account->id,
'relationship_type_id' => $relationshipType->id,
'contact_is' => $contact->id,
'of_contact' => $otherContact->id,
]);
}
/** @test */
public function it_updates_a_partial_relationship()
{
$account = factory(Account::class)->create();
$contact = factory(Contact::class)->create([
'account_id' => $account->id,
]);
$otherContact = factory(Contact::class)->create([
'account_id' => $account->id,
]);
$relationship = factory(Relationship::class)->create([
'account_id' => $account->id,
'contact_is' => $contact->id,
'of_contact' => $otherContact->id,
]);
$relationshipType0 = factory(RelationshipType::class)->create([
'account_id' => $account->id,
'name' => 'name',
]);
$relationshipType = factory(RelationshipType::class)->create([
'account_id' => $account->id,
'name_reverse_relationship' => $relationshipType0->name,
]);
$request = [
'account_id' => $account->id,
'relationship_id' => $relationship->id,
'relationship_type_id' => $relationshipType->id,
];
$newRelationship = app(UpdateRelationship::class)->execute($request);
$this->assertDatabaseHas('relationships', [
'id' => $newRelationship->id,
'account_id' => $account->id,
'relationship_type_id' => $relationshipType->id,
'contact_is' => $contact->id,
'of_contact' => $otherContact->id,
]);
}
/** @test */
public function it_throws_an_exception_if_relationship_is_not_linked_to_account()
{
$account = factory(Account::class)->create();
$relationship = factory(Relationship::class)->create();
$relationshipType = factory(RelationshipType::class)->create([
'account_id' => $account->id,
]);
$request = [
'account_id' => $account->id,
'relationship_id' => $relationship->id,
'relationship_type_id' => $relationshipType->id,
];
$this->expectException(ModelNotFoundException::class);
app(UpdateRelationship::class)->execute($request);
}
/** @test */
public function it_throws_an_exception_if_relationship_type_is_not_linked_to_account()
{
$account = factory(Account::class)->create();
$relationship = factory(Relationship::class)->create([
'account_id' => $account->id,
]);
$relationshipType = factory(RelationshipType::class)->create();
$request = [
'account_id' => $account->id,
'relationship_id' => $relationship->id,
'relationship_type_id' => $relationshipType->id,
];
$this->expectException(ModelNotFoundException::class);
app(UpdateRelationship::class)->execute($request);
}
}