Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Commit

Permalink
Dont use route on test
Browse files Browse the repository at this point in the history
Signed-off-by: Lloric Mayuga Garcia <[email protected]>
  • Loading branch information
lloricode committed Oct 16, 2022
1 parent 0d1473b commit 9458940
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 65 deletions.
10 changes: 2 additions & 8 deletions tests/Auth/Authorization/BaseRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,13 @@ trait BaseRole
* @param string $assert
*/
protected function showModelWithRelation(
string $routeName,
Model $modelShow,
string $url,
Model $modelRelation,
string $relation,
string $assert = 'seeJson'
) {
$this->get(
route(
$routeName,
[
'id' => self::forId($modelShow),
]
)."?include=$relation",
$url."?include=$relation",
$this->addHeaders()
);
$this->assertResponseOk();
Expand Down
25 changes: 12 additions & 13 deletions tests/Auth/Authorization/ManageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
it('assign role to user', function () {
$user = UserFactory::new()->create();
$role = $this->createRole();

$this->showModelWithRelation('backend.users.show', $user, $role, 'roles', 'dontSeeJson');
$this->showModelWithRelation('auth/users/'. self::forId($user), $role, 'roles', 'dontSeeJson');

post(
route('backend.authorizations.assign-role-to-user').'?include=roles',
'auth/authorizations/assign-role-to-user?include=roles',
[
'role_id' => self::forId($role),
'user_id' => self::forId($user),
Expand All @@ -32,7 +31,7 @@
);
assertResponseOk();

$this->showModelWithRelation('backend.users.show', $user, $role, 'roles');
$this->showModelWithRelation('auth/users/'. self::forId($user), $role, 'roles');
});

it('revoke role from user', function () {
Expand All @@ -43,7 +42,7 @@
// $this->showModelWithRelation('backend.users.show', $user, $role, 'roles');

delete(
route('backend.authorizations.revoke-role-from-user').'?include=roles',
'auth/authorizations/revoke-role-from-user?include=roles',
[
'role_id' => self::forId($role),
'user_id' => self::forId($user),
Expand All @@ -61,10 +60,10 @@
$user = UserFactory::new()->create();
$permission = $this->createPermission();

$this->showModelWithRelation('backend.users.show', $user, $permission, 'permissions', 'dontSeeJson');
$this->showModelWithRelation('auth/users/'. self::forId($user), $permission, 'permissions', 'dontSeeJson');

post(
route('backend.authorizations.assign-permission-to-user').'?include=permissions',
'auth/authorizations/assign-permission-to-user?include=permissions',
[
'permission_id' => self::forId($permission),
'user_id' => self::forId($user),
Expand All @@ -73,7 +72,7 @@
);
assertResponseOk();

$this->showModelWithRelation('backend.users.show', $user, $permission, 'permissions');
$this->showModelWithRelation('auth/users/'. self::forId($user), $permission, 'permissions');
});

it('revoke permission to user', function () {
Expand All @@ -86,7 +85,7 @@
// $this->showModelWithRelation('backend.users.show', $user, $permission, 'permissions');

delete(
route('backend.authorizations.revoke-permission-from-user').'?include=permissions',
'auth/authorizations/revoke-permission-from-user?include=permissions',
[
'permission_id' => self::forId($permission),
'user_id' => self::forId($user),
Expand All @@ -104,10 +103,10 @@
$role = $this->createRole();
$permission = $this->createPermission();

$this->showModelWithRelation('backend.roles.show', $role, $permission, 'permissions', 'dontSeeJson');
$this->showModelWithRelation('auth/roles/'.self::forId($role), $permission, 'permissions', 'dontSeeJson');

post(
route('backend.authorizations.attach-permission-to-role').'?include=permissions',
'auth/authorizations/attach-permission-to-role?include=permissions',
[
'permission_id' => self::forId($permission),
'role_id' => self::forId($role),
Expand All @@ -116,7 +115,7 @@
);
assertResponseOk();

$this->showModelWithRelation('backend.roles.show', $role, $permission, 'permissions');
$this->showModelWithRelation('auth/roles/'.self::forId($role), $permission, 'permissions');
});

it('revoke permission from role', function () {
Expand All @@ -127,7 +126,7 @@
// $this->showModelWithRelation('backend.roles.show', $role, $permission, 'permissions');

delete(
route('backend.authorizations.revoke-permission-from-role').'?include=permissions',
'auth/authorizations/revoke-permission-from-role?include=permissions',
[
'permission_id' => self::forId($permission),
'role_id' => self::forId($role),
Expand Down
34 changes: 7 additions & 27 deletions tests/Auth/Authorization/RoleManagementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,11 @@
];
switch ($routeName) {
case 'store':
post(route($route), $paramNoData, $this->addHeaders());
post('auth/roles', $paramNoData, $this->addHeaders());
break;
case 'update':
put(
route(
$route,
[
'id' => self::forId($this->createRole()),
]
),
'auth/roles/'.self::forId($this->createRole()),
$paramNoData,
$this->addHeaders()
);
Expand All @@ -49,12 +44,7 @@
it('default role not allowed', function ($verbMethod, $routeName) {
$this->loggedInAs();
$this->{$verbMethod}(
route(
$routeName,
[
'id' => self::forId($this->getByRoleName('system')),
]
),
'auth/roles/'.self::forId($this->getByRoleName('system')),
$verbMethod == 'delete' ? [] : ['name' => $this->getByRoleName('system')->name],
$this->addHeaders()
);
Expand All @@ -76,7 +66,7 @@
$data = [
'name' => 'test new role',
];
post(route('backend.roles.store'), $data, $this->addHeaders());
post('auth/roles', $data, $this->addHeaders());

assertResponseStatus(201);
seeJson($data);
Expand All @@ -93,12 +83,7 @@
];

put(
route(
'backend.roles.update',
[
'id' => self::forId($role),
]
),
'auth/roles/'.self::forId($role),
$data,
$this->addHeaders()
);
Expand All @@ -120,12 +105,7 @@
];

put(
route(
'backend.roles.update',
[
'id' => self::forId($role),
]
),
'auth/roles/'.self::forId($role),
$data,
$this->addHeaders()
);
Expand All @@ -147,7 +127,7 @@
$data = [
'name' => $roleNameTest,
];
post(route('backend.roles.store'), $data, $this->addHeaders());
post('auth/roles', $data, $this->addHeaders());

assertResponseStatus(422);
seeJson(
Expand Down
8 changes: 6 additions & 2 deletions tests/Auth/User/BasicResourceFailedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
it('cannot_delete_self', function () {
$user = $this->loggedInAs();

$this->delete(route('backend.users.destroy', ['id' => self::forId($user)]), [], $this->addHeaders());
$this->delete(
'auth/users/'. self::forId($user),
[],
$this->addHeaders()
);

assertResponseStatus(403);
seeJson(
Expand All @@ -27,6 +31,6 @@

$user->delete();

get(route('backend.users.show', ['id' => $hashedId]), $this->addHeaders());
get('auth/users/'.$hashedId, $this->addHeaders());
assertResponseStatus(404);
});
17 changes: 8 additions & 9 deletions tests/Auth/User/BasicResourceSuccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
it('store user', function () {
$this->loggedInAs();

post(route('backend.users.store'), $this->userData(), $this->addHeaders());
post('auth/users', $this->userData(), $this->addHeaders());
assertResponseStatus(201);

$data = $this->userData();
Expand All @@ -30,7 +30,7 @@
$user = UserFactory::new()->create();

put(
route('backend.users.update', ['id' => self::forId($user)]),
'auth/users/'.self::forId($user),
$this->userData(),
$this->addHeaders()
);
Expand All @@ -48,7 +48,11 @@

$user = UserFactory::new()->create();

delete(route('backend.users.destroy', ['id' => self::forId($user)]), [], $this->addHeaders());
delete(
'auth/users/'.self::forId($user),
[],
$this->addHeaders()
);
assertResponseStatus(204);

notSeeInDatabase(
Expand All @@ -65,12 +69,7 @@
$user = UserFactory::new()->create($this->userData());

get(
route(
'backend.users.show',
[
'id' => self::forId($user),
]
),
'auth/users/'.self::forId($user),
$this->addHeaders()
);

Expand Down
12 changes: 10 additions & 2 deletions tests/Auth/User/DeleteResourceFailedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@

$user = UserFactory::new()->create();

delete(route('backend.users.purge', ['id' => self::forId($user)]), [], $this->addHeaders());
delete(
'auth/users/'.self::forId($user).'/purge',
[],
$this->addHeaders()
);
assertResponseStatus(404);
});

Expand All @@ -25,6 +29,10 @@

$user = UserFactory::new()->create();

put(route('backend.users.restore', ['id' => self::forId($user)]), [], $this->addHeaders());
put(
'auth/users/'.self::forId($user).'/restore',
[],
$this->addHeaders()
);
assertResponseStatus(404);
});
12 changes: 10 additions & 2 deletions tests/Auth/User/DeleteResourceSuccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
$user = UserFactory::new()->create();
$user->delete();

put(route('backend.users.restore', ['id' => self::forId($user)]), [], $this->addHeaders());
put(
'auth/users/'.self::forId($user).'/restore',
[],
$this->addHeaders()
);
assertResponseStatus(200);

seeInDatabase(
Expand All @@ -44,7 +48,11 @@
$user = UserFactory::new()->create();
$user->delete();

delete(route('backend.users.purge', ['id' => self::forId($user)]), [], $this->addHeaders());
delete(
'auth/users/'.self::forId($user).'/purge',
[],
$this->addHeaders()
);
assertResponseStatus(204);

notSeeInDatabase(
Expand Down
2 changes: 1 addition & 1 deletion tests/Auth/User/UserProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
]
)->toArray();
}
get(route('frontend.users.profile'), $this->addHeaders());
get('profile', $this->addHeaders());

if ( ! empty($roleName)) {
seeJson($userData);
Expand Down
2 changes: 1 addition & 1 deletion tests/Auth/User/UserValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
);

put(
route('backend.users.update', ['id' => self::forId($user)]),
'auth/users/'.self::forId($user),
[
'email' => $uniqueEmail,
],
Expand Down

0 comments on commit 9458940

Please sign in to comment.