Skip to content

Commit

Permalink
fix merge artifacts and tests
Browse files Browse the repository at this point in the history
Signed-off-by: Vinzenz Rosenkranz <[email protected]>
  • Loading branch information
v1r0x committed Nov 25, 2024
1 parent 2b07b8b commit 76289e5
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 116 deletions.
18 changes: 8 additions & 10 deletions app/Http/Controllers/EntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ private function verifyImportData(Request $request) {
'metadata' => 'required|json',
'data' => 'required|json',
]);

$file = $request->file('file');

if(!$file || !$file->isValid()) {
Expand Down Expand Up @@ -758,16 +758,16 @@ public function patchAttributes($id, Request $request) {
foreach($request->request as $patch) {
$op = $patch['op'];
$aid = $patch['params']['aid'];
$error = null;
switch($op) {
case 'remove':
$attrval = AttributeValue::where([
['entity_id', '=', $id],
['attribute_id', '=', $aid],
])->first();
if(!isset($attrval)) {
return response()->json([
'error' => __('This attribute value does either not exist or is in moderation state.'),
], 400);
$error = __('This attribute value does either not exist or is in moderation state.');
break;
}
if($user->isModerated()) {
$attrval->moderate('pending-delete', true);
Expand All @@ -782,9 +782,8 @@ public function patchAttributes($id, Request $request) {
->withModerated()
->exists();
if($alreadyAdded) {
return response()->json([
'error' => __('There is already a value set for this attribute or it is in moderation state.'),
], 400);
$error = __('There is already a value set for this attribute or it is in moderation state.');
break;
}
$value = $patch['value'];
$attrval = new AttributeValue();
Expand All @@ -801,9 +800,8 @@ public function patchAttributes($id, Request $request) {
->onlyModerated()
->exists();
if($alreadyModerated) {
return response()->json([
'error' => __('This attribute value is in moderation state. A user with appropriate permissions has to accept or deny it first.'),
], 400);
$error = __('This attribute value is in moderation state. A user with appropriate permissions has to accept or deny it first.');
break;
}
$value = $patch['value'];
$attrval = AttributeValue::where([
Expand Down
24 changes: 0 additions & 24 deletions database/seeders/Demo/UsersTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,6 @@ public function run()
'updated_at' => '2017-12-20 09:47:36',
'deleted_at' => NULL,
),
array (
'id' => 2,
'name' => 'First User',
'nickname' => 'first_user',
'email' => 'first@localhost',
'metadata' => NULL,
'password' => '$2y$10$GTwOUwcsqgqL/J/0dxxkIenBLR3Pna9ZfIa7sVyPkJgQDwqLU0wqa',
'remember_token' => NULL,
'created_at' => '2017-12-31 09:47:36',
'updated_at' => '2017-12-31 09:47:36',
'deleted_at' => NULL,
),
array (
'id' => 3,
'name' => 'Deleted User',
'nickname' => 'deleted_user',
'email' => 'deleted@localhost',
'metadata' => NULL,
'password' => '$2y$10$GTwOUwcsqgqL/J/0dxxkIenBLR3Pna9ZfIa7sVyPkJgQDwqLU0wqa',
'remember_token' => NULL,
'created_at' => '2017-12-31 09:47:36',
'updated_at' => '2017-12-31 09:47:36',
'deleted_at' => '2018-01-10 09:47:36',
),
));
}
}
1 change: 1 addition & 0 deletions database/seeders/DemoSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Database\Seeders\Demo\EntityTypesTableSeeder;
use Database\Seeders\Demo\ReferencesTableSeeder;
use Database\Seeders\Demo\RoleUserTableSeeder;
use Database\Seeders\Demo\ThesaurexSeeder;
use Database\Seeders\Demo\UsersTableSeeder;
use Database\Seeders\General\RolesPermissionsSeeder;
use Database\Seeders\General\RolesTableSeeder;
Expand Down
45 changes: 0 additions & 45 deletions database/seeders/DemoUserSeeder.php

This file was deleted.

2 changes: 1 addition & 1 deletion database/seeders/Testing/UserSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function run()
'remember_token' => NULL,
'created_at' => '2019-01-06 12:00:00',
'updated_at' => '2019-01-06 12:00:00',
'deleted_at' => NULL,
'deleted_at' => '2020-01-06 12:00:00',
]
]);
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Feature/ApiEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,17 @@ public function testPatchAttributesEndpoint()
->has('updated_at')
->etc()
)
->has('removed_attributes.9', fn($removedAttrJson) =>
$removedAttrJson
->has('id')
->has('entity_id')
->has('attribute_id')
->has('certainty')
->has('user_id')
->has('created_at')
->has('updated_at')
->etc()
)
);

$entity = Entity::with('attributes')->find(4);
Expand Down
44 changes: 25 additions & 19 deletions tests/Feature/ApiSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,27 +198,33 @@ public function testEntitySearchEndpoint()
$response = $this->userRequest()
->get('/api/v1/search/entity?q=Inv.');

