Skip to content

A free open source IT asset/license management system

Update tests to send post request

Marcus Mooref763aea4fc15
diff --git a/tests/Feature/Api/Assets/AssetStoreTest.php b/tests/Feature/Api/Assets/AssetStoreTest.php
index 36678fe05a..e18a957e0f 100644
--- a/tests/Feature/Api/Assets/AssetStoreTest.php
+++ b/tests/Feature/Api/Assets/AssetStoreTest.php
@@ -6,7 +6,6 @@ use App\Models\Asset;
use App\Models\AssetModel;
use App\Models\Company;
use App\Models\CustomField;
-use App\Models\CustomFieldset;
use App\Models\Location;
use App\Models\Statuslabel;
use App\Models\Supplier;
@@ -484,40 +483,50 @@ class AssetStoreTest extends TestCase
public function testEncryptedCustomFieldCanBeStored()
{
+ $status = Statuslabel::factory()->create();
$field = CustomField::factory()->testEncrypted()->create();
- $asset = Asset::factory()->hasEncryptedCustomField($field)->create();
$superuser = User::factory()->superuser()->create();
+ $assetData = Asset::factory()->hasEncryptedCustomField($field)->make();
- //first, test that an Admin user can save the encrypted custom field
$response = $this->actingAsForApi($superuser)
- // @todo: target store method
- ->patchJson(route('api.assets.update', $asset->id), [
- $field->db_column_name() => 'This is encrypted field'
+ ->postJson(route('api.assets.store'), [
+ $field->db_column_name() => 'This is encrypted field',
+ 'model_id' => $assetData->model->id,
+ 'status_id' => $status->id,
+ 'asset_tag' => '1234',
])
->assertStatusMessageIs('success')
->assertOk()
->json();
- $asset->refresh();
+
+ $asset = Asset::findOrFail($response['payload']['id']);
$this->assertEquals('This is encrypted field', \Crypt::decrypt($asset->{$field->db_column_name()}));
}
public function testPermissionNeededToStoreEncryptedField()
{
+ // @todo:
+ $this->markTestIncomplete();
+
+ $status = Statuslabel::factory()->create();
$field = CustomField::factory()->testEncrypted()->create();
- $asset = Asset::factory()->hasEncryptedCustomField()->create();
$normal_user = User::factory()->editAssets()->create();
+ $assetData = Asset::factory()->hasEncryptedCustomField($field)->make();
- //next, test that a 'normal' user *cannot* change the encrypted custom field
$response = $this->actingAsForApi($normal_user)
- // @todo: target store method
- ->patchJson(route('api.assets.update', $asset->id), [
- $field->db_column_name() => 'Some Other Value Entirely!'
+ ->postJson(route('api.assets.store'), [
+ $field->db_column_name() => 'Some Other Value Entirely!',
+ 'model_id' => $assetData->model->id,
+ 'status_id' => $status->id,
+ 'asset_tag' => '1234',
])
+ // @todo: this is 403 unauthorized
->assertStatusMessageIs('success')
->assertOk()
->assertMessagesAre('Asset updated successfully, but encrypted custom fields were not due to permissions')
->json();
- $asset->refresh();
+
+ $asset = Asset::findOrFail($response['payload']['id']);
$this->assertEquals('This is encrypted field', \Crypt::decrypt($asset->{$field->db_column_name()}));
}
}
diff --git a/tests/Feature/Api/Assets/AssetUpdateTest.php b/tests/Feature/Api/Assets/AssetUpdateTest.php
index 05adbb9fff..7a155e1b7f 100644
--- a/tests/Feature/Api/Assets/AssetUpdateTest.php
+++ b/tests/Feature/Api/Assets/AssetUpdateTest.php
@@ -15,14 +15,13 @@ class AssetUpdateTest extends TestCase
$asset = Asset::factory()->hasEncryptedCustomField($field)->create();
$superuser = User::factory()->superuser()->create();
- //first, test that an Admin user can save the encrypted custom field
- $response = $this->actingAsForApi($superuser)
+ $this->actingAsForApi($superuser)
->patchJson(route('api.assets.update', $asset->id), [
$field->db_column_name() => 'This is encrypted field'
])
->assertStatusMessageIs('success')
- ->assertOk()
- ->json();
+ ->assertOk();
+
$asset->refresh();
$this->assertEquals('This is encrypted field', \Crypt::decrypt($asset->{$field->db_column_name()}));
}
@@ -34,17 +33,17 @@ class AssetUpdateTest extends TestCase
$normal_user = User::factory()->editAssets()->create();
$asset->{$field->db_column_name()} = \Crypt::encrypt("encrypted value should not change");
- $asset->save(); //is this needed?
+ $asset->save();
- //test that a 'normal' user *cannot* change the encrypted custom field
- $response = $this->actingAsForApi($normal_user)
+ // test that a 'normal' user *cannot* change the encrypted custom field
+ $this->actingAsForApi($normal_user)
->patchJson(route('api.assets.update', $asset->id), [
$field->db_column_name() => 'Some Other Value Entirely!'
])
->assertStatusMessageIs('success')
->assertOk()
- ->assertMessagesAre('Asset updated successfully, but encrypted custom fields were not due to permissions')
- ->json();
+ ->assertMessagesAre('Asset updated successfully, but encrypted custom fields were not due to permissions');
+
$asset->refresh();
$this->assertEquals("encrypted value should not change", \Crypt::decrypt($asset->{$field->db_column_name()}));
}