Refactor names for the Company, Category, User APIs and tests.
continuous-integration/drone/push Build is passing Details

main
KKlochko 2 years ago
parent 4d8506a3a4
commit d584379888

@ -26,19 +26,19 @@ class CategoryController extends Controller
*/ */
public function index(Request $request) public function index(Request $request)
{ {
$matrix_username = $request->input('matrix_username') ?? ''; $matrixUsername = $request->input('matrixUsername') ?? '';
$company_uuid = $request->input('uuid') ?? ''; $companyUUID = $request->input('uuid') ?? '';
$user = null; $user = null;
$cart = null; $cart = null;
$company = null; $company = null;
if($company_uuid != ''){ if($companyUUID != ''){
$company = Company::where('uuid', $company_uuid)->first(); $company = Company::where('uuid', $companyUUID)->first();
} }
if($matrix_username) { if($matrixUsername) {
$user = User::firstOrCreate([ $user = User::firstOrCreate([
'matrix_username' => $matrix_username 'matrix_username' => $matrixUsername
]); ]);
$cart = Cart::firstOrCreate([ $cart = Cart::firstOrCreate([
@ -47,7 +47,7 @@ class CategoryController extends Controller
]); ]);
$company = $cart->getCompany(); $company = $cart->getCompany();
$company_uuid = $company->uuid; $companyUUID = $company->uuid;
} }
if(!$company) if(!$company)
@ -59,7 +59,7 @@ class CategoryController extends Controller
$fetcher = new ApiFetcher(); $fetcher = new ApiFetcher();
$categoryItemAPI = new CategoryItemAPI($fetcher); $categoryItemAPI = new CategoryItemAPI($fetcher);
$categoriesItemsMap = $categoryItemAPI->getMap($company_uuid); $categoriesItemsMap = $categoryItemAPI->getMap($companyUUID);
$categoryItemAPI->saveMap($categoriesItemsMap, $company); $categoryItemAPI->saveMap($categoriesItemsMap, $company);
// Companies Categories // Companies Categories

@ -26,35 +26,36 @@ class CompanyController extends Controller
*/ */
public function index(Request $request) public function index(Request $request)
{ {
$matrix_username = $request->input('matrix_username') ?? ''; $matrixUsername = $request->input('matrixUsername') ?? '';
$city_uuid = $request->input('uuid') ?? ''; $cityUUID = $request->input('uuid') ?? '';
$user = null; $user = null;
$cart = null; $cart = null;
$city = null; $city = null;
if($city_uuid != ''){ if($cityUUID != ''){
$city = City::where('uuid', $city_uuid)->first(); $city = City::where('uuid', $cityUUID)->first();
} }
if($matrix_username) { if($matrixUsername) {
$user = User::firstOrCreate([ $user = User::firstOrCreate([
'matrix_username' => $matrix_username 'matrix_username' => $matrixUsername
]); ]);
// TODO valid city exists
$cart = Cart::firstOrCreate([ $cart = Cart::firstOrCreate([
'user_id' => $user->id, 'user_id' => $user->id,
'status' => 'CART' 'status' => 'CART'
]); ]);
$city = $cart->getCity(); $city = $cart->getCity();
$city_uuid = $city->uuid; $cityUUID = $city->uuid;
} }
// Update list of companies // Update list of companies
$fetcher = new ApiFetcher(); $fetcher = new ApiFetcher();
$companyAPI = new CompanyAPI($fetcher); $companyAPI = new CompanyAPI($fetcher);
$companyMap = $companyAPI->getMap($city_uuid); $companyMap = $companyAPI->getMap($cityUUID);
$companyAPI->saveMap($companyMap, $city); $companyAPI->saveMap($companyMap, $city);
$companies = $city->getCompanies(); $companies = $city->getCompanies();

@ -12,7 +12,7 @@ class UserController extends Controller
public function register(Request $request) public function register(Request $request)
{ {
$username = $request->input('username') ?? ''; $username = $request->input('username') ?? '';
$matrix_username = $request->input('matrix_username') ?? ''; $matrixUsername = $request->input('matrixUsername') ?? '';
$phone = $request->input('phone') ?? ''; $phone = $request->input('phone') ?? '';
if($username == '') { if($username == '') {
@ -26,7 +26,7 @@ class UserController extends Controller
// if username is free then the new user will be created // if username is free then the new user will be created
// with addition arguments: // with addition arguments:
[ [
'matrix_username' => $matrix_username, 'matrix_username' => $matrixUsername,
'phone' => $phone 'phone' => $phone
] ]
); );
@ -45,7 +45,7 @@ class UserController extends Controller
public function login(Request $request) public function login(Request $request)
{ {
$username = $request->input('username') ?? ''; $username = $request->input('username') ?? '';
$matrix_username = $request->input('matrix_username') ?? ''; $matrixUsername = $request->input('matrixUsername') ?? '';
if($username == '') { if($username == '') {
return response()->json([ return response()->json([
@ -63,8 +63,8 @@ class UserController extends Controller
// Update matrix user if needed // Update matrix user if needed
// TODO add verification check // TODO add verification check
if($user->matrix_username != $matrix_username) { if($user->matrix_username != $matrixUsername) {
$user->matrix_username = $matrix_username; $user->matrix_username = $matrixUsername;
$user->save(); $user->save();
} }

@ -14,10 +14,10 @@ use App\Models\User;
class UserTest extends TestCase class UserTest extends TestCase
{ {
protected $username = 'Oleg'; protected $username = 'Oleg';
protected $matrix_username = '@oleg:oleg.com'; protected $matrixUsername = '@oleg:oleg.com';
protected $phone = '380671231212'; protected $phone = '380671231212';
protected $not_existing_user = [ protected $notExistingUser = [
'username' => 'Kostia', 'username' => 'Kostia',
'matrix_username' => '@kostia:kostia.com', 'matrix_username' => '@kostia:kostia.com',
]; ];
@ -26,7 +26,7 @@ class UserTest extends TestCase
{ {
$response = $this->post('/api/v2/register', [ $response = $this->post('/api/v2/register', [
'username' => $this->username, 'username' => $this->username,
'matrix_username' => $this->matrix_username, 'matrix_username' => $this->matrixUsername,
'phone' => $this->phone, 'phone' => $this->phone,
]); ]);
@ -45,7 +45,7 @@ class UserTest extends TestCase
{ {
$response = $this->post('/api/v2/register', [ $response = $this->post('/api/v2/register', [
'username' => $this->username, 'username' => $this->username,
'matrix_username' => $this->matrix_username, 'matrix_username' => $this->matrixUsername,
'phone' => $this->phone, 'phone' => $this->phone,
]); ]);
@ -58,7 +58,7 @@ class UserTest extends TestCase
public function test_login_not_existing_user(): void public function test_login_not_existing_user(): void
{ {
$response = $this->post('/api/v2/login', $this->not_existing_user); $response = $this->post('/api/v2/login', $this->notExistingUser);
$response->assertStatus(200); $response->assertStatus(200);
@ -71,7 +71,7 @@ class UserTest extends TestCase
{ {
$response = $this->post('/api/v2/login', [ $response = $this->post('/api/v2/login', [
'username' => $this->username, 'username' => $this->username,
'matrix_username' => $this->matrix_username, 'matrix_username' => $this->matrixUsername,
]); ]);
$response->assertStatus(200); $response->assertStatus(200);
@ -102,18 +102,18 @@ class UserTest extends TestCase
public function test_not_existing_user_with_matrix_username(): void public function test_not_existing_user_with_matrix_username(): void
{ {
$matrix_username = '@kostia:test.com'; $matrixUsername = '@kostia:test.com';
$json = User::validate_with_matrix_username($matrix_username); $json = User::validate_with_matrix_username($matrixUsername);
$this->assertEquals($json['error'], 'A user with the username does not exist!!!'); $this->assertEquals($json['error'], 'A user with the username does not exist!!!');
} }
public function test_valid_user_with_matrix_username(): void public function test_valid_user_with_matrix_username(): void
{ {
$matrix_username = '@test:test.com'; $matrixUsername = '@test:test.com';
$json = User::validate_with_matrix_username($matrix_username); $json = User::validate_with_matrix_username($matrixUsername);
$this->assertEquals($json['ok'], 'A user with the username is valid.'); $this->assertEquals($json['ok'], 'A user with the username is valid.');
} }

Loading…
Cancel
Save