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,26 @@
<?php
namespace Tests\Commands\Scheduling;
use Tests\TestCase;
use Illuminate\Database\QueryException;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class CalculateStatisticsTest extends TestCase
{
use DatabaseTransactions;
/** @test */
public function the_command_runs_well()
{
$runsWell = true;
try {
$this->artisan('monica:calculatestatistics')->run();
} catch (QueryException $e) {
$runsWell = false;
}
$this->assertTrue($runsWell);
}
}

View File

@@ -0,0 +1,119 @@
<?php
namespace Tests\Commands\Scheduling;
use Carbon\Carbon;
use Tests\TestCase;
use App\Models\Instance\Cron;
use App\Console\Scheduling\CronEvent;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class CronEventTest extends TestCase
{
use DatabaseTransactions;
/** @test */
public function it_get_the_right_command()
{
$cron = factory(Cron::class)->create();
$event = CronEvent::command($cron->command);
$this->assertEquals($event->cron()->id, $cron->id);
}
/** @test */
public function now_not_due()
{
$cron = factory(Cron::class)->create();
$event = new CronEvent($cron);
$this->assertFalse($event->isDue());
}
/** @test */
public function next_minute_is_due()
{
Carbon::setTestNow(Carbon::create(2019, 5, 1, 7, 0, 0));
$cron = factory(Cron::class)->create();
$event = new CronEvent($cron);
$this->assertFalse($event->isDue());
Carbon::setTestNow(Carbon::create(2019, 5, 1, 7, 1, 0));
$this->assertTrue($event->isDue());
$this->assertDatabaseHas('crons', [
'command' => $cron->command,
'last_run' => '2019-05-01 07:01:00',
]);
}
/** @test */
public function hourly_cron()
{
Carbon::setTestNow(Carbon::create(2019, 5, 1, 7, 0, 0));
$cron = factory(Cron::class)->create();
$event = new CronEvent($cron);
$event->hourly();
$this->assertFalse($event->isDue());
Carbon::setTestNow(Carbon::create(2019, 5, 1, 8, 22, 0));
$this->assertTrue($event->isDue());
$this->assertDatabaseHas('crons', [
'command' => $cron->command,
'last_run' => '2019-05-01 08:22:00',
]);
Carbon::setTestNow(Carbon::create(2019, 5, 1, 8, 59, 0));
$this->assertFalse($event->isDue());
Carbon::setTestNow(Carbon::create(2019, 5, 1, 9, 01, 0));
$this->assertTrue($event->isDue());
$this->assertDatabaseHas('crons', [
'command' => $cron->command,
'last_run' => '2019-05-01 09:01:00',
]);
}
/** @test */
public function daily_cron()
{
Carbon::setTestNow(Carbon::create(2019, 5, 1, 7, 0, 0));
$cron = factory(Cron::class)->create();
$event = new CronEvent($cron);
$event->daily();
Carbon::setTestNow(Carbon::create(2019, 5, 2, 8, 10, 0));
$this->assertTrue($event->isDue());
$this->assertDatabaseHas('crons', [
'command' => $cron->command,
'last_run' => '2019-05-02 08:10:00',
]);
Carbon::setTestNow(Carbon::create(2019, 5, 2, 10, 0, 0));
$this->assertFalse($event->isDue());
Carbon::setTestNow(Carbon::create(2019, 5, 3, 0, 0, 0));
$this->assertTrue($event->isDue());
$this->assertDatabaseHas('crons', [
'command' => $cron->command,
'last_run' => '2019-05-03 00:00:00',
]);
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace Tests\Commands\Scheduling;
use Tests\TestCase;
use App\Jobs\SynchronizeAddressBooks;
use Illuminate\Support\Facades\Queue;
use App\Models\Account\AddressBookSubscription;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class DavClientsUpdateTest extends TestCase
{
use DatabaseTransactions;
/** @test */
public function it_dispatch_subscription_update()
{
Queue::fake();
$subscription = AddressBookSubscription::factory()->create();
$this->artisan('monica:davclients')->run();
Queue::assertPushed(SynchronizeAddressBooks::class, function ($job) use ($subscription) {
return $job->subscription->id === $subscription->id;
});
}
}

View File

@@ -0,0 +1,101 @@
<?php
namespace Tests\Commands\Scheduling;
use Tests\TestCase;
use App\Models\Instance\Instance;
use Illuminate\Support\Facades\Http;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class PingVersionServerTest extends TestCase
{
use DatabaseTransactions;
/** @test */
public function it_send_ping()
{
config(['monica.weekly_ping_server_url' => 'https://version.test/ping']);
config(['monica.app_version' => '2.9.0']);
config(['monica.check_version' => true]);
Instance::all()->each(function ($instance) {
$instance->delete();
});
$instance = factory(Instance::class)->create();
$ret = [
'new_version' => true,
'latest_version' => '3.1.0',
'number_of_versions_since_user_version' => 2,
'notes' => 'notes',
];
Http::fake([
'https://version.test/*' => Http::response($ret, 200),
]);
$this->artisan('monica:ping')->run();
$instance->refresh();
$this->assertEquals('3.1.0', $instance->latest_version);
$this->assertEquals('notes', $instance->latest_release_notes);
$this->assertEquals(2, $instance->number_of_versions_since_current_version);
}
/** @test */
public function it_clear_instance()
{
config(['monica.weekly_ping_server_url' => 'https://version.test/ping']);
config(['monica.app_version' => '3.1.0']);
Instance::all()->each(function ($instance) {
$instance->delete();
});
$instance = factory(Instance::class)->create([
'latest_version' => '3.1.0',
]);
$ret = [
'new_version' => false,
'latest_version' => '2.9.0',
'number_of_versions_since_user_version' => 0,
'notes' => '',
];
Http::fake([
'https://version.test/*' => Http::response($ret, 200),
]);
$this->artisan('monica:ping')->run();
$instance->refresh();
$this->assertEquals('3.1.0', $instance->latest_version);
$this->assertNull($instance->latest_release_notes);
$this->assertNull($instance->number_of_versions_since_current_version);
}
/**
* If an instance sets `version_check` env variable to false, the command
* should exit with 0.
*
* @return void
*/
public function test_check_version_set_to_false_disables_the_check()
{
config(['monica.weekly_ping_server_url' => 'https://version.test/ping']);
config(['monica.app_version' => '2.9.0']);
config(['monica.check_version' => false]);
$fake = Http::fake([
'https://version.test/*' => Http::response([], 500),
]);
$this->artisan('monica:ping')
->assertSuccessful()
->run();
$fake->assertNothingSent();
}
}

View File

@@ -0,0 +1,78 @@
<?php
namespace Tests\Commands\Scheduling;
use Carbon\Carbon;
use Tests\TestCase;
use App\Models\User\User;
use App\Models\Account\Account;
use App\Models\Contact\Contact;
use App\Models\Contact\Reminder;
use Illuminate\Support\Facades\Bus;
use App\Models\Contact\ReminderOutbox;
use App\Jobs\Reminder\NotifyUserAboutReminder;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class SendRemindersTest extends TestCase
{
use DatabaseTransactions;
/** @test */
public function it_schedules_a_reminder_email_job()
{
Bus::fake();
Carbon::setTestNow(Carbon::create(2017, 1, 1, 7, 0, 0));
$account = factory(Account::class)->create([
'default_time_reminder_is_sent' => '07:00',
]);
$contact = factory(Contact::class)->create(['account_id' => $account->id]);
$user = factory(User::class)->create(['account_id' => $account->id]);
$reminder = factory(Reminder::class)->create([
'account_id' => $account->id,
'contact_id' => $contact->id,
'initial_date' => '2017-01-01',
]);
factory(ReminderOutbox::class)->create([
'account_id' => $account->id,
'reminder_id' => $reminder->id,
'user_id' => $user->id,
'planned_date' => '2017-01-01',
]);
$this->artisan('send:reminders')->run();
Bus::assertDispatched(NotifyUserAboutReminder::class);
}
/** @test */
public function it_doesnt_schedule_a_notification_if_it_is_not_the_right_time()
{
Bus::fake();
Carbon::setTestNow(Carbon::create(2017, 1, 1, 7, 0, 0));
$account = factory(Account::class)->create([
'default_time_reminder_is_sent' => '08:00',
]);
$contact = factory(Contact::class)->create(['account_id' => $account->id]);
$user = factory(User::class)->create([
'account_id' => $account->id,
]);
$reminder = factory(Reminder::class)->create([
'account_id' => $account->id,
'contact_id' => $contact->id,
'initial_date' => '2017-01-01',
]);
$reminderOutbox = factory(ReminderOutbox::class)->create([
'account_id' => $account->id,
'reminder_id' => $reminder->id,
'user_id' => $user->id,
'planned_date' => '2017-01-01',
]);
$this->artisan('send:reminders')->run();
Bus::assertNotDispatched(NotifyUserAboutReminder::class);
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace Tests\Commands\Scheduling;
use Carbon\Carbon;
use Tests\TestCase;
use App\Models\Account\Account;
use App\Models\Contact\Contact;
use Illuminate\Support\Facades\Bus;
use App\Jobs\StayInTouch\ScheduleStayInTouch;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class SendStayInTouchTest extends TestCase
{
use DatabaseTransactions;
/** @test */
public function it_schedules_a_stay_in_touch_job()
{
Bus::fake();
Carbon::setTestNow(Carbon::create(2017, 1, 1, 7, 0, 0));
$account = factory(Account::class)->create([]);
$contact = factory(Contact::class)->create([
'account_id' => $account->id,
'stay_in_touch_trigger_date' => '2017-01-01 07:00:00',
'stay_in_touch_frequency' => 30,
]);
$this->artisan('send:stay_in_touch')->run();
Bus::assertDispatched(ScheduleStayInTouch::class);
}
/** @test */
public function it_doesnt_schedule_stay_in_touch_jobs_if_no_date_is_found()
{
Bus::fake();
Carbon::setTestNow(Carbon::create(2017, 1, 1, 7, 0, 0));
$account = factory(Account::class)->create([]);
$contact = factory(Contact::class)->create([
'account_id' => $account->id,
'stay_in_touch_trigger_date' => '2017-03-01 07:00:00',
'stay_in_touch_frequency' => 30,
]);
$this->artisan('send:stay_in_touch')->run();
Bus::assertNotDispatched(ScheduleStayInTouch::class);
}
}