mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 22:07:29 -08:00
Some unittest fixes for local running adapting to various factory changes.
This commit is contained in:
parent
c2f1fd4942
commit
82de51f23e
|
@ -42,10 +42,10 @@ class AssetModelTest extends BaseTest
|
|||
public function testAnAssetModelContainsAssets()
|
||||
{
|
||||
$assetModel = $this->createValidAssetModel();
|
||||
factory(Asset::class)->create([
|
||||
$this->createValidAsset([
|
||||
'model_id' => $assetModel->id,
|
||||
]);
|
||||
$this->assertEquals(1,$assetModel->assets()->count());
|
||||
$this->assertEquals(1, $assetModel->assets()->count());
|
||||
}
|
||||
|
||||
public function testAnAssetModelHasACategory()
|
||||
|
|
|
@ -77,7 +77,11 @@ class AssetTest extends BaseTest
|
|||
*/
|
||||
public function testWarrantyExpiresAttribute()
|
||||
{
|
||||
$asset = factory(Asset::class)->states('laptop-mbp')->create(['model_id' => $this->createValidAssetModel()->id]);
|
||||
$asset = factory(Asset::class)->states('laptop-mbp')->create([
|
||||
'model_id' => $this->createValidAssetModel()->id,
|
||||
'supplier_id' => $this->createvalidSupplier()->id,
|
||||
'rtd_location_id' => $this->createValidLocation()->id
|
||||
]);
|
||||
|
||||
$asset->purchase_date = Carbon::createFromDate(2017, 1, 1)->hour(0)->minute(0)->second(0);
|
||||
$asset->warranty_months = 24;
|
||||
|
@ -109,7 +113,11 @@ class AssetTest extends BaseTest
|
|||
public function testModelIdMustExist()
|
||||
{
|
||||
$model = $this->createValidAssetModel();
|
||||
$asset = factory(Asset::class)->make(['model_id' => $model->id]);
|
||||
$asset = factory(Asset::class)->make([
|
||||
'model_id' => $model->id,
|
||||
'supplier_id' => $this->createValidSupplier()->id,
|
||||
'rtd_location_id' => $this->createValidLocation()->id
|
||||
]);
|
||||
$asset->save();
|
||||
$this->assertTrue($asset->isValid());
|
||||
$newId = $model->id + 1;
|
||||
|
@ -188,7 +196,9 @@ class AssetTest extends BaseTest
|
|||
|
||||
public function testAnAssetCanHaveUploads()
|
||||
{
|
||||
$asset = $this->createValidAsset();
|
||||
$asset = $this->createValidAsset([
|
||||
'supplier_id' => $this->createValidSupplier()->id
|
||||
]);
|
||||
$this->assertCount(0, $asset->uploads);
|
||||
factory(App\Models\Actionlog::class, 'asset-upload')->create(['item_id' => $asset->id]);
|
||||
$this->assertCount(1, $asset->fresh()->uploads);
|
||||
|
|
|
@ -16,7 +16,9 @@ class BaseTest extends \Codeception\TestCase\Test
|
|||
protected function signIn($user = null)
|
||||
{
|
||||
if (!$user) {
|
||||
$user = factory(User::class)->states('superuser')->create();
|
||||
$user = factory(User::class)->states('superuser')->create([
|
||||
'location_id' => $this->createValidLocation()->id
|
||||
]);
|
||||
}
|
||||
Auth::login($user);
|
||||
|
||||
|
@ -78,17 +80,24 @@ class BaseTest extends \Codeception\TestCase\Test
|
|||
|
||||
protected function createValidUser($overrides= [])
|
||||
{
|
||||
return factory(App\Models\User::class)->create($overrides);
|
||||
return factory(App\Models\User::class)->create(
|
||||
array_merge([
|
||||
'location_id'=>$this->createValidLocation()->id
|
||||
], $overrides)
|
||||
);
|
||||
}
|
||||
|
||||
protected function createValidAsset($overrides = [])
|
||||
protected function createValidAsset($overrides = [], $qty = 1)
|
||||
{
|
||||
$locId = $this->createValidLocation();
|
||||
$locId = $this->createValidLocation()->id;
|
||||
$this->createValidAssetModel();
|
||||
return factory(\App\Models\Asset::class)->states('laptop-mbp')->create([
|
||||
'rtd_location_id' => $locId,
|
||||
'location_id' => $locId
|
||||
], $overrides);
|
||||
return factory(\App\Models\Asset::class, $qty)->states('laptop-mbp')->create(
|
||||
array_merge([
|
||||
'rtd_location_id' => $locId,
|
||||
'location_id' => $locId,
|
||||
'supplier_id' => $this->createValidSupplier()->id
|
||||
], $overrides)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -38,7 +38,8 @@ class CategoryTest extends BaseTest
|
|||
$this->assertCount(5, $category->models);
|
||||
|
||||
$models->each(function($model) {
|
||||
factory(App\Models\Asset::class, 2)->create(['model_id' => $model->id]);
|
||||
// factory(App\Models\Asset::class, 2)->create(['model_id' => $model->id]);
|
||||
$this->createValidAsset(['model_id' => $model->id], 2);
|
||||
});
|
||||
$this->assertEquals(10, $category->itemCount());
|
||||
}
|
||||
|
|
|
@ -31,17 +31,14 @@ class CompanyTest extends BaseTest
|
|||
public function testACompanyCanHaveUsers()
|
||||
{
|
||||
$company = $this->createValidCompany();
|
||||
factory(App\Models\User::class, 1)->create(['company_id'=>$company->id]);
|
||||
$user = $this->createValidUser(['company_id'=>$company->id]);
|
||||
$this->assertCount(1, $company->users);
|
||||
}
|
||||
|
||||
public function testACompanyCanHaveAssets()
|
||||
{
|
||||
$company = $this->createValidCompany();
|
||||
factory(App\Models\Asset::class, 1)->states('laptop-mbp')->create([
|
||||
'company_id' => $company->id,
|
||||
'model_id' => $this->createValidAssetModel()->id
|
||||
]);
|
||||
$this->createValidAsset(['company_id' => $company->id]);
|
||||
$this->assertCount(1, $company->assets);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,15 +21,15 @@ class NotificationTest extends BaseTest
|
|||
|
||||
public function testAUserIsEmailedIfTheyCheckoutAnAssetWithEULA()
|
||||
{
|
||||
$admin = factory(User::class)->states('superuser')->create();
|
||||
Auth::login($admin);
|
||||
$cat = $this->createValidCategory('asset-laptop-category', ['require_acceptance' => true]);
|
||||
$model = $this->createValidAssetModel('mbp-13-model', ['category_id' => $cat->id]);
|
||||
$asset = $this->createValidAsset(['model_id' => $model->id]);
|
||||
$user = factory(User::class)->create();
|
||||
Notification::fake();
|
||||
$asset->checkOut($user, 1);
|
||||
$admin = factory(User::class)->states('superuser')->create();
|
||||
Auth::login($admin);
|
||||
$cat = $this->createValidCategory('asset-laptop-category', ['require_acceptance' => true]);
|
||||
$model = $this->createValidAssetModel('mbp-13-model', ['category_id' => $cat->id]);
|
||||
$asset = $this->createValidAsset(['model_id' => $model->id]);
|
||||
$user = $this->createValidUser();
|
||||
|
||||
Notification::assertSentTo($user, CheckoutAssetNotification::class);
|
||||
Notification::fake();
|
||||
$asset->checkOut($user, 1);
|
||||
Notification::assertSentTo($user, CheckoutAssetNotification::class);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue