test: Associate generated users and orders with outlets in dashboard analysis tests.
This commit is contained in:
parent
180a5b5282
commit
f545271040
@ -37,10 +37,13 @@
|
||||
// Member count (User with customer relation)
|
||||
$customerUser = User::factory()->create();
|
||||
Customer::factory()->create(['user_id' => $customerUser->id]);
|
||||
// Member must be attached to the outlet to be counted
|
||||
$customerUser->outlets()->attach($this->outlet->id);
|
||||
|
||||
// Employee count (User with employee relation)
|
||||
$employeeUser = User::factory()->create();
|
||||
\App\Models\Employee::factory()->create(['user_id' => $employeeUser->id]);
|
||||
$employeeUser->outlets()->attach($this->outlet->id);
|
||||
|
||||
Livewire::actingAs($this->user)
|
||||
->test(Analysis::class)
|
||||
@ -53,12 +56,14 @@
|
||||
it('filters data by pre-defined periods', function () {
|
||||
// Order from 10 days ago
|
||||
Order::factory()->paid()->create([
|
||||
'outlet_id' => $this->outlet->id,
|
||||
'total' => 100000,
|
||||
'created_at' => now()->subDays(10),
|
||||
]);
|
||||
|
||||
// Order from today
|
||||
Order::factory()->paid()->create([
|
||||
'outlet_id' => $this->outlet->id,
|
||||
'total' => 50000,
|
||||
'created_at' => now(),
|
||||
]);
|
||||
@ -75,12 +80,14 @@
|
||||
it('filters data by custom date range', function () {
|
||||
// Order in range
|
||||
Order::factory()->paid()->create([
|
||||
'outlet_id' => $this->outlet->id,
|
||||
'total' => 200000,
|
||||
'created_at' => Carbon::parse('2024-01-15'),
|
||||
]);
|
||||
|
||||
// Order out of range
|
||||
Order::factory()->paid()->create([
|
||||
'outlet_id' => $this->outlet->id,
|
||||
'total' => 100000,
|
||||
'created_at' => Carbon::parse('2024-02-15'),
|
||||
]);
|
||||
@ -97,14 +104,14 @@
|
||||
$p2 = Perfume::factory()->create(['name' => 'Perfume B', 'sale_price' => 2000]);
|
||||
|
||||
// Sale of Perfume A (Total sales: 1500)
|
||||
$o1 = Order::factory()->paid()->create();
|
||||
$o1 = Order::factory()->paid()->create(['outlet_id' => $this->outlet->id]);
|
||||
OrderItem::factory()->forOrder($o1)->forPerfume($p1)->create([
|
||||
'unit_price' => 500,
|
||||
'quantity' => 3,
|
||||
]);
|
||||
|
||||
// Sale of Perfume B (Total sales: 4000)
|
||||
$o2 = Order::factory()->paid()->create();
|
||||
$o2 = Order::factory()->paid()->create(['outlet_id' => $this->outlet->id]);
|
||||
OrderItem::factory()->forOrder($o2)->forPerfume($p2)->create([
|
||||
'unit_price' => 2000,
|
||||
'quantity' => 2,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user