Skip to content

Commit

Permalink
a couple more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerrlongg committed May 7, 2024
1 parent ad2ba25 commit 5b86ee7
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions tests/Feature/Assets/AssetsBulkEditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,36 @@

class AssetsBulkEditTest extends TestCase
{
public function testUserWithPermissionsCanAccessPage()
{
$user = User::factory()->viewAssets()->editAssets()->create();
$assets = Asset::factory()->count(2)->create();

$id_array = $assets->pluck('id')->toArray();

$this->actingAs($user)->post('/hardware/bulkedit', [
'ids' => $id_array,
'order' => 'asc',
'bulk_actions' => 'edit',
'sort' => 'id'
])->assertStatus(200);
}

public function testStandardUserCannotAccessPage()
{
$user = User::factory()->create();
$assets = Asset::factory()->count(2)->create();

$id_array = $assets->pluck('id')->toArray();

$this->actingAs($user)->post('/hardware/bulkedit', [
'ids' => $id_array,
'order' => 'asc',
'bulk_actions' => 'edit',
'sort' => 'id'
])->assertStatus(403);
}

public function testBulkEditAssetsAcceptsAllPossibleAttributes()
{
// sets up all needed models and attributes on the assets
Expand Down Expand Up @@ -103,7 +133,7 @@ public function testBulkEditAssetsAcceptsAndUpdatesUnencryptedCustomFields()
'ids' => $id_array,
$ram->db_column => 16,
$cpu->db_column => '4.1',
]);
])->assertStatus(302);

Asset::findMany($id_array)->each(function (Asset $asset) use ($ram, $cpu) {
$this->assertEquals(16, $asset->{$ram->db_column});
Expand All @@ -128,7 +158,7 @@ public function testBulkEditAssetsAcceptsAndUpdatesEncryptedCustomFields()
$this->actingAs(User::factory()->admin()->create())->post(route('hardware/bulksave'), [
'ids' => $id_array,
$encrypted->db_column => 'New Encrypted Text',
]);
])->assertStatus(302);

Asset::findMany($id_array)->each(function (Asset $asset) use ($encrypted) {
$this->assertEquals('New Encrypted Text', Crypt::decrypt($asset->{$encrypted->db_column}));
Expand Down Expand Up @@ -174,6 +204,5 @@ public function testBulkEditAssetsRequiresAdminUserToUpdateEncryptedCustomFields
Asset::findMany($standard_id_array)->each(function (Asset $asset) use ($encrypted) {
$this->assertEquals('Original Encrypted Text', Crypt::decrypt($asset->{$encrypted->db_column}));
});

}
}

0 comments on commit 5b86ee7

Please sign in to comment.