Skip to content

Commit ff94912

Browse files
committed
fix(price-lists): fix tests with updated logic
1 parent 7a2009d commit ff94912

1 file changed

Lines changed: 27 additions & 10 deletions

File tree

tests/Feature/PriceListTest.php

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use Eclipse\Catalogue\Models\PriceList;
44
use Eclipse\Catalogue\Models\PriceListData;
55
use Eclipse\World\Models\Currency;
6+
use Workbench\App\Models\Site;
67

78
beforeEach(function () {
89
// Create test currencies
@@ -19,6 +20,22 @@
1920
]);
2021
});
2122

23+
/**
24+
* Helper: create a PriceListData row including the tenant foreign key when
25+
* tenancy is enabled. Keeps the tests readable and future-proof.
26+
*/
27+
function createPriceListData(array $attributes): PriceListData
28+
{
29+
$tenantFK = config('eclipse-catalogue.tenancy.foreign_key');
30+
if ($tenantFK) {
31+
$siteId = Site::first()?->id;
32+
// Ensure we always include the tenant FK when required
33+
$attributes[$tenantFK] = $attributes[$tenantFK] ?? $siteId;
34+
}
35+
36+
return PriceListData::create($attributes);
37+
}
38+
2239
// Access Control Tests
2340
test('unauthenticated users cannot access price list index', function () {
2441
// Clear any authenticated user
@@ -122,7 +139,7 @@
122139
test('has price list data relationship', function () {
123140
$priceList = PriceList::factory()->create(['currency_id' => 'USD', 'tax_included' => false]);
124141

125-
PriceListData::create([
142+
createPriceListData([
126143
'price_list_id' => $priceList->id,
127144
'is_active' => true,
128145
'is_default' => false,
@@ -157,14 +174,14 @@
157174
$priceList2 = PriceList::factory()->create(['currency_id' => 'USD', 'tax_included' => false]);
158175

159176
// Create price list data for both as default selling
160-
PriceListData::create([
177+
createPriceListData([
161178
'price_list_id' => $priceList1->id,
162179
'is_active' => true,
163180
'is_default' => true,
164181
'is_default_purchase' => false,
165182
]);
166183

167-
PriceListData::create([
184+
createPriceListData([
168185
'price_list_id' => $priceList2->id,
169186
'is_active' => true,
170187
'is_default' => true,
@@ -188,14 +205,14 @@
188205
$priceList2 = PriceList::factory()->create(['currency_id' => 'USD', 'tax_included' => false]);
189206

190207
// Create price list data for both as default purchase
191-
PriceListData::create([
208+
createPriceListData([
192209
'price_list_id' => $priceList1->id,
193210
'is_active' => true,
194211
'is_default' => false,
195212
'is_default_purchase' => true,
196213
]);
197214

198-
PriceListData::create([
215+
createPriceListData([
199216
'price_list_id' => $priceList2->id,
200217
'is_active' => true,
201218
'is_default' => false,
@@ -216,14 +233,14 @@
216233
$sellingPriceList = PriceList::factory()->create(['currency_id' => 'USD', 'tax_included' => false]);
217234
$purchasePriceList = PriceList::factory()->create(['currency_id' => 'USD', 'tax_included' => false]);
218235

219-
PriceListData::create([
236+
createPriceListData([
220237
'price_list_id' => $sellingPriceList->id,
221238
'is_active' => true,
222239
'is_default' => true,
223240
'is_default_purchase' => false,
224241
]);
225242

226-
PriceListData::create([
243+
createPriceListData([
227244
'price_list_id' => $purchasePriceList->id,
228245
'is_active' => true,
229246
'is_default' => false,
@@ -243,7 +260,7 @@
243260
$priceList = PriceList::factory()->create(['currency_id' => 'USD', 'tax_included' => false]);
244261

245262
// Create data that violates the business rule
246-
$priceListData = PriceListData::create([
263+
$priceListData = createPriceListData([
247264
'price_list_id' => $priceList->id,
248265
'is_active' => true,
249266
'is_default' => true,
@@ -259,7 +276,7 @@
259276
test('get default selling price list works', function () {
260277
$priceList = PriceList::factory()->create(['currency_id' => 'USD', 'tax_included' => false]);
261278

262-
PriceListData::create([
279+
createPriceListData([
263280
'price_list_id' => $priceList->id,
264281
'is_active' => true,
265282
'is_default' => true,
@@ -275,7 +292,7 @@
275292
test('get default purchase price list works', function () {
276293
$priceList = PriceList::factory()->create(['currency_id' => 'USD', 'tax_included' => false]);
277294

278-
PriceListData::create([
295+
createPriceListData([
279296
'price_list_id' => $priceList->id,
280297
'is_active' => true,
281298
'is_default' => false,

0 commit comments

Comments
 (0)