This commit is contained in:
@@ -27,22 +27,22 @@ class CartController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function selectCity(Request $request) {
|
public function selectCity(Request $request) {
|
||||||
$matrix_username = $request->input('matrix_username') ?? '';
|
$matrixUsername = $request->input('matrixUsername') ?? '';
|
||||||
$city_name = $request->input('city_name') ?? '';
|
$cityName = $request->input('cityName') ?? '';
|
||||||
|
|
||||||
// check for not valid user
|
// check for not valid user
|
||||||
$validation = User::validate_with_matrix_username($matrix_username);
|
$validation = User::validate_with_matrix_username($matrixUsername);
|
||||||
if(array_key_exists('error', $validation))
|
if(array_key_exists('error', $validation))
|
||||||
return response()->json($validation);
|
return response()->json($validation);
|
||||||
|
|
||||||
// check for not valid city
|
// check for not valid city
|
||||||
$validation = City::validate_with_name($city_name);
|
$validation = City::validate_with_name($cityName);
|
||||||
if(array_key_exists('error', $validation))
|
if(array_key_exists('error', $validation))
|
||||||
return response()->json($validation);
|
return response()->json($validation);
|
||||||
|
|
||||||
// Get objects
|
// Get objects
|
||||||
$user = User::where('matrix_username', $matrix_username)->first();
|
$user = User::where('matrix_username', $matrixUsername)->first();
|
||||||
$city = City::where('name', $city_name)->first();
|
$city = City::where('name', $cityName)->first();
|
||||||
|
|
||||||
$cart = Cart::firstOrCreate(
|
$cart = Cart::firstOrCreate(
|
||||||
[
|
[
|
||||||
@@ -72,22 +72,22 @@ class CartController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function selectCompany(Request $request) {
|
public function selectCompany(Request $request) {
|
||||||
$matrix_username = $request->input('matrix_username') ?? '';
|
$matrixUsername = $request->input('matrixUsername') ?? '';
|
||||||
$company_name = $request->input('company_name') ?? '';
|
$companyName = $request->input('companyName') ?? '';
|
||||||
|
|
||||||
// check for not valid user
|
// check for not valid user
|
||||||
$validation = User::validate_with_matrix_username($matrix_username);
|
$validation = User::validate_with_matrix_username($matrixUsername);
|
||||||
if(array_key_exists('error', $validation))
|
if(array_key_exists('error', $validation))
|
||||||
return response()->json($validation);
|
return response()->json($validation);
|
||||||
|
|
||||||
// check for not valid company
|
// check for not valid company
|
||||||
$validation = Company::validate_with_name($company_name);
|
$validation = Company::validate_with_name($companyName);
|
||||||
if(array_key_exists('error', $validation))
|
if(array_key_exists('error', $validation))
|
||||||
return response()->json($validation);
|
return response()->json($validation);
|
||||||
|
|
||||||
// Get objects
|
// Get objects
|
||||||
$user = User::where('matrix_username', $matrix_username)->first();
|
$user = User::where('matrix_username', $matrixUsername)->first();
|
||||||
$company = Company::where('name', $company_name)->first();
|
$company = Company::where('name', $companyName)->first();
|
||||||
|
|
||||||
$cart = Cart::firstOrCreate([
|
$cart = Cart::firstOrCreate([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
|
|||||||
+101
-100
@@ -14,137 +14,137 @@ use App\Models\Cart;
|
|||||||
|
|
||||||
class CartTest extends TestCase
|
class CartTest extends TestCase
|
||||||
{
|
{
|
||||||
protected $test_user_username = 'Test';
|
protected $testUserUsername = 'Test';
|
||||||
protected $test_city_name = 'testCity';
|
protected $testCityName = 'testCity';
|
||||||
protected $test_city_name2 = 'testCity2';
|
protected $testCityName2 = 'testCity2';
|
||||||
protected $test_company_name = 'testCompany';
|
protected $testCompanyName = 'testCompany';
|
||||||
protected $test_company_name2 = 'testCompany2';
|
protected $testCompanyName2 = 'testCompany2';
|
||||||
|
|
||||||
protected $test_item_name = 'Pizza Polo';
|
protected $testItemName = 'Pizza Polo';
|
||||||
protected $test_item_name2 = 'Pizza Cezar';
|
protected $testItemName2 = 'Pizza Cezar';
|
||||||
|
|
||||||
protected $test_user;
|
protected $testUser;
|
||||||
protected $test_city;
|
protected $testCity;
|
||||||
protected $test_company;
|
protected $testCompany;
|
||||||
protected $test_item;
|
protected $testItem;
|
||||||
|
|
||||||
public function test_get_data(): void
|
public function test_get_data(): void
|
||||||
{
|
{
|
||||||
$this->test_user = User::where('username', $this->test_user_username)->first();
|
$this->testUser = User::where('username', $this->testUserUsername)->first();
|
||||||
$this->test_city = City::where('name', $this->test_city_name)->first();
|
$this->testCity = City::where('name', $this->testCityName)->first();
|
||||||
|
|
||||||
$this->assertNotNull($this->test_user);
|
$this->assertNotNull($this->testUser);
|
||||||
$this->assertNotNull($this->test_city);
|
$this->assertNotNull($this->testCity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_select_city_first_time(): void
|
public function test_select_city_first_time(): void
|
||||||
{
|
{
|
||||||
$this->test_user = User::where('username', $this->test_user_username)->first();
|
$this->testUser = User::where('username', $this->testUserUsername)->first();
|
||||||
$this->test_city = City::where('name', $this->test_city_name)->first();
|
$this->testCity = City::where('name', $this->testCityName)->first();
|
||||||
|
|
||||||
$this->assertNotNull($this->test_user);
|
$this->assertNotNull($this->testUser);
|
||||||
$this->assertNotNull($this->test_city);
|
$this->assertNotNull($this->testCity);
|
||||||
|
|
||||||
$response = $this->post('/api/v2/select-city', [
|
$response = $this->post('/api/v2/select-city', [
|
||||||
'matrix_username' => $this->test_user->matrix_username,
|
'matrixUsername' => $this->testUser->matrix_username,
|
||||||
'city_name' => $this->test_city->name,
|
'cityName' => $this->testCity->name,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
|
||||||
$response->assertJson([
|
$response->assertJson([
|
||||||
'ok' => 'City selected successfully',
|
'ok' => 'City selected successfully',
|
||||||
'name' => $this->test_city->name,
|
'name' => $this->testCity->name,
|
||||||
'uuid' => $this->test_city->uuid,
|
'uuid' => $this->testCity->uuid,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertDatabaseHas('carts', [
|
$this->assertDatabaseHas('carts', [
|
||||||
'city_id' => $this->test_city->id,
|
'city_id' => $this->testCity->id,
|
||||||
'user_id' => $this->test_user->id,
|
'user_id' => $this->testUser->id,
|
||||||
'status' => 'CART',
|
'status' => 'CART',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_select_another_city(): void
|
public function test_select_another_city(): void
|
||||||
{
|
{
|
||||||
$this->test_user = User::where('username', $this->test_user_username)->first();
|
$this->testUser = User::where('username', $this->testUserUsername)->first();
|
||||||
$this->test_city = City::where('name', $this->test_city_name2)->first();
|
$this->testCity = City::where('name', $this->testCityName2)->first();
|
||||||
|
|
||||||
$this->assertNotNull($this->test_user);
|
$this->assertNotNull($this->testUser);
|
||||||
$this->assertNotNull($this->test_city);
|
$this->assertNotNull($this->testCity);
|
||||||
|
|
||||||
$response = $this->post('/api/v2/select-city', [
|
$response = $this->post('/api/v2/select-city', [
|
||||||
'matrix_username' => $this->test_user->matrix_username,
|
'matrixUsername' => $this->testUser->matrix_username,
|
||||||
'city_name' => $this->test_city->name,
|
'cityName' => $this->testCity->name,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
|
||||||
$response->assertJson([
|
$response->assertJson([
|
||||||
'ok' => 'City changed successfully',
|
'ok' => 'City changed successfully',
|
||||||
'name' => $this->test_city->name,
|
'name' => $this->testCity->name,
|
||||||
'uuid' => $this->test_city->uuid,
|
'uuid' => $this->testCity->uuid,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertDatabaseHas('carts', [
|
$this->assertDatabaseHas('carts', [
|
||||||
'city_id' => $this->test_city->id,
|
'city_id' => $this->testCity->id,
|
||||||
'user_id' => $this->test_user->id,
|
'user_id' => $this->testUser->id,
|
||||||
'status' => 'CART',
|
'status' => 'CART',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_select_company_first_time(): void
|
public function test_select_company_first_time(): void
|
||||||
{
|
{
|
||||||
$this->test_user = User::where('username', $this->test_user_username)->first();
|
$this->testUser = User::where('username', $this->testUserUsername)->first();
|
||||||
$this->test_company = Company::where('name', $this->test_company_name)->first();
|
$this->testCompany = Company::where('name', $this->testCompanyName)->first();
|
||||||
|
|
||||||
$this->assertNotNull($this->test_user);
|
$this->assertNotNull($this->testUser);
|
||||||
$this->assertNotNull($this->test_company);
|
$this->assertNotNull($this->testCompany);
|
||||||
|
|
||||||
$response = $this->post('/api/v2/select-company', [
|
$response = $this->post('/api/v2/select-company', [
|
||||||
'matrix_username' => $this->test_user->matrix_username,
|
'matrixUsername' => $this->testUser->matrix_username,
|
||||||
'company_name' => $this->test_company->name,
|
'companyName' => $this->testCompany->name,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
|
||||||
$response->assertJson([
|
$response->assertJson([
|
||||||
'ok' => 'Company selected successfully',
|
'ok' => 'Company selected successfully',
|
||||||
'name' => $this->test_company->name,
|
'name' => $this->testCompany->name,
|
||||||
'uuid' => $this->test_company->uuid,
|
'uuid' => $this->testCompany->uuid,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertDatabaseHas('carts', [
|
$this->assertDatabaseHas('carts', [
|
||||||
'company_id' => $this->test_company->id,
|
'company_id' => $this->testCompany->id,
|
||||||
'user_id' => $this->test_user->id,
|
'user_id' => $this->testUser->id,
|
||||||
'status' => 'CART',
|
'status' => 'CART',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_select_another_company(): void
|
public function test_select_another_company(): void
|
||||||
{
|
{
|
||||||
$this->test_user = User::where('username', $this->test_user_username)->first();
|
$this->testUser = User::where('username', $this->testUserUsername)->first();
|
||||||
$this->test_company = Company::where('name', $this->test_company_name2)->first();
|
$this->testCompany = Company::where('name', $this->testCompanyName2)->first();
|
||||||
|
|
||||||
$this->assertNotNull($this->test_user);
|
$this->assertNotNull($this->testUser);
|
||||||
$this->assertNotNull($this->test_company);
|
$this->assertNotNull($this->testCompany);
|
||||||
|
|
||||||
$response = $this->post('/api/v2/select-company', [
|
$response = $this->post('/api/v2/select-company', [
|
||||||
'matrix_username' => $this->test_user->matrix_username,
|
'matrixUsername' => $this->testUser->matrix_username,
|
||||||
'company_name' => $this->test_company->name,
|
'companyName' => $this->testCompany->name,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
|
||||||
$response->assertJson([
|
$response->assertJson([
|
||||||
'ok' => 'Company changed successfully',
|
'ok' => 'Company changed successfully',
|
||||||
'name' => $this->test_company->name,
|
'name' => $this->testCompany->name,
|
||||||
'uuid' => $this->test_company->uuid,
|
'uuid' => $this->testCompany->uuid,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertDatabaseHas('carts', [
|
$this->assertDatabaseHas('carts', [
|
||||||
'company_id' => $this->test_company->id,
|
'company_id' => $this->testCompany->id,
|
||||||
'user_id' => $this->test_user->id,
|
'user_id' => $this->testUser->id,
|
||||||
'status' => 'CART',
|
'status' => 'CART',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -153,16 +153,16 @@ class CartTest extends TestCase
|
|||||||
|
|
||||||
public function testAddFirstCartItem(): int
|
public function testAddFirstCartItem(): int
|
||||||
{
|
{
|
||||||
$this->test_user = User::where('username', $this->test_user_username)->first();
|
$this->testUser = User::where('username', $this->testUserUsername)->first();
|
||||||
$this->test_item = Item::where('name', $this->test_item_name)->first();
|
$this->testItem = Item::where('name', $this->testItemName)->first();
|
||||||
$count = 2;
|
$count = 2;
|
||||||
|
|
||||||
$this->assertNotNull($this->test_user);
|
$this->assertNotNull($this->testUser);
|
||||||
$this->assertNotNull($this->test_item);
|
$this->assertNotNull($this->testItem);
|
||||||
|
|
||||||
$response = $this->post('/api/v2/add-item', [
|
$response = $this->post('/api/v2/add-item', [
|
||||||
'matrixUsername' => $this->test_user->matrix_username,
|
'matrixUsername' => $this->testUser->matrix_username,
|
||||||
'itemName' => $this->test_item->name,
|
'itemName' => $this->testItem->name,
|
||||||
'itemCount' => $count,
|
'itemCount' => $count,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -170,8 +170,8 @@ class CartTest extends TestCase
|
|||||||
|
|
||||||
$response->assertJson([
|
$response->assertJson([
|
||||||
'ok' => 'The item added successfully',
|
'ok' => 'The item added successfully',
|
||||||
'name' => $this->test_item->name,
|
'name' => $this->testItem->name,
|
||||||
'uuid' => $this->test_item->uuid,
|
'uuid' => $this->testItem->uuid,
|
||||||
'count' => $count,
|
'count' => $count,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -183,13 +183,13 @@ class CartTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testExistingNewCartItem($count): int
|
public function testExistingNewCartItem($count): int
|
||||||
{
|
{
|
||||||
$this->test_item = Item::where('name', $this->test_item_name)->first();
|
$this->testItem = Item::where('name', $this->testItemName)->first();
|
||||||
|
|
||||||
$this->assertNotNull($this->test_item);
|
$this->assertNotNull($this->testItem);
|
||||||
|
|
||||||
$this->assertDatabaseHas('items', [
|
$this->assertDatabaseHas('items', [
|
||||||
'uuid' => $this->test_item->uuid,
|
'uuid' => $this->testItem->uuid,
|
||||||
'name' => $this->test_item->name,
|
'name' => $this->testItem->name,
|
||||||
'count' => $count,
|
'count' => $count,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -201,11 +201,11 @@ class CartTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testExistingCartItemRelationship($count): int
|
public function testExistingCartItemRelationship($count): int
|
||||||
{
|
{
|
||||||
$this->test_item = Item::where('name', $this->test_item_name)->first();
|
$this->testItem = Item::where('name', $this->testItemName)->first();
|
||||||
|
|
||||||
$this->assertNotNull($this->test_item);
|
$this->assertNotNull($this->testItem);
|
||||||
|
|
||||||
$cart_item = Item::where('uuid', $this->test_item->uuid)
|
$cart_item = Item::where('uuid', $this->testItem->uuid)
|
||||||
->where('count', $count)
|
->where('count', $count)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
@@ -221,15 +221,15 @@ class CartTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testAddItemAgain($count): int
|
public function testAddItemAgain($count): int
|
||||||
{
|
{
|
||||||
$this->test_user = User::where('username', $this->test_user_username)->first();
|
$this->testUser = User::where('username', $this->testUserUsername)->first();
|
||||||
$this->test_item = Item::where('name', $this->test_item_name)->first();
|
$this->testItem = Item::where('name', $this->testItemName)->first();
|
||||||
|
|
||||||
$this->assertNotNull($this->test_user);
|
$this->assertNotNull($this->testUser);
|
||||||
$this->assertNotNull($this->test_item);
|
$this->assertNotNull($this->testItem);
|
||||||
|
|
||||||
$response = $this->post('/api/v2/add-item', [
|
$response = $this->post('/api/v2/add-item', [
|
||||||
'matrixUsername' => $this->test_user->matrix_username,
|
'matrixUsername' => $this->testUser->matrix_username,
|
||||||
'itemName' => $this->test_item->name,
|
'itemName' => $this->testItem->name,
|
||||||
// the count as before
|
// the count as before
|
||||||
'itemCount' => $count,
|
'itemCount' => $count,
|
||||||
]);
|
]);
|
||||||
@@ -238,8 +238,8 @@ class CartTest extends TestCase
|
|||||||
|
|
||||||
$response->assertJson([
|
$response->assertJson([
|
||||||
'ok' => 'The item count is changed successfully',
|
'ok' => 'The item count is changed successfully',
|
||||||
'name' => $this->test_item->name,
|
'name' => $this->testItem->name,
|
||||||
'uuid' => $this->test_item->uuid,
|
'uuid' => $this->testItem->uuid,
|
||||||
// the count as before, therefore it must be doubled.
|
// the count as before, therefore it must be doubled.
|
||||||
'count' => $count * 2,
|
'count' => $count * 2,
|
||||||
]);
|
]);
|
||||||
@@ -252,30 +252,31 @@ class CartTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDoubledItemCount($count): void
|
public function testDoubledItemCount($count): void
|
||||||
{
|
{
|
||||||
$this->test_user = User::where('username', $this->test_user_username)->first();
|
$this->testUser = User::where('username', $this->testUserUsername)->first();
|
||||||
$this->test_item = Item::where('name', $this->test_item_name)->first();
|
$this->testItem = Item::where('name', $this->testItemName)->first();
|
||||||
|
|
||||||
$this->assertNotNull($this->test_user);
|
$this->assertNotNull($this->testUser);
|
||||||
$this->assertNotNull($this->test_item);
|
$this->assertNotNull($this->testItem);
|
||||||
|
|
||||||
$this->assertDatabaseHas('items', [
|
$this->assertDatabaseHas('items', [
|
||||||
'uuid' => $this->test_item->uuid,
|
'uuid' => $this->testItem->uuid,
|
||||||
'name' => $this->test_item->name,
|
'name' => $this->testItem->name,
|
||||||
'count' => $count * 2,
|
'count' => $count * 2,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO item from another company -> error
|
||||||
public function test_removing_cart(): void
|
public function test_removing_cart(): void
|
||||||
{
|
{
|
||||||
$this->test_user = User::where('username', $this->test_user_username)->first();
|
$this->testUser = User::where('username', $this->testUserUsername)->first();
|
||||||
$this->test_city = City::where('name', $this->test_city_name2)->first();
|
$this->testCity = City::where('name', $this->testCityName2)->first();
|
||||||
|
|
||||||
$this->assertNotNull($this->test_user);
|
$this->assertNotNull($this->testUser);
|
||||||
$this->assertNotNull($this->test_city);
|
$this->assertNotNull($this->testCity);
|
||||||
|
|
||||||
$cart = Cart::where('status', 'CART')
|
$cart = Cart::where('status', 'CART')
|
||||||
->where('user_id', $this->test_user->id)
|
->where('user_id', $this->testUser->id)
|
||||||
->where('city_id', $this->test_city->id)
|
->where('city_id', $this->testCity->id)
|
||||||
->first();
|
->first();
|
||||||
$cart->delete();
|
$cart->delete();
|
||||||
|
|
||||||
@@ -283,20 +284,20 @@ class CartTest extends TestCase
|
|||||||
|
|
||||||
$this->assertDatabaseMissing('carts', [
|
$this->assertDatabaseMissing('carts', [
|
||||||
'status' => 'CART',
|
'status' => 'CART',
|
||||||
'user_id' => $this->test_user->id,
|
'user_id' => $this->testUser->id,
|
||||||
'city_id'=> $this->test_city->id
|
'city_id'=> $this->testCity->id
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_select_city_with_no_city(): void
|
public function test_select_city_with_no_city(): void
|
||||||
{
|
{
|
||||||
$this->test_city = City::where('name', $this->test_city_name2)->first();
|
$this->testCity = City::where('name', $this->testCityName2)->first();
|
||||||
|
|
||||||
$this->assertNotNull($this->test_city);
|
$this->assertNotNull($this->testCity);
|
||||||
|
|
||||||
$response = $this->post('/api/v2/select-city', [
|
$response = $this->post('/api/v2/select-city', [
|
||||||
'matrix_username' => '',
|
'matrixUsername' => '',
|
||||||
'city_name' => $this->test_city->name,
|
'cityName' => $this->testCity->name,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@@ -308,13 +309,13 @@ class CartTest extends TestCase
|
|||||||
|
|
||||||
public function test_select_city_with_no_user(): void
|
public function test_select_city_with_no_user(): void
|
||||||
{
|
{
|
||||||
$this->test_city = City::where('name', $this->test_city_name2)->first();
|
$this->testCity = City::where('name', $this->testCityName2)->first();
|
||||||
|
|
||||||
$this->assertNotNull($this->test_city);
|
$this->assertNotNull($this->testCity);
|
||||||
|
|
||||||
$response = $this->post('/api/v2/select-city', [
|
$response = $this->post('/api/v2/select-city', [
|
||||||
'matrix_username' => '',
|
'matrixUsername' => '',
|
||||||
'city_name' => $this->test_city->name,
|
'cityName' => $this->testCity->name,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
|||||||
Reference in New Issue
Block a user