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:
71
tests/Commands/Tests/PassportCommandTest.php
Normal file
71
tests/Commands/Tests/PassportCommandTest.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Commands\Tests;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Console\Commands\Helpers\Command;
|
||||
use Laravel\Passport\PersonalAccessClient;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class PassportCommandTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (! file_exists(base_path('storage/oauth-private.key')) || ! file_exists(base_path('storage/oauth-public.key'))) {
|
||||
$this->markTestSkipped('Run "php artisan key:generate" before executing these tests.');
|
||||
}
|
||||
|
||||
foreach (PersonalAccessClient::all() as $client) {
|
||||
$client->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function passport_command_create()
|
||||
{
|
||||
/** @var \Tests\Helpers\CommandCallerFake */
|
||||
$fake = Command::fake();
|
||||
|
||||
$this->artisan('monica:passport')->run();
|
||||
|
||||
$this->assertCount(1, $fake->buffer, $fake->buffer->implode(','));
|
||||
$this->assertCommandContains($fake->buffer[0], '✓ Creating personal access client', 'php artisan passport:client');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function passport_command_already_created()
|
||||
{
|
||||
/** @var \Tests\Helpers\CommandCallerFake */
|
||||
$fake = Command::fake();
|
||||
|
||||
PersonalAccessClient::create();
|
||||
|
||||
$this->artisan('monica:passport')->run();
|
||||
|
||||
$this->assertCount(0, $fake->buffer, $fake->buffer->implode(','));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function passport_command_env_config()
|
||||
{
|
||||
/** @var \Tests\Helpers\CommandCallerFake */
|
||||
$fake = Command::fake();
|
||||
|
||||
config(['passport.private_key' => '-', 'passport.public_key' => '-']);
|
||||
|
||||
$this->artisan('monica:passport')->run();
|
||||
|
||||
$this->assertCount(1, $fake->buffer, $fake->buffer->implode(','));
|
||||
$this->assertCommandContains($fake->buffer[0], '✓ Creating personal access client', 'php artisan passport:client');
|
||||
}
|
||||
|
||||
private function assertCommandContains($array, $message, $command)
|
||||
{
|
||||
$this->assertStringContainsString($message, $array['message']);
|
||||
$this->assertStringContainsString($command, $array['command']);
|
||||
}
|
||||
}
|
||||
55
tests/Commands/Tests/SendTestEmailTest.php
Normal file
55
tests/Commands/Tests/SendTestEmailTest.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Commands\Tests;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class SendTestEmailTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function error_for_bad_email()
|
||||
{
|
||||
$exampleEmail = 'no.at.symbol';
|
||||
|
||||
$this->artisan('monica:test-email', ['--email' => $exampleEmail])
|
||||
->expectsOutput("Invalid email address: \"$exampleEmail\".")
|
||||
->assertFailed()
|
||||
->run();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function command_prompts_for_email()
|
||||
{
|
||||
$exampleEmail = 'no.at.symbol';
|
||||
|
||||
$this->artisan('monica:test-email')
|
||||
->expectsQuestion('What email address should I send the test email to?', $exampleEmail)
|
||||
->expectsOutput("Invalid email address: \"$exampleEmail\".")
|
||||
->assertFailed()
|
||||
->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function command_attempts_to_send_email()
|
||||
{
|
||||
$exampleEmail = 'test@example.org';
|
||||
|
||||
Mail::shouldReceive('raw')
|
||||
->once()
|
||||
->withArgs(function ($message, $closure) use ($exampleEmail) {
|
||||
$this->assertEquals(
|
||||
"Hi $exampleEmail, you requested a test email from Monica.",
|
||||
$message
|
||||
);
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
$this->artisan('monica:test-email', ['--email' => $exampleEmail])
|
||||
->assertSuccessful()
|
||||
->run();
|
||||
}
|
||||
}
|
||||
25
tests/Commands/Tests/SetupFrontEndTestUserTest.php
Normal file
25
tests/Commands/Tests/SetupFrontEndTestUserTest.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Commands\Tests;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User\User;
|
||||
use App\Models\Account\Account;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class SetupFrontEndTestUserTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_create_a_test_user()
|
||||
{
|
||||
$accountCount = Account::count();
|
||||
$userCount = User::count();
|
||||
|
||||
$this->artisan('setup:frontendtestuser')->run();
|
||||
|
||||
$this->assertEquals($accountCount + 1, Account::count());
|
||||
$this->assertEquals($userCount + 1, User::count());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user