$content = json_decode($response->getContent());
$response->assertStatus(200);
$response->assertJsonCount(3);
$response->assertJsonStructure([
[
'id',
'name',
'entity_type_id',
'root_entity_id',
'rank',
'user_id',
'created_at',
'updated_at',
'ancestors'
]
]);
$response->assertJsonCount(9);
// response content is Laravel Paginate Array
$this->assertObjectHasProperty('data', $content);
$this->assertObjectHasProperty('from', $content);
$this->assertObjectHasProperty('to', $content);
$this->assertObjectHasProperty('per_page', $content);
$this->assertObjectHasProperty('current_page', $content);
$this->assertObjectHasProperty('first_page_url', $content);
$this->assertObjectHasProperty('next_page_url', $content);
$this->assertObjectHasProperty('prev_page_url', $content);
$this->assertObjectHasProperty('path', $content);

$response->assertJson([
['name' => 'Inv. 1234'],
['name' => 'Inv. 124'],
['name' => 'Inv. 31']
]);
$this->assertObjectHasProperty('id', $content->data[0]);
$this->assertObjectHasProperty('name', $content->data[0]);
$this->assertObjectHasProperty('entity_type_id', $content->data[0]);
$this->assertObjectHasProperty('root_entity_id', $content->data[0]);
$this->assertObjectHasProperty('rank', $content->data[0]);
$this->assertObjectHasProperty('user_id', $content->data[0]);
$this->assertObjectHasProperty('created_at', $content->data[0]);
$this->assertObjectHasProperty('updated_at', $content->data[0]);
$this->assertObjectHasProperty('ancestors', $content->data[0]);

$this->assertEquals('Inv. 1234', $content->data[0]->name);
$this->assertEquals('Inv. 124', $content->data[1]->name);
$this->assertEquals('Inv. 31', $content->data[2]->name);
}

/**
Expand Down
28 changes: 15 additions & 13 deletions tests/Feature/ApiUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,18 @@ public function testGetUsersEndpoint()
'name' => 'Admin',
],[
'id' => 2,
'name' => "John Doe",
],[
'id' => 3,
'name' => "Gary Guest",
'name' => "John Doe",
],[
'id' => $user->id,
'name' => $user->name,
]
],
],
'deleted_users' => []
'deleted_users' => [
[
'id' => 3,
'name' => "Gary Guest",
],
]
]);
}

Expand Down Expand Up @@ -559,16 +561,16 @@ public function testRestoreUserEndpoint()
$cnt = User::count();
$this->assertEquals(3, $cnt);
$cnt = User::onlyTrashed()->count();
$this->assertEquals(1, $cnt);
$cnt = User::withoutTrashed()->count();
$this->assertEquals(2, $cnt);
$cnt = User::withoutTrashed()->count();
$this->assertEquals(1, $cnt);
$user = User::find(1);
$this->assertNotNull($user->deleted_at);

$response = $this->userRequest()
->patch('/api/v1/user/restore/1');

$user = User::find(3);
$user = User::find(2);
$this->assertNull($user->deleted_at);

$response->assertStatus(204);
Expand All @@ -584,9 +586,9 @@ public function testDeleteUserEndpoint()
$cnt = User::count();
$this->assertEquals(3, $cnt);
$cnt = User::onlyTrashed()->count();
$this->assertEquals(0, $cnt);
$this->assertEquals(1, $cnt);
$cnt = User::withoutTrashed()->count();
$this->assertEquals(3, $cnt);
$this->assertEquals(2, $cnt);
$response = $this->userRequest()
->delete('/api/v1/user/1');

Expand All @@ -595,9 +597,9 @@ public function testDeleteUserEndpoint()
$cnt = User::count();
$this->assertEquals(3, $cnt);
$cnt = User::onlyTrashed()->count();
$this->assertEquals(1, $cnt);
$cnt = User::withoutTrashed()->count();
$this->assertEquals(2, $cnt);
$cnt = User::withoutTrashed()->count();
$this->assertEquals(1, $cnt);
$user = User::find(1);
$this->assertNotNull($user->deleted_at);

Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/Attributes/UserlistAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public static function truthyProvider() {
return [
"empty string" => ["", null],
"single user" => ["admin", "[1]"],
"multiple users" => ["admin;first_user", "[1,2]"],
"multiple users with spaces" => [" admin ; first_user ", "[1,2]"],
"single deleted user" => ["deleted_user", "[3]"],
"multiple users with single deleted user" => ["admin;deleted_user", "[1,3]"],
"multiple users" => ["admin;johndoe", "[1,2]"],
"multiple users with spaces" => [" admin ; johndoe ", "[1,2]"],
"single deleted user" => ["garyguest", "[3]"],
"multiple users with single deleted user" => ["admin;garyguest", "[1,3]"],
];
}

Expand Down

0 comments on commit 76289e5

Please sign in to comment.