Add feature tests for shop functionality and organization purchases
Deploy Test / test (push) Successful in 1m38s
Deploy Test / deploy (push) Successful in 31s

- Implement OfferOptionAdminTest to validate offer option management, including price display, activation, and cancellation.
- Create OrganizationPurchaseTest to ensure correct handling of organization purchases, including access control and order processing.
- Add ShopProductPageTest to verify shop product listings, search functionality, and product page details.
- Introduce BuildsShop trait for seeding test data related to shop functionality.
- Implement MoneyTest to validate money parsing and formatting, ensuring correct handling of euro amounts.
This commit is contained in:
Lars committed 2026-11-21 12:06:24 +01:00
1 parent 6c8bbee363
commit 4e0760db1e
106 files changed
+4068 -76

No files matched your search

+1
View File
@@ -19,6 +19,7 @@ class Acquisition extends Model
'reference_type',
'reference_id',
'conditions',
'acting_user_id',
];
protected function casts(): array
+1 -1
View File
@@ -47,7 +47,7 @@ public function __invoke(
$candidates = Grant::query()
->where('license_article_id', $article->id)
->where('status', GrantStatus::Aktiv)
->whereHas('acquisition', fn ($query) => $query->where('party_id', $user->party_id))
->usableBy($user)
->get()
->filter(function (Grant $grant) use ($now): bool {
if ($grant->valid_from !== null && $grant->valid_from->greaterThan($now)) {
+29
View File
@@ -5,6 +5,9 @@
use App\Domain\Catalog\ArticleRelease;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\RightsProfileVersion;
use App\Domain\Identity\Membership;
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -32,6 +35,32 @@ protected function casts(): array
];
}
/**
* Berechtigungen, die ein Konto nutzen darf (zentrale Regel für Entscheidung, Bibliothek und Vorschaubilder):
* - persönliche Erwerbe: Inhaber ist die Person des Kontos;
* - Erwerbe einer Organisation: nur das auslösende Konto und nur, solange seine Mitgliedschaft mit
* Bestellberechtigung besteht (Etappe 1, Domänenmodell 04; Sitzpools folgen mit A4).
*
* @param Builder<Grant> $query
* @return Builder<Grant>
*/
public function scopeUsableBy(Builder $query, User $user): Builder
{
return $query->whereHas('acquisition', function (Builder $acquisition) use ($user): void {
$acquisition->where(function (Builder $either) use ($user): void {
$either->where('party_id', $user->party_id)
->orWhere(function (Builder $organisation) use ($user): void {
$organisation->where('acting_user_id', $user->id)
->whereIn('party_id', Membership::query()
->active()
->where('user_id', $user->id)
->where('may_order', true)
->select('party_id'));
});
});
});
}
public function acquisition(): BelongsTo
{
return $this->belongsTo(Acquisition::class);
+52
View File
@@ -7,6 +7,8 @@
use App\Domain\Catalog\OfferService;
use App\Domain\Catalog\OfferStatus;
use App\Domain\Catalog\OfferVersion;
use App\Domain\Commerce\OrderLine;
use App\Domain\Identity\Party;
use App\Models\User;
use Illuminate\Support\Facades\DB;
@@ -69,6 +71,56 @@ public function grantManually(User $user, Offer $offer, User $actor, string $rea
});
}
/**
* Freischaltung einer bezahlten Bestellposition aus deren festgehaltenem Umfang (Umfangskopie und Bedingungen der
* Position, nicht aus der Angebotsfassung). Inhaber ist der Lizenzinhaber der Position, das auslösende Konto wird
* am Erwerb festgehalten. Wiederholsicher: je Bestellposition genau ein Erwerb.
*/
public function issueFromOrderLine(OrderLine $line, Party $holder, User $actor): Acquisition
{
return DB::transaction(function () use ($line, $holder, $actor): Acquisition {
$existing = Acquisition::query()->where([
'party_id' => $holder->id,
'type' => AcquisitionType::Bestellposition,
'reference_type' => 'order_line',
'reference_id' => $line->id,
])->first();
if ($existing !== null) {
return $existing->load('grants');
}
$acquisition = Acquisition::query()->create([
'party_id' => $holder->id,
'type' => AcquisitionType::Bestellposition,
'reference_type' => 'order_line',
'reference_id' => $line->id,
'acting_user_id' => $actor->id,
'conditions' => [
'term_rule' => $line->term_rule,
'update_promise' => $line->update_promise,
'holder_kind' => $line->holder_kind,
'offer_version_id' => $line->offer_version_id,
],
]);
$line->loadMissing('scopeItems.article');
foreach ($line->scopeItems as $item) {
$acquisition->grants()->create([
'license_article_id' => $item->license_article_id,
'rights_profile_version_id' => $item->rights_profile_version_id,
'rights_snapshot' => $item->rights_snapshot,
'release_at_grant_id' => $item->article?->current_release_id,
'status' => GrantStatus::Aktiv,
'valid_from' => now(),
]);
}
return $acquisition->load('grants');
});
}
public function issue(
User $user,
OfferVersion $version,