Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gammamatrix committed Feb 21, 2024
1 parent 6153f45 commit 8d9e1b1
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 280 deletions.
80 changes: 2 additions & 78 deletions src/Feature/Http/Controllers/Resource/Playground/LockJsonTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function test_json_guest_cannot_lock()
]);
}

public function test_json_lock_as_admin_user_and_succeed()
public function test_json_lock_as_admin_and_succeed()
{
$packageInfo = $this->getPackageInfo();

Expand Down Expand Up @@ -89,7 +89,7 @@ public function test_json_lock_as_admin_user_and_succeed()
$response->assertStatus(200);
}

public function test_json_lock_as_admin_user_and_succeed_with_no_redirect()
public function test_json_lock_as_admin_and_succeed_with_no_redirect()
{
$packageInfo = $this->getPackageInfo();

Expand Down Expand Up @@ -174,80 +174,4 @@ public function test_json_lock_as_user_and_get_denied()
'locked' => false,
]);
}

public function test_json_lock_as_admin_and_succeed()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;

$user = User::factory()->admin()->create();

$model = $fqdn::factory()->create([
'owned_by_id' => $user->id,
]);

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'locked' => false,
]);

$url = route(sprintf(
'%1$s.lock',
$packageInfo['model_route']
), [
$packageInfo['model_slug'] => $model->id,
]);

$response = $this->actingAs($user)->putJson($url);

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'locked' => true,
]);

$response->assertStatus(200);

$response->assertJsonStructure($this->getStructureData());
}

public function test_json_lock_as_admin_and_succeed_with_json()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;

$user = User::factory()->admin()->create();

$model = $fqdn::factory()->create([
'owned_by_id' => $user->id,
]);

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'locked' => false,
]);

$url = route(sprintf(
'%1$s.lock',
$packageInfo['model_route']
), [
$packageInfo['model_slug'] => $model->id,
]);

$response = $this->actingAs($user)->putJson($url);

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'locked' => true,
]);

$response->assertStatus(200);

$response->assertJsonStructure($this->getStructureData());
}
}
40 changes: 1 addition & 39 deletions src/Feature/Http/Controllers/Resource/Playground/LockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function test_guest_cannot_lock()
]);
}

public function test_lock_as_admin_user_and_succeed()
public function test_lock_as_admin_and_succeed()
{
$packageInfo = $this->getPackageInfo();

Expand Down Expand Up @@ -162,42 +162,4 @@ public function test_lock_as_user_and_get_denied()
'locked' => false,
]);
}

public function test_lock_as_admin_and_succeed()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;

$user = User::factory()->admin()->create();

$model = $fqdn::factory()->create([
'owned_by_id' => $user->id,
]);

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'locked' => false,
]);

$url = route(sprintf(
'%1$s.lock',
$packageInfo['model_route']
), [
$packageInfo['model_slug'] => $model->id,
]);

$response = $this->actingAs($user)->put($url);

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'locked' => true,
]);

$response->assertRedirect(route(sprintf('%1$s.show', $packageInfo['model_route']), [
$packageInfo['model_slug'] => $model->id,
]));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function test_json_guest_cannot_restore()
]);
}

public function test_json_restore_as_admin_user_and_succeed()
public function test_json_restore_as_admin_and_succeed()
{
$packageInfo = $this->getPackageInfo();

Expand Down Expand Up @@ -90,7 +90,7 @@ public function test_json_restore_as_admin_user_and_succeed()
$response->assertJsonStructure($this->getStructureData());
}

public function test_json_restore_as_admin_user_and_succeed_with_no_redirect()
public function test_json_restore_as_admin_and_succeed_with_no_redirect()
{
$packageInfo = $this->getPackageInfo();

Expand Down Expand Up @@ -172,43 +172,4 @@ public function test_json_restore_as_user_and_get_denied()
'deleted_at' => Carbon::now(),
]);
}

public function test_json_restore_as_admin_and_succeed()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;

$user = User::factory()->admin()->create();

$model = $fqdn::factory()->create([
'owned_by_id' => $user->id,
'deleted_at' => Carbon::now(),
]);

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'deleted_at' => Carbon::now(),
]);

$url = route(sprintf(
'%1$s.restore',
$packageInfo['model_route']
), [
$packageInfo['model_slug'] => $model->id,
]);

