snipe-it/tests/unit/AssetTest.php
Andrea Bergamasco e03ebc3fd0 AssetTransformer refactoring, restored tests (#3407)
* Refactored AssetsTransformer

Casted all ids to int, escaped all text values,

* Added warranty_expires attribute to Asset model

$asset->warranty_expires contains a Carbon object with the warranty
expiration date. Returns null when either purchase_date or
warranty_months are not set.

* Ignoring php-cs cache files

* Restored asset tests expectations

Work in progress - tests still fail

* API controller refactoring, fixed HTTP status codes in responses

* Restored $request->get - debugging

* Added further checks in ApiAssetsCest::updateAssetWithPatch
2017-03-14 08:37:39 -07:00

65 lines
2 KiB
PHP

<?php
use App\Models\Asset;
use Illuminate\Support\Facades\Hash;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class AssetTest extends \Codeception\TestCase\Test
{
/**
* @var \UnitTester
*/
protected $tester;
use DatabaseMigrations;
public function testAssetAdd()
{
$asset = factory(Asset::class, 'asset')->make();
$values = [
'name' => $asset->name,
'model_id' => $asset->model_id,
'status_id' => $asset->status_id,
'asset_tag' => $asset->asset_tag,
];
Asset::create($values);
$this->tester->seeRecord('assets', $values);
}
/**
* @test
*/
public function testWarrantyExpiresAttribute()
{
$asset = factory(\App\Models\Asset::class, 'asset')->create();
$asset->purchase_date = \Carbon\Carbon::createFromDate(2017, 1, 1);
$asset->warranty_months = 24;
$asset->save();
$saved_asset = \App\Models\Asset::find($asset->id);
$this->tester->assertInstanceOf(\DateTime::class, $saved_asset->purchase_date);
$this->tester->assertEquals(
\Carbon\Carbon::createFromDate(2017,1,1)->format('Y-m-d'),
$saved_asset->purchase_date->format('Y-m-d')
);
$this->tester->assertEquals(
\Carbon\Carbon::createFromDate(2017,1,1)->setTime(0,0,0),
$saved_asset->purchase_date
);
$this->tester->assertEquals(24, $saved_asset->warranty_months);
$this->tester->assertInstanceOf(\DateTime::class, $saved_asset->warranty_expires);
$this->tester->assertEquals(
\Carbon\Carbon::createFromDate(2019,1,1)->format('Y-m-d'),
$saved_asset->warranty_expires->format('Y-m-d')
);
$this->tester->assertEquals(
\Carbon\Carbon::createFromDate(2019,1,1)->setTime(0,0,0),
$saved_asset->warranty_expires
);
}
}