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(); });