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,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