|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Unit\Importer; |
| 4 | + |
| 5 | +use App\Importer\AssetImporter; |
| 6 | +use App\Models\Statuslabel; |
| 7 | +use Tests\TestCase; |
| 8 | +use function Livewire\invade; |
| 9 | + |
| 10 | +class AssetImportTest extends TestCase |
| 11 | +{ |
| 12 | + public function test_uses_first_deployable_status_label_as_default_if_one_exists() |
| 13 | + { |
| 14 | + Statuslabel::truncate(); |
| 15 | + |
| 16 | + $pendingStatusLabel = Statuslabel::factory()->pending()->create(); |
| 17 | + $readyToDeployStatusLabel = Statuslabel::factory()->readyToDeploy()->create(); |
| 18 | + |
| 19 | + $importer = new AssetImporter('assets.csv'); |
| 20 | + |
| 21 | + $this->assertEquals( |
| 22 | + $readyToDeployStatusLabel->id, |
| 23 | + invade($importer)->defaultStatusLabelId |
| 24 | + ); |
| 25 | + } |
| 26 | + |
| 27 | + public function test_uses_first_status_label_as_default_if_deployable_status_label_does_not_exist() |
| 28 | + { |
| 29 | + Statuslabel::truncate(); |
| 30 | + |
| 31 | + $statusLabel = Statuslabel::factory()->pending()->create(); |
| 32 | + |
| 33 | + $importer = new AssetImporter('assets.csv'); |
| 34 | + |
| 35 | + $this->assertEquals( |
| 36 | + $statusLabel->id, |
| 37 | + invade($importer)->defaultStatusLabelId |
| 38 | + ); |
| 39 | + } |
| 40 | + |
| 41 | + public function test_creates_default_status_label_if_one_does_not_exist() |
| 42 | + { |
| 43 | + Statuslabel::truncate(); |
| 44 | + |
| 45 | + $this->assertEquals(0, Statuslabel::count()); |
| 46 | + |
| 47 | + $importer = new AssetImporter('assets.csv'); |
| 48 | + |
| 49 | + $this->assertEquals(1, Statuslabel::count()); |
| 50 | + |
| 51 | + $this->assertEquals( |
| 52 | + Statuslabel::first()->id, |
| 53 | + invade($importer)->defaultStatusLabelId |
| 54 | + ); |
| 55 | + } |
| 56 | +} |
0 commit comments