$response = $this->actingAs($user)->putJson($url);

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'deleted_at' => null,
]);

$response->assertStatus(200);

$response->assertJsonStructure($this->getStructureData());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function test_guest_cannot_restore()
]);
}

public function test_restore_as_admin_user_and_succeed()
public function test_restore_as_admin_and_succeed()
{
$packageInfo = $this->getPackageInfo();

Expand Down Expand Up @@ -175,43 +175,4 @@ public function test_restore_as_user_and_get_denied()
'deleted_at' => Carbon::now(),
]);
}

public function test_restore_as_admin_and_succeed()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;

$user = User::factory()->admin()->create();

$model = $fqdn::factory()->create([
'owned_by_id' => $user->id,
'deleted_at' => Carbon::now(),
]);

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'deleted_at' => Carbon::now(),
]);

$url = route(sprintf(
'%1$s.restore',
$packageInfo['model_route']
), [
$packageInfo['model_slug'] => $model->id,
]);

$response = $this->actingAs($user)->put($url);

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'deleted_at' => null,
]);

$response->assertRedirect(route(sprintf('%1$s.show', $packageInfo['model_route']), [
$packageInfo['model_slug'] => $model->id,
]));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function test_json_guest_cannot_unlock()
]);
}

public function test_json_unlock_as_admin_user_and_succeed()
public function test_json_unlock_as_admin_and_succeed()
{
$packageInfo = $this->getPackageInfo();

Expand Down Expand Up @@ -94,7 +94,7 @@ public function test_json_unlock_as_admin_user_and_succeed()
$response->assertJsonStructure($this->getStructureData());
}

public function test_json_unlock_as_admin_user_and_succeed_with_no_redirect()
public function test_json_unlock_as_admin_and_succeed_with_no_redirect()
{
$packageInfo = $this->getPackageInfo();

Expand Down Expand Up @@ -174,43 +174,4 @@ public function test_json_unlock_as_user_and_get_denied()
'locked' => true,
]);
}

public function test_json_unlock_as_admin_and_succeed()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;

$user = User::factory()->admin()->create();

$model = $fqdn::factory()->create([
'owned_by_id' => $user->id,
'locked' => true,
]);

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'locked' => true,
]);

$url = route(sprintf(
'%1$s.unlock',
$packageInfo['model_route']
), [
$packageInfo['model_slug'] => $model->id,
]);

$response = $this->actingAs($user)->deleteJson($url);

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'locked' => false,
]);

$response->assertStatus(200);

$response->assertJsonStructure($this->getStructureData());
}
}
43 changes: 2 additions & 41 deletions src/Feature/Http/Controllers/Resource/Playground/UnlockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function test_guest_cannot_unlock()
]);
}

public function test_unlock_as_admin_user_and_succeed()
public function test_unlock_as_admin_and_succeed()
{
$packageInfo = $this->getPackageInfo();

Expand Down Expand Up @@ -99,7 +99,7 @@ public function test_unlock_as_admin_user_and_succeed()
]));
}

public function test_unlock_as_admin_user_and_succeed_with_redirect_to_index_with_sorted_by_unlocked_desc()
public function test_unlock_as_admin_and_succeed_with_redirect_to_index_with_sorted_by_unlocked_desc()
{
$packageInfo = $this->getPackageInfo();

Expand Down Expand Up @@ -177,43 +177,4 @@ public function test_unlock_as_user_and_get_denied()
'locked' => true,
]);
}

public function test_unlock_as_admin_and_succeed()
{
$packageInfo = $this->getPackageInfo();

$fqdn = $this->fqdn;

$user = User::factory()->admin()->create();

$model = $fqdn::factory()->create([
'owned_by_id' => $user->id,
'locked' => true,
]);

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'locked' => true,
]);

$url = route(sprintf(
'%1$s.unlock',
$packageInfo['model_route']
), [
$packageInfo['model_slug'] => $model->id,
]);

$response = $this->actingAs($user)->delete($url);

$this->assertDatabaseHas($packageInfo['table'], [
'id' => $model->id,
'owned_by_id' => $user->id,
'locked' => false,
]);

$response->assertRedirect(route(sprintf('%1$s.show', $packageInfo['model_route']), [
$packageInfo['model_slug'] => $model->id,
]));
}
}

0 comments on commit 8d9e1b1

Please sign in to comment.