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

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

View File

@@ -0,0 +1,102 @@
<?php
namespace Tests\Commands\Other;
use Tests\TestCase;
use App\Models\User\User;
use App\Models\User\SyncToken;
use App\Models\Account\Account;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class CleanCommandTest extends TestCase
{
use DatabaseTransactions;
/** @test */
public function clean_command_left_one_token()
{
$account = factory(Account::class)->create();
$user = factory(User::class)->create([
'account_id' => $account->id,
]);
SyncToken::create([
'account_id' => $account->id,
'user_id' => $user->id,
'name' => 'contacts',
'timestamp' => now(),
]);
$this->artisan('monica:clean')->run();
$this->assertDatabaseHas('synctoken', [
'account_id' => $account->id,
'user_id' => $user->id,
'name' => 'contacts',
]);
}
/** @test */
public function clean_command_left_all_token()
{
$account = factory(Account::class)->create();
$user = factory(User::class)->create([
'account_id' => $account->id,
]);
$s1 = SyncToken::create([
'account_id' => $account->id,
'user_id' => $user->id,
'name' => 'contacts',
'timestamp' => now(),
]);
$s2 = SyncToken::create([
'account_id' => $account->id,
'user_id' => $user->id,
'name' => 'contacts',
'timestamp' => now()->addDays(-10),
]);
$command = $this->artisan('monica:clean');
$command->expectsOutput("Delete token {$s2->id} - User {$user->id} - Type contacts - timestamp {$s2->timestamp}");
$command->run();
$this->assertDatabaseHas('synctoken', [
'id' => $s1->id,
]);
$this->assertDatabaseMissing('synctoken', [
'id' => $s2->id,
]);
}
/** @test */
public function clean_command_dryrun()
{
$account = factory(Account::class)->create();
$user = factory(User::class)->create([
'account_id' => $account->id,
]);
$s1 = SyncToken::create([
'account_id' => $account->id,
'user_id' => $user->id,
'name' => 'contacts',
'timestamp' => now(),
]);
$s2 = SyncToken::create([
'account_id' => $account->id,
'user_id' => $user->id,
'name' => 'contacts',
'timestamp' => now()->addDays(-10),
]);
$this->artisan('monica:clean', ['--dry-run' => true])->run();
$this->assertDatabaseHas('synctoken', [
'id' => $s1->id,
]);
$this->assertDatabaseHas('synctoken', [
'id' => $s2->id,
]);
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Tests\Commands\Other;
use Tests\TestCase;
use App\Models\User\User;
use App\Console\Commands\CreateAccount;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class CreateAccountTest extends TestCase
{
use DatabaseTransactions;
/** @test */
public function it_creates_account()
{
$email = 'user1@example.com';
$this->artisan('account:create', ['--email' => 'user1@example.com', '--password' => 'astrongpassword'])
->run();
$user = User::where('email', '=', $email)->first();
$this->assertNotEmpty($user);
}
/** @test */
public function it_creates_account_with_specified_name()
{
$email = 'user1@example.com';
$firstname = 'firstname';
$lastname = 'lastname';
$this->artisan('account:create', [
'--email' => $email,
'--password' => 'astrongpassword',
'--firstname' => $firstname,
'--lastname' => $lastname,
])->run();
$user = User::where('email', '=', $email)->first();
$this->assertNotEmpty($user);
}
/** @test */
public function it_fails_creation_without_email()
{
$this->artisan('account:create', ['--password' => 'astrongpassword'])
->expectsOutput(CreateAccount::ERROR_MISSING_EMAIL)
->doesntExpectOutput(CreateAccount::ERROR_MISSING_PASSWORD)
->run();
}
/** @test */
public function it_fails_creation_without_password()
{
$email = 'user1@example.com';
$this->artisan('account:create', ['--email' => $email])
->expectsOutput(CreateAccount::ERROR_MISSING_PASSWORD)
->doesntExpectOutput(CreateAccount::ERROR_MISSING_EMAIL)
->run();
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Tests\Commands\Other;
use Tests\TestCase;
use App\Models\User\User;
use Mockery\MockInterface;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use App\Services\DavClient\CreateAddressBookSubscription;
class CreateAddressBookSubscriptionTest extends TestCase
{
use DatabaseTransactions;
/** @test */
public function it_add_addressbook()
{
$user = factory(User::class)->create();
$this->mock(CreateAddressBookSubscription::class, function (MockInterface $mock) use ($user) {
$mock->shouldReceive('execute')
->once()
->withArgs(function ($data) use ($user) {
$this->assertEquals([
'account_id' => $user->account_id,
'user_id' => $user->id,
'base_uri' => 'https://test',
'username' => 'login',
'password' => 'password',
], $data);
return true;
});
});
$this->artisan('monica:newaddressbooksubscription', [
'--email' => $user->email,
'--url' => 'https://test',
'--login' => 'login',
'--password' => 'password',
])->run();
}
}

View File

@@ -0,0 +1,87 @@
<?php
namespace Tests\Commands\Other;
use Tests\TestCase;
use App\Models\Account\Account;
use App\Models\Contact\Contact;
use Illuminate\Support\Facades\Storage;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ImportCSVTest extends TestCase
{
use DatabaseTransactions;
/** @test */
public function csv_import_contacts()
{
Storage::fake('public');
$user = $this->getUser();
$path = base_path('tests/stubs/single_contact_stub.csv');
$totalContacts = Contact::where('account_id', $user->account_id)->count();
$this->artisan('import:csv', [
'user' => $user->email,
'file' => $path,
])
->assertSuccessful()
->run();
$this->assertDatabaseHas('contacts', [
'first_name' => 'Bono',
'last_name' => 'Hewson',
]);
$this->assertDatabaseHas('contact_fields', [
'data' => 'bono@example.com',
]);
// Allows checking if birthday was correctly set
$this->assertDatabaseHas('special_dates', [
'date' => '1960-05-10',
]);
// Asserts that only 3 new contacts were created
$this->assertEquals(
$totalContacts + 1,
Contact::where('account_id', $user->account_id)->count()
);
}
/** @test */
public function csv_import_validates_user()
{
$path = base_path('tests/stubs/single_contact_stub.csv');
$this->artisan('import:csv', [
'user' => 'test@test.com',
'file' => $path,
])
->assertFailed()
->expectsOutput('You need to provide a valid User ID or email address!')
->run();
}
/** @test */
public function csv_import_validates_file()
{
$user = $this->getUser();
$this->artisan('import:csv', [
'user' => $user->email,
'file' => 'xxx',
])
->assertFailed()
->expectsOutput('You need to provide a valid file path.')
->run();
}
private function getUser()
{
$account = Account::createDefault('John', 'Doe', 'johndoe@example.com', 'secret', null, 'en');
return $account->users()->first();
}
}

View File

@@ -0,0 +1,104 @@
<?php
namespace Tests\Commands\Other;
use Tests\TestCase;
use App\Models\Account\Account;
use App\Models\Contact\Contact;
use Illuminate\Support\Facades\Storage;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ImportVCardsTest extends TestCase
{
use DatabaseTransactions;
/** @test */
public function it_validates_user()
{
$path = base_path('tests/stubs/vcard_stub.vcf');
$this->artisan('import:vcard', ['--user' => 'notfound@example.com', '--path' => $path, '--no-interaction' => true])
->assertFailed()
->expectsOutput('No user with that email.')
->run();
}
/** @test */
public function it_validates_file()
{
$user = $this->getUser();
$this->artisan('import:vcard', ['--user' => $user->email, '--path' => 'not_found', '--no-interaction' => true])
->assertFailed()
->expectsOutput('The provided vcard file was not found or is not valid!')
->run();
}
/** @test */
public function it_imports_contacts()
{
Storage::fake('public');
$user = $this->getUser();
$path = base_path('tests/stubs/vcard_stub.vcf');
$totalContacts = Contact::where('account_id', $user->account_id)->count();
$this->artisan('import:vcard', ['--user' => $user->email, '--path' => $path, '--no-interaction' => true])
->assertSuccessful()
->run();
$this->assertDatabaseHas('contacts', [
'first_name' => 'John',
'last_name' => 'Doe',
]);
$this->assertDatabaseHas('contact_fields', [
'data' => 'john.doe@example.com',
]);
// Allows checking if birthday was correctly set
$this->assertDatabaseHas('special_dates', [
'date' => '1960-05-10',
]);
// Allows checking nickname fallback
$this->assertDatabaseHas('contacts', [
'first_name' => 'Johnny',
]);
$this->assertDatabaseHas('contacts', [
'company' => 'U2',
'job' => 'Lead vocalist',
]);
// Allows checking addresses are correctly saved
$this->assertDatabaseHas('places', [
'street' => '17 Shakespeare Ave.',
'postal_code' => 'SO17 2HB',
'city' => 'Southampton',
'country' => 'GB',
]);
$this->assertDatabaseHas('contact_fields', [
'data' => 'bono@example.com',
]);
$this->assertDatabaseHas('contact_fields', [
'data' => '+1 202-555-0191',
]);
// Asserts that only 3 new contacts were created
$this->assertEquals(
$totalContacts + 3,
Contact::where('account_id', $user->account_id)->count()
);
}
private function getUser()
{
$account = Account::createDefault('John', 'Doe', 'johndoe@example.com', 'secret', null, 'en');
return $account->users()->first();
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace Tests\Commands\Other;
use Tests\TestCase;
use App\Console\Commands\Helpers\Command;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class UpdateCommandTest extends TestCase
{
use DatabaseTransactions;
/** @test */
public function update_command_default()
{
/** @var \Tests\Helpers\CommandCallerFake */
$fake = Command::fake();
$this->artisan('monica:update')->run();
$this->assertCount(9, $fake->buffer);
$this->assertCommandContains($fake->buffer[0], 'Maintenance mode: on', 'php artisan down');
$this->assertCommandContains($fake->buffer[1], 'Resetting application cache', 'php artisan cache:clear');
$this->assertCommandContains($fake->buffer[2], 'Clear config cache', 'php artisan config:clear');
$this->assertCommandContains($fake->buffer[3], 'Clear route cache', 'php artisan route:clear');
$this->assertCommandContains($fake->buffer[4], 'Clear view cache', 'php artisan view:clear');
$this->assertCommandContains($fake->buffer[5], 'Performing migrations', 'php artisan migrate');
$this->assertCommandContains($fake->buffer[6], 'Check for encryption keys', 'php artisan monica:passport');
$this->assertCommandContains($fake->buffer[7], 'Ping for new version', 'php artisan monica:ping');
$this->assertCommandContains($fake->buffer[8], 'Maintenance mode: off', 'php artisan up');
}
/** @test */
public function update_command_composer()
{
/** @var \Tests\Helpers\CommandCallerFake */
$fake = Command::fake();
$this->artisan('monica:update', ['--composer-install' => true])->run();
$this->assertCount(10, $fake->buffer);
$this->assertCommandContains($fake->buffer[0], 'Maintenance mode: on', 'php artisan down');
$this->assertCommandContains($fake->buffer[1], 'Resetting application cache', 'php artisan cache:clear');
$this->assertCommandContains($fake->buffer[2], 'Clear config cache', 'php artisan config:clear');
$this->assertCommandContains($fake->buffer[3], 'Clear route cache', 'php artisan route:clear');
$this->assertCommandContains($fake->buffer[4], 'Clear view cache', 'php artisan view:clear');
$this->assertCommandContains($fake->buffer[5], 'Updating composer dependencies', 'composer install');
$this->assertCommandContains($fake->buffer[6], 'Performing migrations', 'php artisan migrate');
$this->assertCommandContains($fake->buffer[7], 'Check for encryption keys', 'php artisan monica:passport');
$this->assertCommandContains($fake->buffer[8], 'Ping for new version', 'php artisan monica:ping');
$this->assertCommandContains($fake->buffer[9], 'Maintenance mode: off', 'php artisan up');
}
private function assertCommandContains($array, $message, $command)
{
$this->assertStringContainsString($message, $array['message']);
$this->assertStringContainsString($command, $array['command']);
}
}