refactor: replace custom CRM with Monica fork
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
This commit is contained in:
55
tests/Unit/Services/Account/Gender/CreateGenderTest.php
Normal file
55
tests/Unit/Services/Account/Gender/CreateGenderTest.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Gender;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Contact\Gender;
|
||||
use App\Models\Account\Account;
|
||||
use App\Services\Account\Gender\CreateGender;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class CreateGenderTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_stores_a_gender()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'name' => 'man',
|
||||
'type' => 'M',
|
||||
];
|
||||
|
||||
$gender = app(CreateGender::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('genders', [
|
||||
'id' => $gender->id,
|
||||
'account_id' => $account->id,
|
||||
'name' => 'man',
|
||||
'type' => 'M',
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Gender::class,
|
||||
$gender
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'name' => 'man',
|
||||
'type' => 'X',
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(CreateGender::class)->execute($request);
|
||||
}
|
||||
}
|
||||
60
tests/Unit/Services/Account/Gender/DestroyGenderTest.php
Normal file
60
tests/Unit/Services/Account/Gender/DestroyGenderTest.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Gender;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Contact\Gender;
|
||||
use App\Models\Account\Account;
|
||||
use App\Services\Account\Gender\DestroyGender;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class DestroyGenderTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_destroys_a_gender()
|
||||
{
|
||||
$gender = factory(Gender::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $gender->account_id,
|
||||
'gender_id' => $gender->id,
|
||||
];
|
||||
|
||||
app(DestroyGender::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseMissing('genders', [
|
||||
'id' => $gender->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_account_is_not_linked_to_gender()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
$gender = factory(Gender::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'gender_id' => $gender->id,
|
||||
];
|
||||
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
app(DestroyGender::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_ids_do_not_exist()
|
||||
{
|
||||
$request = [
|
||||
'account_id' => 11111111,
|
||||
'gender_id' => 11111111,
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(DestroyGender::class)->execute($request);
|
||||
}
|
||||
}
|
||||
74
tests/Unit/Services/Account/Gender/UpdateGenderTest.php
Normal file
74
tests/Unit/Services/Account/Gender/UpdateGenderTest.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Gender;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Contact\Gender;
|
||||
use App\Models\Account\Account;
|
||||
use App\Services\Account\Gender\UpdateGender;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class UpdateGenderTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_updates_a_gender()
|
||||
{
|
||||
$gender = factory(Gender::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $gender->account_id,
|
||||
'gender_id' => $gender->id,
|
||||
'name' => 'man',
|
||||
'type' => 'M',
|
||||
];
|
||||
|
||||
$gender = app(UpdateGender::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('genders', [
|
||||
'id' => $gender->id,
|
||||
'account_id' => $gender->account_id,
|
||||
'name' => 'man',
|
||||
'type' => 'M',
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Gender::class,
|
||||
$gender
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$gender = factory(Gender::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'name' => 'man',
|
||||
'type' => 'X',
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(UpdateGender::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_place_is_not_linked_to_account()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
$gender = factory(Gender::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'gender_id' => $gender->id,
|
||||
'name' => 'man',
|
||||
'type' => 'M',
|
||||
];
|
||||
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
app(UpdateGender::class)->execute($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user