Steuerberater Modul tax
This commit is contained in:
parent
0f82fea88a
commit
245c281541
22 changed files with 1489 additions and 139 deletions
|
|
@ -1,15 +1,23 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Country;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\UserAbo;
|
||||
use App\Repositories\AboRepository;
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(Tests\TestCase::class);
|
||||
uses(Tests\TestCase::class, RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->repository = new AboRepository;
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
Carbon::setTestNow();
|
||||
});
|
||||
|
||||
/**
|
||||
* Szenario: Heute = 15. März, next_date = 5. April (März-Ausführung bereits erfolgt).
|
||||
* Änderung auf Tag 20 → neues Datum soll der 20. April sein, NICHT der 20. März.
|
||||
|
|
@ -86,6 +94,54 @@ it('verwendet heute als Referenz wenn kein next_date gesetzt ist', function () {
|
|||
Carbon::setTestNow();
|
||||
});
|
||||
|
||||
it('erlaubt Admins den nächsten Ausführungstermin ohne User-Sperrfrist direkt zu setzen', function () {
|
||||
Carbon::setTestNow('2026-03-19 12:00:00');
|
||||
|
||||
$abo = createRepositoryTestAbo([
|
||||
'abo_interval' => 5,
|
||||
'next_date' => '2026-03-20',
|
||||
]);
|
||||
|
||||
$this->repository->setModel($abo);
|
||||
|
||||
$result = $this->repository->update([
|
||||
'action' => 'abo_update_settings',
|
||||
'id' => $abo->id,
|
||||
'view' => 'admin',
|
||||
'abo_interval' => 20,
|
||||
'abo_next_month' => '2026-03',
|
||||
'abo_is_active' => 'true',
|
||||
]);
|
||||
|
||||
expect($result)->toBeTrue();
|
||||
expect($abo->refresh()->abo_interval)->toBe(20);
|
||||
expect($abo->getRawOriginal('next_date'))->toBe('2026-03-20');
|
||||
});
|
||||
|
||||
it('behält die User-Sperrfrist für normale Abo-Änderungen bei', function () {
|
||||
Carbon::setTestNow('2026-03-19 12:00:00');
|
||||
|
||||
$abo = createRepositoryTestAbo([
|
||||
'abo_interval' => 5,
|
||||
'next_date' => '2026-03-20',
|
||||
]);
|
||||
|
||||
$this->actingAs($abo->user);
|
||||
$this->repository->setModel($abo);
|
||||
|
||||
$result = $this->repository->update([
|
||||
'action' => 'abo_update_settings',
|
||||
'id' => $abo->id,
|
||||
'view' => 'me',
|
||||
'abo_interval' => 20,
|
||||
'abo_is_active' => 'true',
|
||||
]);
|
||||
|
||||
expect($result)->toBeFalse();
|
||||
expect($abo->refresh()->abo_interval)->toBe(5);
|
||||
expect($abo->getRawOriginal('next_date'))->toBe('2026-03-20');
|
||||
});
|
||||
|
||||
/**
|
||||
* Hilfsfunktion zum Aufruf privater Methoden.
|
||||
*
|
||||
|
|
@ -98,3 +154,53 @@ function invadePrivateMethod(object $object, string $methodName, array $args = [
|
|||
|
||||
return $reflection->invoke($object, ...$args);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $overrides
|
||||
*/
|
||||
function createRepositoryTestAbo(array $overrides = []): UserAbo
|
||||
{
|
||||
$country = Country::create([
|
||||
'code' => 'DE',
|
||||
'phone' => '49',
|
||||
'en' => 'Germany',
|
||||
'de' => 'Deutschland',
|
||||
'es' => 'Alemania',
|
||||
'fr' => 'Allemagne',
|
||||
'it' => 'Germania',
|
||||
'ru' => 'Deutschland',
|
||||
]);
|
||||
|
||||
$user = User::forceCreate([
|
||||
'email' => 'abo-repository-'.uniqid('', true).'@example.com',
|
||||
'password' => bcrypt('secret'),
|
||||
'lang' => 'de',
|
||||
'admin' => 0,
|
||||
]);
|
||||
|
||||
$shoppingUser = ShoppingUser::create([
|
||||
'auth_user_id' => $user->id,
|
||||
'member_id' => $user->id,
|
||||
'billing_country_id' => $country->id,
|
||||
'shipping_country_id' => $country->id,
|
||||
'billing_email' => $user->email,
|
||||
'is_for' => 'me',
|
||||
'is_from' => 'user_order',
|
||||
]);
|
||||
|
||||
return UserAbo::create(array_merge([
|
||||
'user_id' => $user->id,
|
||||
'member_id' => $user->id,
|
||||
'shopping_user_id' => $shoppingUser->id,
|
||||
'is_for' => 'me',
|
||||
'email' => $user->email,
|
||||
'payone_userid' => random_int(100000, 999999),
|
||||
'clearingtype' => 'cc',
|
||||
'active' => true,
|
||||
'status' => 2,
|
||||
'abo_interval' => 5,
|
||||
'start_date' => '2026-01-05',
|
||||
'last_date' => '2026-02-05',
|
||||
'next_date' => '2026-03-05',
|
||||
], $overrides));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue