Skip to content

Commit 7acd8d8

Browse files
committed
Changelog:
- Fixed: reward execution - Added: test reward system
1 parent 41c4b97 commit 7acd8d8

File tree

9 files changed

+112
-286645
lines changed

9 files changed

+112
-286645
lines changed

app/Jobs/ComputeCustomerAccountJob.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
namespace App\Jobs;
44

55
use App\Events\OrderAfterCreatedEvent;
6-
use App\Events\OrderAfterPaymentCreatedEvent;
76
use App\Events\OrderAfterRefundedEvent;
87
use App\Events\OrderAfterUpdatedEvent;
98
use App\Events\OrderBeforeDeleteEvent;
109
use App\Models\Order;
11-
use App\Models\OrderPayment;
1210
use App\Services\CustomerService;
1311
use Illuminate\Bus\Queueable;
1412
use Illuminate\Contracts\Queue\ShouldQueue;

app/Models/Customer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public function coupons()
2525
return $this->hasMany( CustomerCoupon::class, 'customer_id' );
2626
}
2727

28+
public function rewards()
29+
{
30+
return $this->hasMany( CustomerReward::class, 'customer_id' );
31+
}
32+
2833
/**
2934
* define the relationship
3035
* @return Model\RelationShip

app/Services/CustomerService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ public function applyReward( CustomerReward $customerReward, Customer $customer,
373373
* we'll issue a new coupon and update the customer
374374
* point counter
375375
*/
376-
if ( $customerReward->points - $customerReward->target >= 0 ) {
376+
if ( $customerReward->points >= $customerReward->target ) {
377377
$coupon = $reward->coupon;
378378

379379
if ( $coupon instanceof Coupon ) {

public/css/app.css

Lines changed: 4 additions & 281968 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/manifest.js

Lines changed: 2 additions & 195 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/pos-init.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/pos.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/vendor.js

Lines changed: 3 additions & 4477 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Feature/TestRewardSystem.php

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
namespace Tests\Feature;
4+
5+
use App\Models\Customer;
6+
use App\Models\Product;
7+
use App\Models\RewardSystem;
8+
use App\Models\Role;
9+
use Illuminate\Foundation\Testing\RefreshDatabase;
10+
use Illuminate\Foundation\Testing\WithFaker;
11+
use Laravel\Sanctum\Sanctum;
12+
use Tests\TestCase;
13+
14+
class TestRewardSystem extends TestCase
15+
{
16+
use WithFaker;
17+
18+
/**
19+
* A basic feature test example.
20+
*
21+
* @return void
22+
*/
23+
public function test_reward_system()
24+
{
25+
Sanctum::actingAs(
26+
Role::namespace( 'admin' )->users->first(),
27+
['*']
28+
);
29+
30+
$reward = RewardSystem::with( 'rules' )->first();
31+
$rules = $reward->rules->sortBy( 'reward' )->reverse();
32+
$timesForOrders = ( $reward->target / $rules->first()->reward );
33+
34+
$product = Product::withStockEnabled()->get()->random();
35+
$unit = $product->unit_quantities()->where( 'quantity', '>', 0 )->first();
36+
$subtotal = $unit->sale_price * 5;
37+
$shippingFees = 0;
38+
39+
$customer = Customer::first();
40+
41+
if ( ! $customer->group->reward instanceof RewardSystem ) {
42+
$customer->group->reward_system_id = $reward->id;
43+
$customer->group->save();
44+
}
45+
46+
$previousCoupons = $customer->coupons()->count();
47+
48+
for( $i = 0; $i < $timesForOrders; $i++ ) {
49+
$response = $this->withSession( $this->app[ 'session' ]->all() )
50+
->json( 'POST', 'api/nexopos/v4/orders', [
51+
'customer_id' => $customer->id,
52+
'type' => [ 'identifier' => 'takeaway' ],
53+
// 'discount_type' => 'percentage',
54+
// 'discount_percentage' => 2.5,
55+
'addresses' => [
56+
'shipping' => [
57+
'name' => 'First Name Delivery',
58+
'surname' => 'Surname',
59+
'country' => 'Cameroon',
60+
],
61+
'billing' => [
62+
'name' => 'EBENE Voundi',
63+
'surname' => 'Antony Hervé',
64+
'country' => 'United State Seattle',
65+
]
66+
],
67+
'subtotal' => $subtotal,
68+
'shipping' => $shippingFees,
69+
'products' => [
70+
[
71+
'product_id' => $product->id,
72+
'quantity' => 1,
73+
'unit_price' => $this->faker->numberBetween( $rules->first()->from, $rules->first()->to ),
74+
'unit_quantity_id' => $unit->id,
75+
'custom' => 'retail'
76+
],
77+
],
78+
'payments' => [
79+
[
80+
'identifier' => 'paypal-payment',
81+
'value' => ns()->currency->define( $subtotal )
82+
->additionateBy( $shippingFees )
83+
->getRaw()
84+
]
85+
]
86+
]);
87+
88+
$response->assertStatus( 200 );
89+
}
90+
91+
$currentCoupons = $customer->coupons()->count();
92+
93+
$this->assertTrue( $previousCoupons < $currentCoupons, __( 'The coupons count has\'nt changed.' ) );
94+
}
95+
}

0 commit comments

Comments
 (0)