Subdomain-Cleanup-Commands
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>
This commit is contained in:
parent
9b7665c59a
commit
84238c7694
4 changed files with 677 additions and 0 deletions
109
tests/Feature/DeleteAllKasSubdomainsCommandTest.php
Normal file
109
tests/Feature/DeleteAllKasSubdomainsCommandTest.php
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
use App\Http\Controllers\Api\KasController;
|
||||
use Tests\TestCase;
|
||||
|
||||
uses(TestCase::class);
|
||||
|
||||
it('erstellt ohne force nur eine temporäre kas liste', function () {
|
||||
$listFile = sys_get_temp_dir().'/kas-subdomains-dry-run-test-'.uniqid().'.json';
|
||||
|
||||
$kas = \Mockery::mock(KasController::class);
|
||||
$kas->shouldReceive('action')
|
||||
->once()
|
||||
->with('get_subdomains')
|
||||
->andReturn([
|
||||
['subdomain_name' => 'api.mivita.care', 'subdomain_path' => '/api/public/', 'php_version' => '8.2'],
|
||||
['subdomain_name' => 'shop.mivita.care', 'subdomain_path' => '/mein.mivita.care/public/', 'php_version' => '8.2'],
|
||||
]);
|
||||
|
||||
$this->app->instance(KasController::class, $kas);
|
||||
|
||||
$this->artisan('subdomains:delete-all-kas', [
|
||||
'--list-file' => $listFile,
|
||||
])->assertSuccessful();
|
||||
|
||||
$data = json_decode(file_get_contents($listFile), true);
|
||||
|
||||
expect(file_exists($listFile))->toBeTrue();
|
||||
expect($data['count'])->toBe(2);
|
||||
expect($data['subdomains'])->toHaveCount(2);
|
||||
expect($data['mode'])->toBe('dry-run');
|
||||
|
||||
@unlink($listFile);
|
||||
});
|
||||
|
||||
it('löscht mit force alle subdomains aus der kas liste ohne datenbankabgleich', function () {
|
||||
$listFile = sys_get_temp_dir().'/kas-subdomains-force-test-'.uniqid().'.json';
|
||||
|
||||
$kas = \Mockery::mock(KasController::class);
|
||||
$kas->shouldReceive('action')
|
||||
->once()
|
||||
->with('get_subdomains')
|
||||
->andReturn([
|
||||
['subdomain_name' => 'api.mivita.care', 'subdomain_path' => '/api/public/'],
|
||||
['subdomain_name' => 'preview.mivita.care', 'subdomain_path' => '/preview/public/'],
|
||||
['subdomain_name' => 'partner.mivita.care', 'subdomain_path' => '/mein.mivita.care/public/'],
|
||||
]);
|
||||
$kas->shouldReceive('action')
|
||||
->once()
|
||||
->with('delete_subdomain', ['subdomain_name' => 'api.mivita.care'])
|
||||
->andReturn('TRUE');
|
||||
$kas->shouldReceive('action')
|
||||
->once()
|
||||
->with('delete_subdomain', ['subdomain_name' => 'partner.mivita.care'])
|
||||
->andReturn('TRUE');
|
||||
$kas->shouldReceive('action')
|
||||
->once()
|
||||
->with('delete_subdomain', ['subdomain_name' => 'preview.mivita.care'])
|
||||
->andReturn('TRUE');
|
||||
|
||||
$this->app->instance(KasController::class, $kas);
|
||||
|
||||
$this->artisan('subdomains:delete-all-kas', [
|
||||
'--force' => true,
|
||||
'--list-file' => $listFile,
|
||||
])->assertSuccessful();
|
||||
|
||||
$data = json_decode(file_get_contents($listFile), true);
|
||||
|
||||
expect($data['count'])->toBe(3);
|
||||
expect($data['mode'])->toBe('delete');
|
||||
|
||||
@unlink($listFile);
|
||||
});
|
||||
|
||||
it('kann optional auf eine hauptdomain und ein limit begrenzen', function () {
|
||||
$listFile = sys_get_temp_dir().'/kas-subdomains-filter-test-'.uniqid().'.json';
|
||||
|
||||
$kas = \Mockery::mock(KasController::class);
|
||||
$kas->shouldReceive('action')
|
||||
->once()
|
||||
->with('get_subdomains')
|
||||
->andReturn([
|
||||
['subdomain_name' => 'a.mivita.care'],
|
||||
['subdomain_name' => 'b.mivita.care'],
|
||||
['subdomain_name' => 'extern.example.com'],
|
||||
]);
|
||||
$kas->shouldReceive('action')
|
||||
->once()
|
||||
->with('delete_subdomain', ['subdomain_name' => 'a.mivita.care'])
|
||||
->andReturn('TRUE');
|
||||
|
||||
$this->app->instance(KasController::class, $kas);
|
||||
|
||||
$this->artisan('subdomains:delete-all-kas', [
|
||||
'--force' => true,
|
||||
'--domain' => 'mivita.care',
|
||||
'--limit' => 1,
|
||||
'--list-file' => $listFile,
|
||||
])->assertSuccessful();
|
||||
|
||||
$data = json_decode(file_get_contents($listFile), true);
|
||||
|
||||
expect($data['count'])->toBe(1);
|
||||
expect($data['domain_filter'])->toBe('mivita.care');
|
||||
expect($data['subdomains'])->toHaveCount(1);
|
||||
|
||||
@unlink($listFile);
|
||||
});
|
||||
113
tests/Feature/DeletePartnerShopSubdomainsCommandTest.php
Normal file
113
tests/Feature/DeletePartnerShopSubdomainsCommandTest.php
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
<?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();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue