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:
@@ -0,0 +1,249 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Activity;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Contact\Contact;
|
||||
use App\Models\Account\Activity;
|
||||
use App\Models\Account\ActivityType;
|
||||
use App\Models\Account\ActivityStatistic;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use App\Services\Account\Activity\ActivityStatisticService;
|
||||
|
||||
class ActivityStatisticServiceTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_gets_a_list_of_activities_since_a_given_number_of_months()
|
||||
{
|
||||
$service = new ActivityStatisticService;
|
||||
$contact = factory(Contact::class)->create();
|
||||
|
||||
for ($i = 0; $i <= 2; $i++) {
|
||||
$activity = factory(Activity::class)->create([
|
||||
'happened_at' => now()->subMonth(),
|
||||
'account_id' => $contact->account_id,
|
||||
]);
|
||||
$contact->activities()->attach($activity, ['account_id' => $contact->account_id]);
|
||||
}
|
||||
|
||||
$this->assertCount(
|
||||
3,
|
||||
$service->activitiesWithContactInTimeRange($contact, now()->subMonths(2), now())
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Activity::class,
|
||||
$service->activitiesWithContactInTimeRange($contact, now()->subMonths(2), now())[1]
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_an_empty_list_of_activities()
|
||||
{
|
||||
$service = new ActivityStatisticService;
|
||||
$contact = factory(Contact::class)->create();
|
||||
|
||||
for ($i = 0; $i <= 2; $i++) {
|
||||
$activity = factory(Activity::class)->create([
|
||||
'happened_at' => now()->subYears(2),
|
||||
'account_id' => $contact->account_id,
|
||||
]);
|
||||
$contact->activities()->attach($activity, ['account_id' => $contact->account_id]);
|
||||
}
|
||||
|
||||
$this->assertCount(
|
||||
0,
|
||||
$service->activitiesWithContactInTimeRange($contact, now()->subMonths(2), now())
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_a_list_of_unique_activity_types()
|
||||
{
|
||||
$service = new ActivityStatisticService;
|
||||
$account = factory(Account::class)->create();
|
||||
$contact = factory(Contact::class)->create([
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
|
||||
// creation of 3 activities with a given activity type
|
||||
$activityType = factory(ActivityType::class)->create([
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
|
||||
for ($i = 0; $i <= 2; $i++) {
|
||||
$activity = factory(Activity::class)->create([
|
||||
'happened_at' => now(),
|
||||
'account_id' => $account->id,
|
||||
'activity_type_id' => $activityType->id,
|
||||
]);
|
||||
$contact->activities()->attach($activity, ['account_id' => $contact->account_id]);
|
||||
}
|
||||
|
||||
// creation of 1 activity with a given activity type
|
||||
$activityType = factory(ActivityType::class)->create([
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
|
||||
$activity = factory(Activity::class)->create([
|
||||
'happened_at' => now(),
|
||||
'account_id' => $account->id,
|
||||
'activity_type_id' => $activityType->id,
|
||||
]);
|
||||
$contact->activities()->attach($activity, ['account_id' => $contact->account_id]);
|
||||
|
||||
// here we should have 2 uniques activity types, one with 3 and the other with 1 occurence
|
||||
$response = $service->uniqueActivityTypesInTimeRange($contact, now()->subMonths(2), now());
|
||||
|
||||
$this->assertCount(
|
||||
2,
|
||||
$response
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
ActivityType::class,
|
||||
$response[0]['object']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
3,
|
||||
$response[0]['occurences']
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
ActivityType::class,
|
||||
$response[1]['object']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$response[1]['occurences']
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_the_breakdown_of_activities_per_year()
|
||||
{
|
||||
$service = new ActivityStatisticService;
|
||||
$account = factory(Account::class)->create();
|
||||
$contact = factory(Contact::class)->create([
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
|
||||
for ($i = 0; $i <= 2; $i++) {
|
||||
$activity = factory(Activity::class)->create([
|
||||
'happened_at' => now()->subYears(2),
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
$contact->activities()->attach($activity, ['account_id' => $contact->account_id]);
|
||||
}
|
||||
|
||||
for ($i = 0; $i <= 5; $i++) {
|
||||
$activity = factory(Activity::class)->create([
|
||||
'happened_at' => now(),
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
$contact->activities()->attach($activity, ['account_id' => $contact->account_id]);
|
||||
}
|
||||
|
||||
$activityStatistic = $contact->activityStatistics()->make();
|
||||
$activityStatistic->account_id = $contact->account_id;
|
||||
$activityStatistic->contact_id = $contact->id;
|
||||
$activityStatistic->year = now()->year;
|
||||
$activityStatistic->count = 6;
|
||||
$activityStatistic->save();
|
||||
|
||||
$activityStatistic = $contact->activityStatistics()->make();
|
||||
$activityStatistic->account_id = $contact->account_id;
|
||||
$activityStatistic->contact_id = $contact->id;
|
||||
$activityStatistic->year = now()->subYears(2)->year;
|
||||
$activityStatistic->count = 3;
|
||||
$activityStatistic->save();
|
||||
|
||||
$response = $service->activitiesPerYearWithContact($contact);
|
||||
|
||||
$this->assertCount(
|
||||
2,
|
||||
$response
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
6,
|
||||
$response[0]->count
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
3,
|
||||
$response[1]->count
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
ActivityStatistic::class,
|
||||
$response[0]
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_a_list_of_activities_per_month_for_given_year()
|
||||
{
|
||||
$service = new ActivityStatisticService;
|
||||
$account = factory(Account::class)->create();
|
||||
$contact = factory(Contact::class)->create([
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
|
||||
Carbon::setTestNow(Carbon::create(2017, 1, 1));
|
||||
|
||||
for ($i = 0; $i <= 2; $i++) {
|
||||
$activity = factory(Activity::class)->create([
|
||||
'happened_at' => '2017-01-02',
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
$contact->activities()->attach($activity, ['account_id' => $contact->account_id]);
|
||||
}
|
||||
|
||||
for ($i = 0; $i <= 5; $i++) {
|
||||
$activity = factory(Activity::class)->create([
|
||||
'happened_at' => '2017-02-01',
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
$contact->activities()->attach($activity, ['account_id' => $contact->account_id]);
|
||||
}
|
||||
|
||||
$response = $service->activitiesPerMonthForYear($contact, 2017);
|
||||
|
||||
$this->assertCount(
|
||||
12,
|
||||
$response
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$response[0]['month']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
3,
|
||||
$response[0]['occurences']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
2,
|
||||
$response[1]['month']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
6,
|
||||
$response[1]['occurences']
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Activity::class,
|
||||
$response[1]['activities'][0]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Activity\ActivityType;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Account\ActivityType;
|
||||
use App\Models\Account\ActivityTypeCategory;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Services\Account\Activity\ActivityType\CreateActivityType;
|
||||
|
||||
class CreateActivityTypeTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_stores_an_activity_type()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
$activityTypeCategory = factory(ActivityTypeCategory::class)->create([
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'activity_type_category_id' => $activityTypeCategory->id,
|
||||
'name' => 'central perk',
|
||||
'translation_key' => 'central_perk',
|
||||
];
|
||||
|
||||
$activityType = app(CreateActivityType::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('activity_types', [
|
||||
'id' => $activityType->id,
|
||||
'account_id' => $account->id,
|
||||
'activity_type_category_id' => $activityTypeCategory->id,
|
||||
'name' => 'central perk',
|
||||
'translation_key' => 'central_perk',
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
ActivityType::class,
|
||||
$activityType
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$request = [
|
||||
'name' => '199 Lafayette Street',
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(CreateActivityType::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_activity_type_category_is_not_linked_to_account()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
$activityTypeCategory = factory(ActivityTypeCategory::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'activity_type_category_id' => $activityTypeCategory->id,
|
||||
'name' => 'central perk',
|
||||
'translation_key' => 'central_perk',
|
||||
];
|
||||
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
app(CreateActivityType::class)->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Activity\ActivityType;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Account\ActivityType;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Services\Account\Activity\ActivityType\DestroyActivityType;
|
||||
|
||||
class DestroyActivityTypeTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_destroys_a_activity_type()
|
||||
{
|
||||
$activityType = factory(ActivityType::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $activityType->account_id,
|
||||
'activity_type_id' => $activityType->id,
|
||||
];
|
||||
|
||||
app(DestroyActivityType::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseMissing('activity_types', [
|
||||
'id' => $activityType->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_account_is_not_linked_to_activity_type()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
$activityType = factory(ActivityType::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'activity_type_id' => $activityType->id,
|
||||
];
|
||||
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
app(DestroyActivityType::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_ids_do_not_exist()
|
||||
{
|
||||
$request = [
|
||||
'account_id' => 11111111,
|
||||
'activity_type_id' => 11111111,
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(DestroyActivityType::class)->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Activity\ActivityType;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Account\ActivityType;
|
||||
use App\Models\Account\ActivityTypeCategory;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Services\Account\Activity\ActivityType\UpdateActivityType;
|
||||
|
||||
class UpdateActivityTypeTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_updates_an_activity_type()
|
||||
{
|
||||
$activityType = factory(ActivityType::class)->create([]);
|
||||
$activityTypeCategory = factory(ActivityTypeCategory::class)->create([
|
||||
'account_id' => $activityType->account_id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $activityType->account_id,
|
||||
'activity_type_id' => $activityType->id,
|
||||
'activity_type_category_id' => $activityTypeCategory->id,
|
||||
'name' => 'Chandler House',
|
||||
'translation_key' => 'https://centralperk.com',
|
||||
];
|
||||
|
||||
$activityType = app(UpdateActivityType::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('activity_types', [
|
||||
'id' => $activityType->id,
|
||||
'account_id' => $activityType->account_id,
|
||||
'activity_type_category_id' => $activityTypeCategory->id,
|
||||
'name' => 'Chandler House',
|
||||
'translation_key' => 'https://centralperk.com',
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
ActivityType::class,
|
||||
$activityType
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$activityType = factory(ActivityType::class)->create([]);
|
||||
$activityTypeCategory = factory(ActivityTypeCategory::class)->create([
|
||||
'account_id' => $activityType->account_id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $activityType->account_id,
|
||||
'activity_type_category_id' => $activityTypeCategory->id,
|
||||
'name' => 'Chandler House',
|
||||
'translation_key' => 'https://centralperk.com',
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(UpdateActivityType::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_activity_is_not_linked_to_account()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
$activityType = factory(ActivityType::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'activity_type_id' => $activityType->id,
|
||||
'activity_type_category_id' => $activityType->activity_type_category_id,
|
||||
'name' => 'Chandler House',
|
||||
'translation_key' => 'https://centralperk.com',
|
||||
];
|
||||
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
app(UpdateActivityType::class)->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Activity\ActivityTypeCategory;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Account\ActivityTypeCategory;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use App\Services\Account\Activity\ActivityTypeCategory\CreateActivityTypeCategory;
|
||||
|
||||
class CreateActivityTypeCategoryTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_stores_an_activity_type_category()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'name' => 'central perk',
|
||||
'translation_key' => 'central_perk',
|
||||
];
|
||||
|
||||
$activityTypeCategory = app(CreateActivityTypeCategory::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('activity_type_categories', [
|
||||
'id' => $activityTypeCategory->id,
|
||||
'account_id' => $account->id,
|
||||
'name' => 'central perk',
|
||||
'translation_key' => 'central_perk',
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
ActivityTypeCategory::class,
|
||||
$activityTypeCategory
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$request = [
|
||||
'name' => '199 Lafayette Street',
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(CreateActivityTypeCategory::class)->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Activity\ActivityTypeCategory;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Account\ActivityTypeCategory;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Services\Account\Activity\ActivityTypeCategory\DestroyActivityTypeCategory;
|
||||
|
||||
class DestroyActivityTypeCategoryTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_destroys_a_activity_type_category()
|
||||
{
|
||||
$activityTypeCategory = factory(ActivityTypeCategory::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $activityTypeCategory->account_id,
|
||||
'activity_type_category_id' => $activityTypeCategory->id,
|
||||
];
|
||||
|
||||
app(DestroyActivityTypeCategory::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseMissing('activity_type_categories', [
|
||||
'id' => $activityTypeCategory->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_account_is_not_linked_to_activity_type_category()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
$activityTypeCategory = factory(ActivityTypeCategory::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'activity_type_category_id' => $activityTypeCategory->id,
|
||||
];
|
||||
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
app(DestroyActivityTypeCategory::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_ids_do_not_exist()
|
||||
{
|
||||
$request = [
|
||||
'account_id' => 11111111,
|
||||
'activity_type_category_id' => 11111111,
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(DestroyActivityTypeCategory::class)->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Activity\ActivityTypeCategory;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Account\ActivityTypeCategory;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Services\Account\Activity\ActivityTypeCategory\UpdateActivityTypeCategory;
|
||||
|
||||
class UpdateActivityTypeCategoryTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_updates_a_activity_type_category()
|
||||
{
|
||||
$activityTypeCategory = factory(ActivityTypeCategory::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $activityTypeCategory->account_id,
|
||||
'activity_type_category_id' => $activityTypeCategory->id,
|
||||
'name' => 'Chandler House',
|
||||
'translation_key' => 'https://centralperk.com',
|
||||
];
|
||||
|
||||
$activityTypeCategory = app(UpdateActivityTypeCategory::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('activity_type_categories', [
|
||||
'id' => $activityTypeCategory->id,
|
||||
'account_id' => $activityTypeCategory->account_id,
|
||||
'name' => 'Chandler House',
|
||||
'translation_key' => 'https://centralperk.com',
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
ActivityTypeCategory::class,
|
||||
$activityTypeCategory
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$activityTypeCategory = factory(ActivityTypeCategory::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'name' => '199 Lafayette Street',
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(UpdateActivityTypeCategory::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_activity_is_not_linked_to_account()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
$activityTypeCategory = factory(ActivityTypeCategory::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'activity_type_category_id' => $activityTypeCategory->id,
|
||||
'name' => '199 Lafayette Street',
|
||||
];
|
||||
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
app(UpdateActivityTypeCategory::class)->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Activity;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Contact\Contact;
|
||||
use App\Models\Account\Activity;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Services\Account\Activity\Activity\AttachContactToActivity;
|
||||
|
||||
class AttachContactToActivityTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_attaches_contacts()
|
||||
{
|
||||
$activity = factory(Activity::class)->create([]);
|
||||
$contactA = factory(Contact::class)->create([
|
||||
'account_id' => $activity->account_id,
|
||||
]);
|
||||
$contactB = factory(Contact::class)->create([
|
||||
'account_id' => $activity->account_id,
|
||||
]);
|
||||
$contactC = factory(Contact::class)->create([
|
||||
'account_id' => $activity->account_id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $activity->account_id,
|
||||
'activity_id' => $activity->id,
|
||||
'contacts' => [$contactA->id, $contactB->id, $contactC->id],
|
||||
];
|
||||
|
||||
$activity = app(AttachContactToActivity::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('activity_contact', [
|
||||
'activity_id' => $activity->id,
|
||||
'contact_id' => $contactA->id,
|
||||
'account_id' => $activity->account_id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('activity_contact', [
|
||||
'activity_id' => $activity->id,
|
||||
'contact_id' => $contactB->id,
|
||||
'account_id' => $activity->account_id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('activity_contact', [
|
||||
'activity_id' => $activity->id,
|
||||
'contact_id' => $contactC->id,
|
||||
'account_id' => $activity->account_id,
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Activity::class,
|
||||
$activity
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$activity = factory(Activity::class)->create([]);
|
||||
$contactA = factory(Contact::class)->create([
|
||||
'account_id' => $activity->account_id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'activity_id' => $activity->id,
|
||||
'contacts' => [$contactA->id],
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(AttachContactToActivity::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_contact_is_not_linked_to_account()
|
||||
{
|
||||
$activity = factory(Activity::class)->create([]);
|
||||
$account = factory(Account::class)->create([]);
|
||||
$contactA = factory(Contact::class)->create([
|
||||
'account_id' => $activity->account_id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'activity_id' => $activity->id,
|
||||
'account_id' => $account->id,
|
||||
'contacts' => [$contactA->id],
|
||||
];
|
||||
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
app(AttachContactToActivity::class)->execute($request);
|
||||
}
|
||||
}
|
||||
149
tests/Unit/Services/Account/Activity/CreateActivityTest.php
Normal file
149
tests/Unit/Services/Account/Activity/CreateActivityTest.php
Normal file
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Activity;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Contact\Contact;
|
||||
use App\Models\Account\Activity;
|
||||
use App\Models\Account\ActivityType;
|
||||
use App\Models\Instance\Emotion\Emotion;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Services\Account\Activity\Activity\CreateActivity;
|
||||
|
||||
class CreateActivityTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_stores_an_activity_and_creates_an_entry_in_the_journal()
|
||||
{
|
||||
$account = factory(Account::class)->create();
|
||||
$contacts = factory(Contact::class, 3)->create([
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
$activityType = factory(ActivityType::class)->create([
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'activity_type_id' => $activityType->id,
|
||||
'summary' => 'we went to central perk',
|
||||
'description' => 'it was awesome',
|
||||
'happened_at' => '2009-09-09',
|
||||
'contacts' => $contacts->map(function ($contact) {
|
||||
return $contact->id;
|
||||
})->toArray(),
|
||||
];
|
||||
|
||||
$activity = app(CreateActivity::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('activities', [
|
||||
'id' => $activity->id,
|
||||
'account_id' => $account->id,
|
||||
'summary' => 'we went to central perk',
|
||||
'description' => 'it was awesome',
|
||||
'happened_at' => '2009-09-09',
|
||||
]);
|
||||
|
||||
foreach ($contacts as $contact) {
|
||||
$this->assertDatabaseHas('activity_contact', [
|
||||
'account_id' => $account->id,
|
||||
'activity_id' => $activity->id,
|
||||
'contact_id' => $contact->id,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Activity::class,
|
||||
$activity
|
||||
);
|
||||
|
||||
$this->assertDatabaseHas('journal_entries', [
|
||||
'account_id' => $account->id,
|
||||
'journalable_id' => $activity->id,
|
||||
'journalable_type' => get_class($activity),
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_adds_emotions()
|
||||
{
|
||||
$account = factory(Account::class)->create();
|
||||
$contact = factory(Contact::class)->create([
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
$emotion = factory(Emotion::class)->create([]);
|
||||
$emotion2 = factory(Emotion::class)->create([]);
|
||||
|
||||
$emotionArray = [];
|
||||
$emotionArray[] = $emotion->id;
|
||||
$emotionArray[] = $emotion2->id;
|
||||
|
||||
$activityType = factory(ActivityType::class)->create([
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'activity_type_id' => $activityType->id,
|
||||
'summary' => 'we went to central perk',
|
||||
'description' => 'it was awesome',
|
||||
'happened_at' => '2009-09-09',
|
||||
'emotions' => $emotionArray,
|
||||
'contacts' => [$contact->id],
|
||||
];
|
||||
|
||||
$activity = app(CreateActivity::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('emotion_activity', [
|
||||
'account_id' => $account->id,
|
||||
'activity_id' => $activity->id,
|
||||
'emotion_id' => $emotion->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('emotion_activity', [
|
||||
'account_id' => $account->id,
|
||||
'activity_id' => $activity->id,
|
||||
'emotion_id' => $emotion2->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @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(CreateActivity::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_activity_type_is_not_linked_to_account()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
$activityType = factory(ActivityType::class)->create([]);
|
||||
$contact = factory(Contact::class)->create([
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'activity_type_id' => $activityType->id,
|
||||
'summary' => 'we went to central perk',
|
||||
'description' => 'it was awesome',
|
||||
'happened_at' => '2009-09-09',
|
||||
'contacts' => [$contact->id],
|
||||
];
|
||||
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
app(CreateActivity::class)->execute($request);
|
||||
}
|
||||
}
|
||||
94
tests/Unit/Services/Account/Activity/DestroyActivityTest.php
Normal file
94
tests/Unit/Services/Account/Activity/DestroyActivityTest.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Activity;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Contact\Contact;
|
||||
use App\Models\Account\Activity;
|
||||
use App\Models\Account\ActivityType;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use App\Services\Account\Activity\Activity\CreateActivity;
|
||||
use App\Services\Account\Activity\Activity\DestroyActivity;
|
||||
|
||||
class DestroyActivityTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_destroys_a_activity()
|
||||
{
|
||||
$activity = factory(Activity::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $activity->account_id,
|
||||
'activity_id' => $activity->id,
|
||||
];
|
||||
|
||||
$this->assertDatabaseHas('activities', [
|
||||
'id' => $activity->id,
|
||||
]);
|
||||
|
||||
app(DestroyActivity::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseMissing('activities', [
|
||||
'id' => $activity->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_removes_the_journal_entry_when_destroying_the_activity()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
$activityType = factory(ActivityType::class)->create([
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
$contact = factory(Contact::class)->create([
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'activity_type_id' => $activityType->id,
|
||||
'summary' => 'we went to central perk',
|
||||
'description' => 'it was awesome',
|
||||
'happened_at' => '2009-09-09',
|
||||
'contacts' => [$contact->id],
|
||||
];
|
||||
|
||||
$activity = app(CreateActivity::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('activities', [
|
||||
'id' => $activity->id,
|
||||
]);
|
||||
$this->assertDatabaseHas('activity_contact', [
|
||||
'activity_id' => $activity->id,
|
||||
'contact_id' => $contact->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('journal_entries', [
|
||||
'account_id' => $account->id,
|
||||
'journalable_id' => $activity->id,
|
||||
'journalable_type' => get_class($activity),
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $activity->account_id,
|
||||
'activity_id' => $activity->id,
|
||||
];
|
||||
app(DestroyActivity::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseMissing('activities', [
|
||||
'id' => $activity->id,
|
||||
]);
|
||||
$this->assertDatabaseMissing('activity_contact', [
|
||||
'activity_id' => $activity->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseMissing('journal_entries', [
|
||||
'account_id' => $account->id,
|
||||
'journalable_id' => $activity->id,
|
||||
'journalable_type' => get_class($activity),
|
||||
]);
|
||||
}
|
||||
}
|
||||
191
tests/Unit/Services/Account/Activity/UpdateActivityTest.php
Normal file
191
tests/Unit/Services/Account/Activity/UpdateActivityTest.php
Normal file
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Activity;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Contact\Contact;
|
||||
use App\Models\Account\Activity;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Services\Account\Activity\Activity\UpdateActivity;
|
||||
|
||||
class UpdateActivityTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_updates_an_activity()
|
||||
{
|
||||
$activity = factory(Activity::class)->create([]);
|
||||
$contact = factory(Contact::class)->create([
|
||||
'account_id' => $activity->account_id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $activity->account_id,
|
||||
'activity_id' => $activity->id,
|
||||
'activity_type_id' => $activity->activity_type_id,
|
||||
'summary' => 'we went to central perk',
|
||||
'description' => 'it was awesome',
|
||||
'happened_at' => '2009-09-09',
|
||||
'contacts' => [$contact->id],
|
||||
];
|
||||
|
||||
app(UpdateActivity::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('activities', [
|
||||
'id' => $activity->id,
|
||||
'account_id' => $activity->account_id,
|
||||
'summary' => 'we went to central perk',
|
||||
'description' => 'it was awesome',
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Activity::class,
|
||||
$activity
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_removes_old_associated_contacts()
|
||||
{
|
||||
$activity = factory(Activity::class)->create();
|
||||
$contacts = factory(Contact::class, 3)->create([
|
||||
'account_id' => $activity->account_id,
|
||||
]);
|
||||
foreach ($contacts as $contact) {
|
||||
$activity->contacts()->syncWithoutDetaching([$contact->id => [
|
||||
'account_id' => $activity->account_id,
|
||||
]]);
|
||||
}
|
||||
|
||||
foreach ($contacts as $contact) {
|
||||
$this->assertDatabaseHas('activity_contact', [
|
||||
'account_id' => $activity->account_id,
|
||||
'activity_id' => $activity->id,
|
||||
'contact_id' => $contact->id,
|
||||
]);
|
||||
}
|
||||
|
||||
$newContact = factory(Contact::class)->create([
|
||||
'account_id' => $activity->account_id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $activity->account_id,
|
||||
'activity_id' => $activity->id,
|
||||
'activity_type_id' => $activity->activity_type_id,
|
||||
'summary' => 'we went to central perk',
|
||||
'description' => 'it was awesome',
|
||||
'happened_at' => '2009-09-09',
|
||||
'contacts' => [$newContact->id],
|
||||
];
|
||||
|
||||
app(UpdateActivity::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('activity_contact', [
|
||||
'account_id' => $activity->account_id,
|
||||
'activity_id' => $activity->id,
|
||||
'contact_id' => $newContact->id,
|
||||
]);
|
||||
foreach ($contacts as $contact) {
|
||||
$this->assertDatabaseMissing('activity_contact', [
|
||||
'account_id' => $activity->account_id,
|
||||
'activity_id' => $activity->id,
|
||||
'contact_id' => $contact->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_removes_old_associated_contacts_and_keep_previous_one()
|
||||
{
|
||||
$activity = factory(Activity::class)->create();
|
||||
$contacts = factory(Contact::class, 3)->create([
|
||||
'account_id' => $activity->account_id,
|
||||
]);
|
||||
foreach ($contacts as $contact) {
|
||||
$activity->contacts()->syncWithoutDetaching([$contact->id => [
|
||||
'account_id' => $activity->account_id,
|
||||
]]);
|
||||
}
|
||||
|
||||
foreach ($contacts as $contact) {
|
||||
$this->assertDatabaseHas('activity_contact', [
|
||||
'account_id' => $activity->account_id,
|
||||
'activity_id' => $activity->id,
|
||||
'contact_id' => $contact->id,
|
||||
]);
|
||||
}
|
||||
|
||||
$request = [
|
||||
'account_id' => $activity->account_id,
|
||||
'activity_id' => $activity->id,
|
||||
'activity_type_id' => $activity->activity_type_id,
|
||||
'summary' => 'we went to central perk',
|
||||
'description' => 'it was awesome',
|
||||
'happened_at' => '2009-09-09',
|
||||
'contacts' => [$contacts[0]->id, $contacts[1]->id],
|
||||
];
|
||||
|
||||
app(UpdateActivity::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('activity_contact', [
|
||||
'account_id' => $activity->account_id,
|
||||
'activity_id' => $activity->id,
|
||||
'contact_id' => $contacts[0]->id,
|
||||
]);
|
||||
$this->assertDatabaseHas('activity_contact', [
|
||||
'account_id' => $activity->account_id,
|
||||
'activity_id' => $activity->id,
|
||||
'contact_id' => $contacts[1]->id,
|
||||
]);
|
||||
$this->assertDatabaseMissing('activity_contact', [
|
||||
'account_id' => $activity->account_id,
|
||||
'activity_id' => $activity->id,
|
||||
'contact_id' => $contacts[2]->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$activity = factory(Activity::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'activity_id' => $activity->id,
|
||||
'activity_type_id' => $activity->activity_type_id,
|
||||
'summary' => 'we went to central perk',
|
||||
'description' => 'it was awesome',
|
||||
'happened_at' => '2009-09-09',
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(UpdateActivity::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_contact_is_not_linked_to_account()
|
||||
{
|
||||
$activity = factory(Activity::class)->create([]);
|
||||
$account = factory(Account::class)->create([]);
|
||||
$contact = factory(Contact::class)->create([
|
||||
'account_id' => $activity->account_id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'activity_id' => $activity->id,
|
||||
'activity_type_id' => $activity->activity_type_id,
|
||||
'summary' => 'we went to central perk',
|
||||
'description' => 'it was awesome',
|
||||
'happened_at' => '2009-09-09',
|
||||
'contacts' => [$contact->id],
|
||||
];
|
||||
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
app(UpdateActivity::class)->execute($request);
|
||||
}
|
||||
}
|
||||
76
tests/Unit/Services/Account/Company/CreateCompanyTest.php
Normal file
76
tests/Unit/Services/Account/Company/CreateCompanyTest.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Company;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User\User;
|
||||
use function Safe\json_encode;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Account\Company;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use App\Jobs\AuditLog\LogAccountAudit;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use App\Services\Account\Company\CreateCompany;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class CreateCompanyTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_stores_a_company()
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
$account = factory(Account::class)->create([]);
|
||||
$user = factory(User::class)->create([
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'author_id' => $user->id,
|
||||
'name' => 'central perk',
|
||||
'website' => 'https://centralperk.com',
|
||||
'number_of_employees' => 3,
|
||||
];
|
||||
|
||||
$company = app(CreateCompany::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('companies', [
|
||||
'id' => $company->id,
|
||||
'account_id' => $account->id,
|
||||
'name' => 'central perk',
|
||||
'website' => 'https://centralperk.com',
|
||||
'number_of_employees' => 3,
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Company::class,
|
||||
$company
|
||||
);
|
||||
|
||||
Queue::assertPushed(LogAccountAudit::class, function ($job) use ($user) {
|
||||
return $job->auditLog['action'] === 'company_created' &&
|
||||
$job->auditLog['author_id'] === $user->id &&
|
||||
$job->auditLog['about_contact_id'] === null &&
|
||||
$job->auditLog['should_appear_on_dashboard'] === true &&
|
||||
$job->auditLog['objects'] === json_encode([
|
||||
'name' => 'central perk',
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'street' => '199 Lafayette Street',
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(CreateCompany::class)->execute($request);
|
||||
}
|
||||
}
|
||||
60
tests/Unit/Services/Account/Company/DestroyCompanyTest.php
Normal file
60
tests/Unit/Services/Account/Company/DestroyCompanyTest.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Company;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Account\Company;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use App\Services\Account\Company\DestroyCompany;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class DestroyCompanyTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_destroys_a_company()
|
||||
{
|
||||
$company = factory(Company::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $company->account_id,
|
||||
'company_id' => $company->id,
|
||||
];
|
||||
|
||||
app(DestroyCompany::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseMissing('companies', [
|
||||
'id' => $company->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_account_is_not_linked_to_company()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
$company = factory(Company::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'company_id' => $company->id,
|
||||
];
|
||||
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
app(DestroyCompany::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_ids_do_not_exist()
|
||||
{
|
||||
$request = [
|
||||
'account_id' => 11111111,
|
||||
'company_id' => 11111111,
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(DestroyCompany::class)->execute($request);
|
||||
}
|
||||
}
|
||||
74
tests/Unit/Services/Account/Company/UpdateCompanyTest.php
Normal file
74
tests/Unit/Services/Account/Company/UpdateCompanyTest.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Company;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Account\Company;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use App\Services\Account\Company\UpdateCompany;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class UpdateCompanyTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_updates_a_company()
|
||||
{
|
||||
$company = factory(Company::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $company->account_id,
|
||||
'company_id' => $company->id,
|
||||
'name' => 'Chandler House',
|
||||
'website' => 'https://centralperk.com',
|
||||
'number_of_employees' => 300,
|
||||
];
|
||||
|
||||
app(UpdateCompany::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('companies', [
|
||||
'id' => $company->id,
|
||||
'account_id' => $company->account_id,
|
||||
'name' => 'Chandler House',
|
||||
'website' => 'https://centralperk.com',
|
||||
'number_of_employees' => 300,
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Company::class,
|
||||
$company
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$company = factory(Company::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'name' => '199 Lafayette Street',
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(UpdateCompany::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_place_is_not_linked_to_account()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
$company = factory(Company::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'company_id' => $company->id,
|
||||
'name' => '199 Lafayette Street',
|
||||
];
|
||||
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
app(UpdateCompany::class)->execute($request);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\LifeEvent\LifeEventType;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Contact\LifeEventType;
|
||||
use App\Models\Contact\LifeEventCategory;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Services\Account\LifeEvent\LifeEventType\CreateLifeEventType;
|
||||
|
||||
class CreateLifeEventTypeTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_stores_a_life_event_type()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
$lifeEventCategory = factory(LifeEventCategory::class)->create([
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'life_event_category_id' => $lifeEventCategory->id,
|
||||
'name' => 'Had a major health problem',
|
||||
];
|
||||
|
||||
$lifeEventType = app(CreateLifeEventType::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('life_event_types', [
|
||||
'id' => $lifeEventType->id,
|
||||
'account_id' => $account->id,
|
||||
'life_event_category_id' => $lifeEventCategory->id,
|
||||
'name' => 'Had a major health problem',
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
LifeEventType::class,
|
||||
$lifeEventType
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$request = [
|
||||
'name' => 'Had a major health problem',
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(CreateLifeEventType::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_life_event_category_is_not_linked_to_account()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
$lifeEventCategory = factory(LifeEventCategory::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'life_event_category_id' => $lifeEventCategory->id,
|
||||
'name' => 'Had a major health problem',
|
||||
];
|
||||
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
app(CreateLifeEventType::class)->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\LifeEvent\LifeEventType;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Contact\LifeEventType;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Services\Account\LifeEvent\LifeEventType\DestroyLifeEventType;
|
||||
|
||||
class DestroyLifeEventTypeTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_destroys_a_life_event_type()
|
||||
{
|
||||
$lifeEventType = factory(LifeEventType::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $lifeEventType->account_id,
|
||||
'life_event_type_id' => $lifeEventType->id,
|
||||
];
|
||||
|
||||
app(DestroyLifeEventType::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseMissing('life_event_types', [
|
||||
'id' => $lifeEventType->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_account_is_not_linked_to_life_event_type()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
$lifeEventType = factory(LifeEventType::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'life_event_type_id' => $lifeEventType->id,
|
||||
];
|
||||
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
app(DestroyLifeEventType::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_ids_do_not_exist()
|
||||
{
|
||||
$request = [
|
||||
'account_id' => 11111111,
|
||||
'life_event_type_id' => 11111111,
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(DestroyLifeEventType::class)->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\LifeEvent\LifeEventType;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Contact\LifeEventType;
|
||||
use App\Models\Contact\LifeEventCategory;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Services\Account\LifeEvent\LifeEventType\UpdateLifeEventType;
|
||||
|
||||
class UpdateLifeEventTypeTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_updates_a_life_event_type()
|
||||
{
|
||||
$lifeEventType = factory(LifeEventType::class)->create([]);
|
||||
$lifeEventCategory = factory(LifeEventCategory::class)->create([
|
||||
'account_id' => $lifeEventType->account_id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $lifeEventType->account_id,
|
||||
'life_event_type_id' => $lifeEventType->id,
|
||||
'life_event_category_id' => $lifeEventCategory->id,
|
||||
'name' => 'Had a major health problem',
|
||||
];
|
||||
|
||||
$lifeEventType = app(UpdateLifeEventType::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('life_event_types', [
|
||||
'id' => $lifeEventType->id,
|
||||
'account_id' => $lifeEventType->account_id,
|
||||
'life_event_category_id' => $lifeEventCategory->id,
|
||||
'name' => 'Had a major health problem',
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
LifeEventType::class,
|
||||
$lifeEventType
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$lifeEventType = factory(LifeEventType::class)->create([]);
|
||||
$lifeEventCategory = factory(LifeEventCategory::class)->create([
|
||||
'account_id' => $lifeEventType->account_id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $lifeEventType->account_id,
|
||||
'life_event_category_id' => $lifeEventCategory->id,
|
||||
'name' => 'Had a major health problem',
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(UpdateLifeEventType::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_life_event_is_not_linked_to_account()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
$lifeEventType = factory(LifeEventType::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'life_event_type_id' => $lifeEventType->id,
|
||||
'life_event_category_id' => $lifeEventType->life_event_category_id,
|
||||
'name' => 'Had a major health problem',
|
||||
];
|
||||
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
app(UpdateLifeEventType::class)->execute($request);
|
||||
}
|
||||
}
|
||||
85
tests/Unit/Services/Account/Photo/DestroyPhotoTest.php
Normal file
85
tests/Unit/Services/Account/Photo/DestroyPhotoTest.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Photo;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Photo;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Services\Account\Photo\UploadPhoto;
|
||||
use App\Services\Account\Photo\DestroyPhoto;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class DestroyPhotoTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_destroys_a_photo()
|
||||
{
|
||||
$contact = factory(Contact::class)->create([]);
|
||||
$photo = $this->uploadPhoto($contact);
|
||||
|
||||
$request = [
|
||||
'account_id' => $photo->account_id,
|
||||
'photo_id' => $photo->id,
|
||||
];
|
||||
|
||||
$this->assertDatabaseHas('photos', [
|
||||
'id' => $photo->id,
|
||||
]);
|
||||
|
||||
app(DestroyPhoto::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseMissing('photos', [
|
||||
'id' => $photo->id,
|
||||
]);
|
||||
|
||||
Storage::disk('photos')->assertMissing('photo.png');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$request = [
|
||||
'photo_id' => 2,
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
|
||||
app(DestroyPhoto::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_a_photo_doesnt_exist()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
$photo = factory(Photo::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'photo_id' => $photo->id,
|
||||
];
|
||||
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
|
||||
app(DestroyPhoto::class)->execute($request);
|
||||
}
|
||||
|
||||
private function uploadPhoto($contact)
|
||||
{
|
||||
Storage::fake('photos');
|
||||
|
||||
$request = [
|
||||
'account_id' => $contact->account_id,
|
||||
'contact_id' => $contact->id,
|
||||
'photo' => UploadedFile::fake()->image('photo.png'),
|
||||
];
|
||||
|
||||
return app(UploadPhoto::class)->execute($request);
|
||||
}
|
||||
}
|
||||
74
tests/Unit/Services/Account/Photo/UploadPhotoTest.php
Normal file
74
tests/Unit/Services/Account/Photo/UploadPhotoTest.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Photo;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Photo;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Services\Account\Photo\UploadPhoto;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class UploadPhotoTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_uploads_a_photo()
|
||||
{
|
||||
Storage::fake('photos');
|
||||
|
||||
$contact = factory(Contact::class)->create([]);
|
||||
|
||||
$file = UploadedFile::fake()->image('imag.png');
|
||||
|
||||
$request = [
|
||||
'account_id' => $contact->account_id,
|
||||
'contact_id' => $contact->id,
|
||||
'photo' => $file,
|
||||
];
|
||||
|
||||
$photo = app(UploadPhoto::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('photos', [
|
||||
'id' => $photo->id,
|
||||
'account_id' => $contact->account_id,
|
||||
'mime_type' => 'image/png',
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Photo::class,
|
||||
$photo
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$request = [
|
||||
'account_id' => 'wrong',
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
|
||||
app(UploadPhoto::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_account_does_not_exist()
|
||||
{
|
||||
Storage::fake('photos');
|
||||
|
||||
$request = [
|
||||
'account_id' => 0,
|
||||
'contact_id' => 0,
|
||||
'photo' => UploadedFile::fake()->image('document.pdf'),
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
|
||||
app(UploadPhoto::class)->execute($request);
|
||||
}
|
||||
}
|
||||
95
tests/Unit/Services/Account/Place/CreatePlaceTest.php
Normal file
95
tests/Unit/Services/Account/Place/CreatePlaceTest.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Place;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Place;
|
||||
use App\Models\Account\Account;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Services\Account\Place\CreatePlace;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class CreatePlaceTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_stores_a_place_without_fetching_geolocation_information()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'street' => '199 Lafayette Street',
|
||||
'city' => 'New York City',
|
||||
'province' => '',
|
||||
'postal_code' => '',
|
||||
'country' => 'USA',
|
||||
'latitude' => '10',
|
||||
'longitude' => '10',
|
||||
];
|
||||
|
||||
$place = app(CreatePlace::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('places', [
|
||||
'id' => $place->id,
|
||||
'account_id' => $account->id,
|
||||
'street' => '199 Lafayette Street',
|
||||
'latitude' => 10,
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Place::class,
|
||||
$place
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_stores_a_place_and_fetch_geolocation_information()
|
||||
{
|
||||
config(['monica.enable_geolocation' => true]);
|
||||
config(['monica.location_iq_api_key' => 'test']);
|
||||
|
||||
$body = file_get_contents(base_path('tests/Fixtures/Services/Account/Place/CreatePlaceSampleResponse.json'));
|
||||
Http::fake([
|
||||
'us1.locationiq.com/v1/*' => Http::response($body, 200),
|
||||
]);
|
||||
|
||||
$account = factory(Account::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'street' => '12',
|
||||
'city' => 'beverly hills',
|
||||
'province' => '',
|
||||
'postal_code' => '90210',
|
||||
'country' => 'US',
|
||||
'latitude' => '',
|
||||
'longitude' => '',
|
||||
];
|
||||
|
||||
$place = app(CreatePlace::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('places', [
|
||||
'id' => $place->id,
|
||||
'account_id' => $account->id,
|
||||
'street' => '12',
|
||||
'latitude' => 34.0736204,
|
||||
'longitude' => -118.4003563,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
factory(Account::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'street' => '199 Lafayette Street',
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(CreatePlace::class)->execute($request);
|
||||
}
|
||||
}
|
||||
60
tests/Unit/Services/Account/Place/DestroyPlaceTest.php
Normal file
60
tests/Unit/Services/Account/Place/DestroyPlaceTest.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Place;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Place;
|
||||
use App\Models\Account\Account;
|
||||
use App\Services\Account\Place\DestroyPlace;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class DestroyPlaceTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_destroys_a_place()
|
||||
{
|
||||
$place = factory(Place::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $place->account_id,
|
||||
'place_id' => $place->id,
|
||||
];
|
||||
|
||||
app(DestroyPlace::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseMissing('places', [
|
||||
'id' => $place->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_account_is_not_linked_to_places()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
$place = factory(Place::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'place_id' => $place->id,
|
||||
];
|
||||
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
app(DestroyPlace::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_ids_do_not_exist()
|
||||
{
|
||||
$request = [
|
||||
'account_id' => 11111111,
|
||||
'place_id' => 11111111,
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(DestroyPlace::class)->execute($request);
|
||||
}
|
||||
}
|
||||
113
tests/Unit/Services/Account/Place/UpdatePlaceTest.php
Normal file
113
tests/Unit/Services/Account/Place/UpdatePlaceTest.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Place;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Place;
|
||||
use App\Models\Account\Account;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Services\Account\Place\UpdatePlace;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class UpdatePlaceTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_updates_a_place_without_fetching_geolocation_information()
|
||||
{
|
||||
$place = factory(Place::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $place->account_id,
|
||||
'place_id' => $place->id,
|
||||
'street' => '199 Lafayette Street',
|
||||
'city' => 'New York City',
|
||||
'province' => '',
|
||||
'postal_code' => '',
|
||||
'country' => 'USA',
|
||||
'latitude' => '10',
|
||||
'longitude' => '10',
|
||||
];
|
||||
|
||||
$place = app(UpdatePlace::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('places', [
|
||||
'id' => $place->id,
|
||||
'account_id' => $place->account_id,
|
||||
'latitude' => 10,
|
||||
'city' => 'New York City',
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Place::class,
|
||||
$place
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_updates_a_place_and_fetch_geolocation_information()
|
||||
{
|
||||
config(['monica.enable_geolocation' => true]);
|
||||
config(['monica.location_iq_api_key' => 'test']);
|
||||
|
||||
$body = file_get_contents(base_path('tests/Fixtures/Services/Account/Place/UpdatePlaceSampleResponse.json'));
|
||||
Http::fake([
|
||||
'us1.locationiq.com/v1/*' => Http::response($body, 200),
|
||||
]);
|
||||
|
||||
$place = factory(Place::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $place->account_id,
|
||||
'place_id' => $place->id,
|
||||
'street' => '12',
|
||||
'city' => 'beverly hills',
|
||||
'province' => '',
|
||||
'postal_code' => '90210',
|
||||
'country' => 'US',
|
||||
'latitude' => '',
|
||||
'longitude' => '',
|
||||
];
|
||||
|
||||
$place = app(UpdatePlace::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('places', [
|
||||
'id' => $place->id,
|
||||
'account_id' => $place->account_id,
|
||||
'street' => '12',
|
||||
'latitude' => 34.0736204,
|
||||
'longitude' => -118.4003563,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$place = factory(Place::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'street' => '199 Lafayette Street',
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(UpdatePlace::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_place_is_not_linked_to_account()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
$place = factory(Place::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'place_id' => $place->id,
|
||||
];
|
||||
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
app(UpdatePlace::class)->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Settings;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User\User;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use App\Services\Account\Settings\DestroyAccount;
|
||||
use App\Services\Account\Settings\ArchiveAllContacts;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class ArchiveAllContactsTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_archives_all_the_contacts_in_an_account()
|
||||
{
|
||||
$user = factory(User::class)->create([]);
|
||||
factory(Contact::class, 3)->create([
|
||||
'account_id' => $user->account_id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $user->account_id,
|
||||
];
|
||||
|
||||
$result = app(ArchiveAllContacts::class)->execute($request);
|
||||
|
||||
$this->assertTrue($result);
|
||||
|
||||
$this->assertDatabaseHas('contacts', [
|
||||
'is_active' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$request = [];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(DestroyAccount::class)->execute($request);
|
||||
}
|
||||
}
|
||||
47
tests/Unit/Services/Account/Settings/DestroyAccountTest.php
Normal file
47
tests/Unit/Services/Account/Settings/DestroyAccountTest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Settings;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User\User;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use App\Services\Account\Settings\DestroyAccount;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class DestroyAccountTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_destroys_an_account()
|
||||
{
|
||||
$user = factory(User::class)->create([]);
|
||||
factory(Contact::class, 3)->create([
|
||||
'account_id' => $user->account_id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $user->account_id,
|
||||
];
|
||||
|
||||
app(DestroyAccount::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseMissing('contacts', [
|
||||
'account_id' => $user->account_id,
|
||||
'deleted_at' => null,
|
||||
]);
|
||||
$this->assertDatabaseMissing('accounts', [
|
||||
'id' => $user->account_id,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$request = [];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(DestroyAccount::class)->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Settings;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use App\Services\Contact\Document\UploadDocument;
|
||||
use App\Services\Account\Settings\DestroyAllDocuments;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class DestroyAllDocumentsTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_destroys_all_documents()
|
||||
{
|
||||
Storage::fake();
|
||||
|
||||
$contact = factory(Contact::class)->create([]);
|
||||
|
||||
$documents = [];
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$documents[] = $this->uploadDocument($contact);
|
||||
}
|
||||
|
||||
$request = [
|
||||
'account_id' => $contact->account_id,
|
||||
];
|
||||
|
||||
app(DestroyAllDocuments::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseMissing('documents', [
|
||||
'account_id' => $contact->account_id,
|
||||
]);
|
||||
|
||||
foreach ($documents as $document) {
|
||||
Storage::disk('public')->assertMissing($document->new_filename);
|
||||
}
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$request = [
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
|
||||
app(DestroyAllDocuments::class)->execute($request);
|
||||
}
|
||||
|
||||
private function uploadDocument($contact)
|
||||
{
|
||||
$request = [
|
||||
'account_id' => $contact->account_id,
|
||||
'contact_id' => $contact->id,
|
||||
'document' => UploadedFile::fake()->image('document.pdf'),
|
||||
];
|
||||
|
||||
$document = app(UploadDocument::class)->execute($request);
|
||||
|
||||
Storage::disk('public')->assertExists($document->new_filename);
|
||||
|
||||
return $document;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Settings;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Services\Account\Photo\UploadPhoto;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use App\Services\Account\Settings\DestroyAllPhotos;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class DestroyAllPhotosTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_destroys_all_photos()
|
||||
{
|
||||
Storage::fake();
|
||||
|
||||
$contact = factory(Contact::class)->create([]);
|
||||
|
||||
$photos = [];
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$photos[] = $this->uploadPhoto($contact);
|
||||
}
|
||||
|
||||
$request = [
|
||||
'account_id' => $contact->account_id,
|
||||
];
|
||||
|
||||
app(DestroyAllPhotos::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseMissing('photos', [
|
||||
'account_id' => $contact->account_id,
|
||||
]);
|
||||
|
||||
foreach ($photos as $photo) {
|
||||
Storage::disk('public')->assertMissing($photo->new_filename);
|
||||
}
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$request = [];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
|
||||
app(DestroyAllPhotos::class)->execute($request);
|
||||
}
|
||||
|
||||
private function uploadPhoto($contact)
|
||||
{
|
||||
$request = [
|
||||
'account_id' => $contact->account_id,
|
||||
'contact_id' => $contact->id,
|
||||
'photo' => UploadedFile::fake()->image('imag.png'),
|
||||
];
|
||||
|
||||
$photo = app(UploadPhoto::class)->execute($request);
|
||||
|
||||
Storage::disk('public')->assertExists($photo->new_filename);
|
||||
|
||||
return $photo;
|
||||
}
|
||||
}
|
||||
363
tests/Unit/Services/Account/Settings/ExportAccountTest.php
Normal file
363
tests/Unit/Services/Account/Settings/ExportAccountTest.php
Normal file
@@ -0,0 +1,363 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Settings;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Mockery\MockInterface;
|
||||
use App\Jobs\ExportAccount;
|
||||
use App\Models\Contact\Contact;
|
||||
use App\Models\Account\ExportJob;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Notifications\ExportAccountDone;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Testing\AssertableJsonString;
|
||||
use App\Services\Account\Settings\SqlExportAccount;
|
||||
use App\Services\Account\Settings\JsonExportAccount;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class ExportAccountTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_exports_account_json()
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
Storage::fake();
|
||||
$fake = Storage::fake('local');
|
||||
$fake->put('temp/test.json', 'null');
|
||||
|
||||
$job = ExportJob::factory()->create();
|
||||
|
||||
$this->mock(JsonExportAccount::class, function (MockInterface $mock) use ($job) {
|
||||
$mock->shouldReceive('execute')
|
||||
->once()
|
||||
->with([
|
||||
'account_id' => $job->account_id,
|
||||
'user_id' => $job->user_id,
|
||||
])
|
||||
->andReturn('temp/test.json');
|
||||
});
|
||||
|
||||
ExportAccount::dispatchSync($job);
|
||||
$job->refresh();
|
||||
|
||||
Storage::disk('public')->assertExists($job->filename);
|
||||
|
||||
Notification::assertSentTo(
|
||||
[$job->user], ExportAccountDone::class
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_exports_account_sql()
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
Storage::fake();
|
||||
$fake = Storage::fake('local');
|
||||
$fake->put('temp/test.sql', 'null');
|
||||
|
||||
$job = ExportJob::factory()->create([
|
||||
'type' => 'sql',
|
||||
]);
|
||||
|
||||
$this->mock(SqlExportAccount::class, function (MockInterface $mock) use ($job) {
|
||||
$mock->shouldReceive('execute')
|
||||
->once()
|
||||
->with([
|
||||
'account_id' => $job->account_id,
|
||||
'user_id' => $job->user_id,
|
||||
])
|
||||
->andReturn('temp/test.sql');
|
||||
});
|
||||
|
||||
ExportAccount::dispatchSync($job);
|
||||
$job->refresh();
|
||||
|
||||
Storage::disk('public')->assertExists($job->filename);
|
||||
|
||||
Notification::assertSentTo(
|
||||
[$job->user], ExportAccountDone::class
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_exports_account_file()
|
||||
{
|
||||
Storage::fake();
|
||||
Storage::fake('local');
|
||||
|
||||
$job = ExportJob::factory()->create();
|
||||
ExportAccount::dispatchSync($job);
|
||||
|
||||
$job->refresh();
|
||||
|
||||
$this->assertStringStartsWith('exports/', $job->filename);
|
||||
$this->assertStringEndsWith('.json', $job->filename);
|
||||
Storage::disk('public')->assertExists($job->filename);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_exports_account_file_sql()
|
||||
{
|
||||
Storage::fake();
|
||||
Storage::fake('local');
|
||||
|
||||
$job = ExportJob::factory()->create([
|
||||
'type' => 'sql',
|
||||
]);
|
||||
ExportAccount::dispatchSync($job);
|
||||
|
||||
$job->refresh();
|
||||
|
||||
$this->assertStringStartsWith('exports/', $job->filename);
|
||||
$this->assertStringEndsWith('.sql', $job->filename);
|
||||
Storage::disk('public')->assertExists($job->filename);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_exports_json_file()
|
||||
{
|
||||
Storage::fake();
|
||||
Storage::fake('local');
|
||||
|
||||
$job = ExportJob::factory()->create();
|
||||
ExportAccount::dispatchSync($job);
|
||||
|
||||
$job->refresh();
|
||||
|
||||
$this->assertStringStartsWith('exports/', $job->filename);
|
||||
$this->assertStringEndsWith('.json', $job->filename);
|
||||
Storage::disk('public')->assertExists($job->filename);
|
||||
|
||||
$json = Storage::disk('public')->get($job->filename);
|
||||
$test = new AssertableJsonString($json);
|
||||
|
||||
$test->assertStructure([
|
||||
'account' => [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'data' => [
|
||||
'*' => [
|
||||
'count',
|
||||
'type',
|
||||
'values' => [
|
||||
'*' => [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'properties',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'properties' => [
|
||||
'modules' => [
|
||||
'*' => [
|
||||
'key',
|
||||
'translation_key',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'properties',
|
||||
],
|
||||
],
|
||||
'reminder_rules' => [
|
||||
'*' => [
|
||||
'number_of_days_before',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'properties',
|
||||
],
|
||||
],
|
||||
],
|
||||
'instance' => [
|
||||
'activity_types' => [
|
||||
'*' => [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'properties' => [
|
||||
'name',
|
||||
'translation_key',
|
||||
'category',
|
||||
],
|
||||
],
|
||||
],
|
||||
'activity_type_categories' => [
|
||||
'*' => [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'properties' => [
|
||||
'name',
|
||||
'translation_key',
|
||||
],
|
||||
],
|
||||
],
|
||||
'life_event_types' => [
|
||||
'*' => [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'properties' => [
|
||||
'translation_key',
|
||||
'core_monica_data',
|
||||
'category',
|
||||
],
|
||||
],
|
||||
],
|
||||
'life_event_categories' => [
|
||||
'*' => [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'properties' => [
|
||||
'translation_key',
|
||||
'core_monica_data',
|
||||
],
|
||||
],
|
||||
],
|
||||
'contact_field_types' => [
|
||||
'*' => [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'properties' => [
|
||||
'name',
|
||||
'fontawesome_icon',
|
||||
'delible',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_exports_json_file_contacts()
|
||||
{
|
||||
Storage::fake();
|
||||
Storage::fake('local');
|
||||
|
||||
$job = ExportJob::factory()->create();
|
||||
factory(Contact::class, 5)->create([
|
||||
'account_id' => $job->account->id,
|
||||
]);
|
||||
|
||||
ExportAccount::dispatchSync($job);
|
||||
|
||||
$job->refresh();
|
||||
|
||||
$this->assertStringStartsWith('exports/', $job->filename);
|
||||
$this->assertStringEndsWith('.json', $job->filename);
|
||||
Storage::disk('public')->assertExists($job->filename);
|
||||
|
||||
$json = Storage::disk('public')->get($job->filename);
|
||||
$test = new AssertableJsonString($json);
|
||||
|
||||
$test->assertStructure([
|
||||
'account' => [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'data' => [
|
||||
'*' => [
|
||||
'count',
|
||||
'type',
|
||||
'values' => [
|
||||
'*' => [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'properties',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'properties' => [
|
||||
'modules' => [
|
||||
'*' => [
|
||||
'key',
|
||||
'translation_key',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'properties',
|
||||
],
|
||||
],
|
||||
'reminder_rules' => [
|
||||
'*' => [
|
||||
'number_of_days_before',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'properties',
|
||||
],
|
||||
],
|
||||
],
|
||||
'instance' => [
|
||||
'activity_types' => [
|
||||
'*' => [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'properties' => [
|
||||
'name',
|
||||
'translation_key',
|
||||
'category',
|
||||
],
|
||||
],
|
||||
],
|
||||
'activity_type_categories' => [
|
||||
'*' => [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'properties' => [
|
||||
'name',
|
||||
'translation_key',
|
||||
],
|
||||
],
|
||||
],
|
||||
'life_event_types' => [
|
||||
'*' => [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'properties' => [
|
||||
'translation_key',
|
||||
'core_monica_data',
|
||||
'category',
|
||||
],
|
||||
],
|
||||
],
|
||||
'life_event_categories' => [
|
||||
'*' => [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'properties' => [
|
||||
'translation_key',
|
||||
'core_monica_data',
|
||||
],
|
||||
],
|
||||
],
|
||||
'contact_field_types' => [
|
||||
'*' => [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'properties' => [
|
||||
'name',
|
||||
'fontawesome_icon',
|
||||
'delible',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
67
tests/Unit/Services/Account/Settings/ResetAccountTest.php
Normal file
67
tests/Unit/Services/Account/Settings/ResetAccountTest.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Settings;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User\User;
|
||||
use App\Models\Contact\Contact;
|
||||
use App\Models\Account\ActivityType;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use App\Services\Account\Settings\ResetAccount;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use App\Services\Account\Activity\Activity\CreateActivity;
|
||||
|
||||
class ResetAccountTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_resets_an_account()
|
||||
{
|
||||
// populate the account with fake contacts and activities
|
||||
$user = factory(User::class)->create();
|
||||
$contacts = factory(Contact::class, 3)->create([
|
||||
'account_id' => $user->account_id,
|
||||
]);
|
||||
|
||||
$activityType = factory(ActivityType::class)->create([
|
||||
'account_id' => $user->account_id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $user->account_id,
|
||||
'activity_type_id' => $activityType->id,
|
||||
'summary' => 'we went to central perk',
|
||||
'description' => 'it was awesome',
|
||||
'happened_at' => '2009-09-09',
|
||||
'contacts' => $contacts->map(function ($contact) {
|
||||
return $contact->id;
|
||||
})->toArray(),
|
||||
];
|
||||
|
||||
app(CreateActivity::class)->execute($request);
|
||||
|
||||
$request = [
|
||||
'account_id' => $user->account_id,
|
||||
];
|
||||
|
||||
app(ResetAccount::class)->handle($request);
|
||||
|
||||
$this->assertDatabaseMissing('contacts', [
|
||||
'account_id' => $user->account_id,
|
||||
'deleted_at' => null,
|
||||
]);
|
||||
$this->assertDatabaseMissing('activities', [
|
||||
'account_id' => $user->account_id,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$request = [];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(ResetAccount::class)->handle($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Account\Settings;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User\User;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use App\Services\Account\Settings\SqlExportAccount;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class SqlExportAccountTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_exports_account_information()
|
||||
{
|
||||
Storage::fake('local');
|
||||
|
||||
$user = factory(User::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $user->account_id,
|
||||
'user_id' => $user->id,
|
||||
];
|
||||
|
||||
$filename = app(SqlExportAccount::class)->execute($request);
|
||||
|
||||
$this->assertStringStartsWith('temp/', $filename);
|
||||
$this->assertStringEndsWith('.sql', $filename);
|
||||
Storage::disk('local')->assertExists($filename);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$request = [];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(SqlExportAccount::class)->execute($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user