| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <?php
- use Webkul\User\Models\Role;
- use function Pest\Laravel\deleteJson;
- use function Pest\Laravel\get;
- use function Pest\Laravel\postJson;
- use function Pest\Laravel\putJson;
- it('should returns the role index page', function () {
- // Act and Assert.
- $this->loginAsAdmin();
- get(route('admin.settings.roles.index'))
- ->assertOk()
- ->assertSeeText(trans('admin::app.settings.roles.index.title'))
- ->assertSeeText(trans('admin::app.settings.roles.index.create-btn'));
- });
- it('should returns the create page of role', function () {
- // Act and Assert.
- $this->loginAsAdmin();
- get(route('admin.settings.roles.create'))
- ->assertOk()
- ->assertSeeText(trans('admin::app.settings.roles.create.title'))
- ->assertSeeText(trans('admin::app.settings.roles.create.save-btn'));
- });
- it('should fail the validation with errors when certain field not provided when store the roles', function () {
- // Act and Assert.
- $this->loginAsAdmin();
- postJson(route('admin.settings.roles.store'))
- ->assertJsonValidationErrorFor('name')
- ->assertJsonValidationErrorFor('description')
- ->assertJsonValidationErrorFor('permission_type')
- ->assertUnprocessable();
- });
- it('should store the newly created roles', function () {
- // Act and Assert.
- $this->loginAsAdmin();
- postJson(route('admin.settings.roles.store'), $data = [
- 'name' => fake()->name(),
- 'permission_type' => fake()->randomElement(['custom', 'all']),
- 'description' => fake()->sentence(),
- 'permissions' => [
- 0 => acl()->getRoles()->random(),
- ],
- ])
- ->assertRedirect(route('admin.settings.roles.index'))
- ->isRedirection();
- $this->assertModelWise([
- Role::class => [
- [
- 'name' => $data['name'],
- 'permission_type' => $data['permission_type'],
- 'description' => $data['description'],
- ],
- ],
- ]);
- });
- it('should returns the edit page of roles', function () {
- // Arrange.
- $role = Role::factory()->create();
- // Act and Assert.
- $this->loginAsAdmin();
- putJson(route('admin.settings.roles.edit', $role->id), $data = [
- 'name' => fake()->name(),
- 'permission_type' => fake()->randomElement(['custom', 'all']),
- 'description' => fake()->sentence(),
- ])
- ->assertRedirect(route('admin.settings.roles.index'))
- ->isRedirection();
- $this->assertModelWise([
- Role::class => [
- [
- 'name' => $data['name'],
- 'permission_type' => $data['permission_type'],
- 'description' => $data['description'],
- ],
- ],
- ]);
- });
- it('should fail the validation with errors when certain field not provided when update the roles', function () {
- // Arrange.
- $role = Role::factory()->create();
- // Act and Assert.
- $this->loginAsAdmin();
- putJson(route('admin.settings.roles.update', $role->id))
- ->assertJsonValidationErrorFor('name')
- ->assertJsonValidationErrorFor('description')
- ->assertJsonValidationErrorFor('permission_type')
- ->assertUnprocessable();
- });
- it('should update the existing role', function () {
- // Arrange.
- $role = Role::factory()->create();
- // Act and Assert.
- $this->loginAsAdmin();
- putJson(route('admin.settings.roles.update', $role->id), $data = [
- 'name' => fake()->name(),
- 'permission_type' => fake()->randomElement(['custom', 'all']),
- 'description' => fake()->sentence(),
- ])
- ->assertRedirect(route('admin.settings.roles.index'))
- ->isRedirection();
- $this->assertModelWise([
- Role::class => [
- [
- 'name' => $data['name'],
- 'permission_type' => $data['permission_type'],
- 'description' => $data['description'],
- ],
- ],
- ]);
- });
- it('should delete the existing role', function () {
- // Arrange.
- $role = Role::factory()->create();
- // Act and Assert.
- $this->loginAsAdmin();
- deleteJson(route('admin.settings.roles.delete', $role->id))
- ->assertOk()
- ->assertJsonPath('message', trans('admin::app.settings.roles.delete-success'));
- $this->assertDatabaseMissing('roles', [
- 'id' => $role->id,
- ]);
- });
|