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

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

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

@ -14,10 +14,10 @@ use App\Models\User;
class UserTest extends TestCase
{
protected $username = 'Oleg';
protected $matrix_username = '@oleg:oleg.com';
protected $matrixUsername = '@oleg:oleg.com';
protected $phone = '380671231212';
protected $not_existing_user = [
protected $notExistingUser = [
'username' => 'Kostia',
'matrix_username' => '@kostia:kostia.com',
];
@ -26,7 +26,7 @@ class UserTest extends TestCase
{
$response = $this->post('/api/v2/register', [
'username' => $this->username,
'matrix_username' => $this->matrix_username,
'matrix_username' => $this->matrixUsername,
'phone' => $this->phone,
]);
@ -45,7 +45,7 @@ class UserTest extends TestCase
{
$response = $this->post('/api/v2/register', [
'username' => $this->username,
'matrix_username' => $this->matrix_username,
'matrix_username' => $this->matrixUsername,
'phone' => $this->phone,
]);
@ -58,7 +58,7 @@ class UserTest extends TestCase
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);
@ -71,7 +71,7 @@ class UserTest extends TestCase
{
$response = $this->post('/api/v2/login', [
'username' => $this->username,
'matrix_username' => $this->matrix_username,
'matrix_username' => $this->matrixUsername,
]);
$response->assertStatus(200);
@ -102,18 +102,18 @@ class UserTest extends TestCase
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!!!');
}
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.');
}

Loading…
Cancel
Save