- E-Mail-Aenderung durch Berater wird erst nach Bestaetigung durch den Kunden aktiv (Link an die neue Adresse, Portal kunde/email-bestaetigen); danach ziehen alle Eintraege des Kunden und seine Abos mit. Admins aendern direkt. - Kundenhoheit: E-Mail eines Beraterkontos oder eines Kunden eines anderen Beraters wird abgelehnt (beim Speichern und bei der Bestaetigung). - Fix CustomerPriority::entryExists: aelteste gepruefte Zuordnung gilt, Eintraege in Pruefung (is_like) dienen nicht mehr als Vorlage. - "Berater zuweisen" voreingestellt auf alle Bestellungen des Kunden. - Neue Admin-Seite Kundenhoheit: offene Pruefungen, Kunden bei mehreren Beratern, abgelehnte/offene E-Mail-Aenderungen; Zaehler im Menue. - Neue Tabelle shopping_user_email_changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
2.7 KiB
PHP
85 lines
2.7 KiB
PHP
<?php
|
|
|
|
use App\Models\Country;
|
|
use App\Models\ShoppingUser;
|
|
use App\Services\CustomerPriority;
|
|
use App\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Tests\TestCase;
|
|
|
|
uses(TestCase::class, RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
Mail::fake();
|
|
|
|
$this->country = Country::create([
|
|
'code' => 'DE', 'phone' => '49', 'en' => 'Germany', 'de' => 'Deutschland',
|
|
'es' => 'Alemania', 'fr' => 'Allemagne', 'it' => 'Germania', 'ru' => 'Германия',
|
|
]);
|
|
|
|
$this->owner = cpeConsultant();
|
|
$this->other = cpeConsultant();
|
|
});
|
|
|
|
function cpeConsultant(): User
|
|
{
|
|
return User::forceCreate([
|
|
'email' => 'cpe-'.uniqid('', true).'@example.com',
|
|
'password' => Hash::make('secret'),
|
|
'lang' => 'de',
|
|
'active' => 1,
|
|
]);
|
|
}
|
|
|
|
function cpeEntry(array $attributes = []): ShoppingUser
|
|
{
|
|
return ShoppingUser::create(array_merge([
|
|
'auth_user_id' => null,
|
|
'billing_firstname' => 'Karola',
|
|
'billing_lastname' => 'Home',
|
|
'billing_address' => 'Weg 1',
|
|
'billing_zipcode' => '11111',
|
|
'billing_city' => 'Stadt',
|
|
'billing_email' => 'karola@example.com',
|
|
'billing_country_id' => test()->country->id,
|
|
'shipping_country_id' => test()->country->id,
|
|
'is_from' => 'shopping',
|
|
], $attributes));
|
|
}
|
|
|
|
it('ordnet eine neue Bestellung der ältesten geprüften Zuordnung zu, nicht einem Eintrag in Prüfung', function () {
|
|
$established = cpeEntry(['member_id' => $this->owner->id, 'number' => 100]);
|
|
cpeEntry(['member_id' => $this->other->id, 'number' => 200, 'is_like' => true]);
|
|
$new = cpeEntry();
|
|
|
|
expect(CustomerPriority::checkOne($new))->toBe('exists');
|
|
|
|
$new->refresh();
|
|
expect($new->member_id)->toBe($this->owner->id)
|
|
->and($new->number)->toBe($established->number);
|
|
});
|
|
|
|
it('nimmt bei mehreren geprüften Zuordnungen die älteste', function () {
|
|
cpeEntry(['member_id' => $this->owner->id, 'number' => 100]);
|
|
cpeEntry(['member_id' => $this->other->id, 'number' => 200]);
|
|
$new = cpeEntry();
|
|
|
|
CustomerPriority::checkOne($new);
|
|
|
|
expect($new->fresh()->member_id)->toBe($this->owner->id)
|
|
->and($new->fresh()->number)->toBe(100);
|
|
});
|
|
|
|
it('übernimmt keine Zuordnung von einem Eintrag in Prüfung, sondern prüft den Kunden selbst', function () {
|
|
cpeEntry(['member_id' => $this->other->id, 'number' => 200, 'is_like' => true]);
|
|
$new = cpeEntry();
|
|
|
|
expect(CustomerPriority::checkOne($new, false, false))->toStartWith('like');
|
|
|
|
$new->refresh();
|
|
expect((bool) $new->is_like)->toBeTrue()
|
|
->and($new->number)->toBeNull()
|
|
->and($new->member_id)->toBeNull();
|
|
});
|