Skip to content

Commit

Permalink
fixing unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
miftahurrahmi committed Jul 9, 2024
1 parent 912d4be commit 9db8ba4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 46 deletions.
2 changes: 2 additions & 0 deletions src/Controllers/BadasoCRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ function ($attribute, $value, $fail) {
'required',
function ($attribute, $value, $fail) use ($request) {
if (! Schema::hasColumn($request->name, $value)) {

$split_attribute = explode('.', $attribute);
$split_attribute[2] = 'relation_type';
$field_to_relation = join('.', $split_attribute);
Expand Down Expand Up @@ -432,6 +433,7 @@ function ($attribute, $value, $fail) use ($request) {

return ApiResponse::success($new_data_type);
} catch (Exception $e) {
// dd($e);
DB::rollBack();

return ApiResponse::failed($e);
Expand Down
5 changes: 1 addition & 4 deletions src/Database/Schema/SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ public static function listTableDetails($table_name)
$columns = $sm->listTableColumns($table_name);

$foreign_keys = [];
if (static::registerConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) {
$foreign_keys = $sm->listTableForeignKeys($table_name);
}
$foreign_keys = $sm->listTableForeignKeys($table_name);

$indexes = $sm->listTableIndexes($table_name);

Expand Down Expand Up @@ -129,7 +127,6 @@ public static function describeTable($table_name)
$indexType = array_values($column_array['indexes'])[0]['type'];
$column_array['key'] = substr($indexType, 0, 3);
}

return $column_array;
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/resources/js/layout/admin/footer/Footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="badaso-footer__container">
<div class="badaso-footer__version">Version {{ version }}</div>
<div>
Copyright © 2020
Copyright © 2024
<a href="https://soft.uatech.co.id" target="_blank">UASOFT</a>. All rights
reserved.
</div>
Expand Down
60 changes: 19 additions & 41 deletions tests/Feature/BadasoApiCrudManagementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ private function createTestTables(int $max_count_table_generate)
$table_names = [];
for ($index = 1; $index <= $max_count_table_generate; $index++) {
$table_name = "{$this->TABLE_TEST_PREFIX}{$index}";
if (! Schema::hasTable($table_name)) {
if (!Schema::hasTable($table_name)) {
Schema::create($table_name, function (Blueprint $table) use ($index, $table_names) {
$table->id();

Expand Down Expand Up @@ -441,7 +441,7 @@ private function createTestEmptyValueTables(int $max_count_table_generate)
$table_names = [];
for ($index = 1; $index <= $max_count_table_generate; $index++) {
$table_name = "{$this->TABLE_TEST_EMPTY_VALUE_PREFIX}{$index}";
if (! Schema::hasTable($table_name)) {
if (!Schema::hasTable($table_name)) {
Schema::create($table_name, function (Blueprint $table) use ($index, $table_names) {
$table->id();

Expand Down Expand Up @@ -478,6 +478,10 @@ private function deleteAllTestTables()
foreach ($table_empty_names as $key => $table_empty_names) {
Schema::dropIfExists($table_empty_names);
}
$multiple_tables = ['multiple_table_1', 'multiple_table_2'];
foreach ($multiple_tables as $key => $multiple_table) {
Schema::dropIfExists($multiple_table);
}

// clear cache
CallHelperTest::clearCache();
Expand Down Expand Up @@ -589,6 +593,7 @@ public function testAddCrudManagement()
],
];
foreach ($const_fields as $key => ['badaso_type' => $badaso_type, 'schema_type' => $schema_type, 'details' => $details]) {

if ($index_table_name == 0 && $badaso_type == 'relation') {
continue;
}
Expand Down Expand Up @@ -641,7 +646,7 @@ class {$model_name} extends Model {
}
PHP;
$model_path = app_path("Models/$model_file_name");
if (! file_exists($model_path)) {
if (!file_exists($model_path)) {
file_put_contents($model_path, $model_body);
}

Expand All @@ -662,7 +667,7 @@ class {$model_name} extends Model {
$controller_data = [];
if (rand(0, 1)) {
// create new controller
$controller_name = str_replace([' ', '_'], '', ucwords($table_name)).'Controller';
$controller_name = str_replace([' ', '_'], '', ucwords($table_name)) . 'Controller';
$controller_file_name = "{$controller_name}.php";
$controller_body = <<<PHP
<?php
Expand All @@ -671,7 +676,7 @@ class {$model_name} extends Model {
class {$controller_name} extends \Uasoft\Badaso\Controllers\BadasoBaseController {}
PHP;
$controller_path = app_path("/Http/Controllers/$controller_file_name");
if (! file_exists($controller_path)) {
if (!file_exists($controller_path)) {
file_put_contents($controller_path, $controller_body);
}

Expand Down Expand Up @@ -711,6 +716,7 @@ class {$controller_name} extends \Uasoft\Badaso\Controllers\BadasoBaseController
'rows' => $rows,
];
$response = CallHelperTest::withAuthorizeBearer($this)->json('POST', CallHelperTest::getUrlApiV1Prefix('/crud/add'), $request_body);

$response->assertSuccessful();

// save logs
Expand Down Expand Up @@ -1052,7 +1058,9 @@ public function testAddTableCrudMultiRelationEntity()
foreach ($add_crud_table as $key => $request_data_crud_table) {
$response = CallHelperTest::withAuthorizeBearer($this)->json('POST', CallHelperTest::getUrlApiV1Prefix('/crud/add'), $request_data_crud_table);
// $response->assertSuccessful();

}

}

public function testAddTableManyToMany()
Expand Down Expand Up @@ -1337,6 +1345,7 @@ public function testEntityManytoMany()
}
}

//
public function testAddEntityMultiRelation()
{
$first_table = 'multiple_table_1';
Expand Down Expand Up @@ -1365,6 +1374,7 @@ public function testAddEntityMultiRelation()
// add fill table 1
$response_crud_table = CallHelperTest::withAuthorizeBearer($this)->json('GET', CallHelperTest::getUrlApiV1Prefix('/crud?'));
$response_crud_table = $response_crud_table['data'];

foreach ($response_crud_table['tablesWithCrudData'] as $key => $value_response_crud_table) {
foreach ($list_table as $key_add_table => $value_add_table) {
if (in_array($value_add_table, $value_response_crud_table)) {
Expand All @@ -1390,41 +1400,6 @@ public function testAddEntityMultiRelation()
// add fill table 2
$response = CallHelperTest::withAuthorizeBearer($this)->json('POST', CallHelperTest::getUrlApiV1Prefix('/entities/multiple-table-2/add'), $add_fill_table_2);
$response->assertSuccessful();
$response_table_2 = $response['data'];
foreach ($response_table_2 as $key => $value) {
if ($key == 'idRelation1Field1') {
$this->assertTrue($value == $add_fill_table_2['data']['id_relation1_field1']);
}
if ($key == 'idRelation2Field1') {
$this->assertTrue($value == $add_fill_table_2['data']['id_relation2_field1']);
}
}
// delete crud management
foreach ($ids_list_table as $key => $value_ids_list_table) {
$response = CallHelperTest::withAuthorizeBearer($this)->json('DELETE', CallHelperTest::getUrlApiV1Prefix('/crud/delete'), $value_ids_list_table);
$response->assertSuccessful();
}

// delete table
foreach ($list_table as $key => $request_data_table) {
$response = CallHelperTest::withAuthorizeBearer($this)->json('DELETE', CallHelperTest::getUrlApiV1Prefix('/database/delete'), ['table' => $request_data_table]);
$response->assertSuccessful();
}

// Delete Migration
$response = CallHelperTest::withAuthorizeBearer($this)
->json('GET', CallHelperTest::getUrlApiV1Prefix('/database/migration/browse'));

$response = $response->json('data');
$migration_name = [];
for ($i = count($response) - 8; $i < count($response); $i++) {
$migration_name[] = $response[$i]['migration'];
}
$response = CallHelperTest::withAuthorizeBearer($this)
->json('POST', CallHelperTest::getUrlApiV1Prefix('/database/migration/delete'), [
'file_name' => $migration_name,
]);
$response->assertSuccessful();
}

public function testAddEditEntityCrudManagement()
Expand Down Expand Up @@ -1725,6 +1700,7 @@ class {$controller_name} extends \Uasoft\Badaso\Controllers\BadasoBaseController
'rows' => $rows,
];
$response = CallHelperTest::withAuthorizeBearer($this)->json('POST', CallHelperTest::getUrlApiV1Prefix('/crud/add'), $request_body);

$response->assertSuccessful();

// save logs
Expand Down Expand Up @@ -2256,7 +2232,9 @@ public function testDeleteCrudManagement()
{
$tables = CallHelperTest::getCache($this->KEY_LIST_CREATE_TABLES);
$empty_tables = CallHelperTest::getCache($this->KEY_LIST_CREATE_EMPTY_TABLES);
$collect_tables = [$tables, $empty_tables];
$multiple_tables = ['multiple_table_1', 'multiple_table_2'];

$collect_tables = [$tables, $empty_tables, $multiple_tables];
foreach ($collect_tables as $key => $item_tables) {
$data_types = DataType::whereIn('name', $item_tables)->get();
foreach ($data_types as $key => $data_type) {
Expand Down

0 comments on commit 9db8ba4

Please sign in to comment.