- @include( 'common.dashboard.title' )
+ @include( 'common.dashboard.title' )
where([ 'customer' => '[0-9]+' ]);
+Route::get( 'customers/recently-active', [ CustomersController::class, 'getRecentlyActive' ]);
Route::get( 'customers/{customer}/orders', [ CustomersController::class, 'getOrders' ]);
Route::get( 'customers/{customer}/addresses', [ CustomersController::class, 'getAddresses' ]);
Route::get( 'customers/{customer}/group', [ CustomersController::class, 'getGroup' ]);
diff --git a/tests/Feature/CreateExpenseTest.php b/tests/Feature/CreateExpenseTest.php
index 048fd3017..c69c8a0ed 100644
--- a/tests/Feature/CreateExpenseTest.php
+++ b/tests/Feature/CreateExpenseTest.php
@@ -15,7 +15,7 @@ class CreateExpenseTest extends TestCase
*
* @return void
*/
- public function testExample()
+ public function testCreateAllExpenses()
{
$this->attemptAuthenticate();
$this->attemptCreateExpenses();
diff --git a/tests/Feature/CreateUserTest.php b/tests/Feature/CreateUserTest.php
index dcbb96f1f..3b96c42eb 100644
--- a/tests/Feature/CreateUserTest.php
+++ b/tests/Feature/CreateUserTest.php
@@ -117,6 +117,44 @@ public function test_create_users()
});
}
+ /**
+ * @depends test_created_users
+ */
+ public function test_delete_users()
+ {
+ Role::get()->map( function( Role $role ) {
+ $role->users()->get()->each( function( User $user ) {
+ $this->attemptAuthenticate( $user );
+
+ /**
+ * Step 1: attempt to delete himself
+ */
+
+ $response = $this->withSession( $this->app[ 'session' ]->all() )
+ ->json( 'delete', '/api/nexopos/v4/crud/ns.users/' . $user->id );
+
+ $response->assertStatus( 401 );
+ });
+ });
+
+ $user = Role::namespace( Role::ADMIN )->users()->first();
+
+ /**
+ * Step 2: try to delete a user who has some sales
+ */
+ $order = Order::where( 'author', '<>', $user->id )->first();
+
+ if ( $order instanceof Order ) {
+ $response = $this->withSession( $this->app[ 'session' ]->all() )
+ ->json( 'delete', '/api/nexopos/v4/crud/ns.users/' . $order->author );
+
+ $response->assertStatus( 401 );
+ }
+ }
+
+ /**
+ * @depends test_create_users
+ */
public function test_created_users()
{
$user = User::first();
@@ -125,11 +163,6 @@ public function test_created_users()
private function attemptAllRoutes( $user )
{
- /**
- * @var User $user
- */
- $user = User::findOrFail( $user->id );
-
$paramsModelBinding = [
'/\{product\}/' => Product::class,
'/\{provider\}/' => Provider::class,
diff --git a/tests/Traits/WithOrderTest.php b/tests/Traits/WithOrderTest.php
index 4e385eda0..67741214a 100644
--- a/tests/Traits/WithOrderTest.php
+++ b/tests/Traits/WithOrderTest.php
@@ -89,6 +89,7 @@ protected function attemptCreateOrderOnRegister( $data = [] )
]);
$cashRegister = Register::first();
+
$previousValue = $cashRegister->balance;
/**
@@ -128,15 +129,25 @@ protected function attemptCreateOrderOnRegister( $data = [] )
* from a specific moment
*/
$totalValue = ns()->currency->define( RegisterHistory::where( 'register_id', $cashRegister->id )
- ->where( 'created_at', '>', $specificMoment )
+ ->whereIn( 'action', RegisterHistory::IN_ACTIONS )
->sum( 'value' ) )->getRaw();
+ /**
+ * We should also take into account the change that produce
+ * records on the cash register history
+ */
+ $rawTotalChangeValue = RegisterHistory::where( 'action', RegisterHistory::ACTION_CHANGE )
+ ->where( 'register_id', $cashRegister->id )
+ ->sum( 'value' );
+
+ $totalChangeValue = ns()->currency->define( $rawTotalChangeValue )->getRaw();
+
/**
* only if the order total is greater than 0
*/
if ( (float) $response[ 'data' ][ 'order' ][ 'tendered' ] > 0 ) {
$this->assertNotEquals( $cashRegister->balance, $previousValue, __( 'There hasn\'t been any change during the transaction on the cash register balance.' ) );
- $this->assertEquals( (float) $cashRegister->balance, (float) ( $totalValue ), __( 'The cash register balance hasn\'t been updated correctly.' ) );
+ $this->assertEquals( (float) $cashRegister->balance, (float) ( ns()->currency->define( $totalValue )->subtractBy( $totalChangeValue )->getRaw() ), __( 'The cash register balance hasn\'t been updated correctly.' ) );
}
/**
@@ -145,6 +156,16 @@ protected function attemptCreateOrderOnRegister( $data = [] )
*/
$previousValue = (float) $cashRegister->balance;
+ /**
+ * let's assert only one history has been created
+ * for the selected cash register.
+ */
+ $historyCount = RegisterHistory::where( 'register_id', $cashRegister->id )
+ ->where( 'action', RegisterHistory::ACTION_SALE )
+ ->count();
+
+ $this->assertTrue( $historyCount == count( $response[ 'data' ][ 'order' ][ 'payments' ] ), 'The cash register history is not accurate' );
+
/**
* Step 2: We'll try here to delete order
* from the register and see if the balance is updated
@@ -227,6 +248,10 @@ protected function attemptCreateOrderOnRegister( $data = [] )
->from( $opening->created_at )
->action( RegisterHistory::ACTION_CASHOUT )->sum( 'value' );
+ $totalChange = RegisterHistory::register( $cashRegister )
+ ->from( $opening->created_at )
+ ->action( RegisterHistory::ACTION_CHANGE )->sum( 'value' );
+
$totalRefunds = RegisterHistory::register( $cashRegister )
->from( $opening->created_at )
->action( RegisterHistory::ACTION_REFUND )->sum( 'value' );
@@ -239,6 +264,7 @@ protected function attemptCreateOrderOnRegister( $data = [] )
->additionateBy( $totalCashing )
->additionateBy( $totalSales )
->subtractBy( $totalClosing )
+ ->subtractBy( $totalChange )
->subtractBy( $totalRefunds )
->subtractBy( $totalCashOut )
->subtractBy( $totalDelete )