Neue Artisan-Commands DeleteAllKasSubdomains und DeletePartnerShopSubdomains zum Aufraeumen von KAS-/Partnershop-Subdomains, jeweils mit Feature-Tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
113 lines
3.7 KiB
PHP
113 lines
3.7 KiB
PHP
<?php
|
|
|
|
use App\Http\Controllers\Api\KasController;
|
|
use App\Models\UserShop;
|
|
use App\User;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Tests\TestCase;
|
|
|
|
uses(TestCase::class);
|
|
|
|
beforeEach(function () {
|
|
Schema::dropIfExists('user_shops');
|
|
Schema::dropIfExists('users');
|
|
|
|
Schema::create('users', function (Blueprint $table) {
|
|
$table->increments('id');
|
|
$table->string('email')->unique();
|
|
$table->string('password');
|
|
$table->char('lang', 2)->default('de');
|
|
$table->timestamps();
|
|
$table->softDeletes();
|
|
});
|
|
|
|
Schema::create('user_shops', function (Blueprint $table) {
|
|
$table->increments('id');
|
|
$table->unsignedInteger('user_id');
|
|
$table->string('name', 20)->unique();
|
|
$table->string('slug', 40)->unique();
|
|
$table->boolean('active')->default(false);
|
|
$table->timestamps();
|
|
$table->softDeletes();
|
|
});
|
|
});
|
|
|
|
afterEach(function () {
|
|
Schema::dropIfExists('user_shops');
|
|
Schema::dropIfExists('users');
|
|
});
|
|
|
|
it('führt ohne force nur einen dry run aus', function () {
|
|
UserShop::forceCreate([
|
|
'user_id' => User::forceCreate([
|
|
'email' => 'partner@example.test',
|
|
'password' => 'secret',
|
|
'lang' => 'de',
|
|
])->id,
|
|
'name' => 'Partner Shop',
|
|
'slug' => 'partner',
|
|
'active' => true,
|
|
]);
|
|
|
|
$kas = \Mockery::mock(KasController::class);
|
|
$kas->shouldReceive('action')
|
|
->once()
|
|
->with('get_subdomains')
|
|
->andReturn([
|
|
['subdomain_name' => 'partner.mivita.care', 'subdomain_path' => '/mein.mivita.care/public/'],
|
|
]);
|
|
$this->app->instance(KasController::class, $kas);
|
|
|
|
$this->artisan('subdomains:delete-partnershops')->assertSuccessful();
|
|
});
|
|
|
|
it('löscht passende partnershop subdomains mit force', function () {
|
|
UserShop::forceCreate([
|
|
'user_id' => User::forceCreate([
|
|
'email' => 'shop@example.test',
|
|
'password' => 'secret',
|
|
'lang' => 'de',
|
|
])->id,
|
|
'name' => 'Shop Eins',
|
|
'slug' => 'shop-eins',
|
|
'active' => true,
|
|
]);
|
|
|
|
$kas = \Mockery::mock(KasController::class);
|
|
$kas->shouldReceive('action')
|
|
->once()
|
|
->with('get_subdomains')
|
|
->andReturn([
|
|
['subdomain_name' => 'shop-eins.mivita.care', 'subdomain_path' => '/mein.mivita.care/public/'],
|
|
['subdomain_name' => 'api.mivita.care', 'subdomain_path' => '/mein.mivita.care/public/'],
|
|
['subdomain_name' => 'extern.mivita.care', 'subdomain_path' => '/andere-app/public/'],
|
|
]);
|
|
$kas->shouldReceive('action')
|
|
->once()
|
|
->with('delete_subdomain', ['subdomain_name' => 'shop-eins.mivita.care'])
|
|
->andReturn('TRUE');
|
|
|
|
$this->app->instance(KasController::class, $kas);
|
|
|
|
$this->artisan('subdomains:delete-partnershops --force')->assertSuccessful();
|
|
});
|
|
|
|
it('kann verwaiste partnershop subdomains über den kas pfad löschen', function () {
|
|
$kas = \Mockery::mock(KasController::class);
|
|
$kas->shouldReceive('action')
|
|
->once()
|
|
->with('get_subdomains')
|
|
->andReturn([
|
|
['subdomain_name' => 'alte-partnerin.mivita.care', 'subdomain_path' => '/mein.mivita.care/public/'],
|
|
['subdomain_name' => 'preview.mivita.care', 'subdomain_path' => '/mein.mivita.care/public/'],
|
|
]);
|
|
$kas->shouldReceive('action')
|
|
->once()
|
|
->with('delete_subdomain', ['subdomain_name' => 'alte-partnerin.mivita.care'])
|
|
->andReturn('TRUE');
|
|
|
|
$this->app->instance(KasController::class, $kas);
|
|
|
|
$this->artisan('subdomains:delete-partnershops --force --include-path-matches')->assertSuccessful();
|
|
});
|