Add tests.
This commit is contained in:
		| @@ -6,7 +6,9 @@ use App\Exports\Sales\Invoices as Export; | ||||
| use App\Jobs\Document\CreateDocument; | ||||
| use App\Models\Document\Document; | ||||
| use Illuminate\Http\UploadedFile; | ||||
| use Illuminate\Support\Carbon; | ||||
| use Illuminate\Support\Facades\File; | ||||
| use Illuminate\Support\Facades\Storage; | ||||
| use Tests\Feature\FeatureTestCase; | ||||
|  | ||||
| class InvoicesTest extends FeatureTestCase | ||||
| @@ -54,6 +56,47 @@ class InvoicesTest extends FeatureTestCase | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldCreateInvoiceWithAttachment() | ||||
|     { | ||||
|         Storage::fake('uploads'); | ||||
|         Carbon::setTestNow(Carbon::create(2021, 05, 15)); | ||||
|  | ||||
|         $file = new UploadedFile( | ||||
|             base_path('public/img/empty_pages/invoices.png'), | ||||
|             'invoices.png', | ||||
|             'image/png', | ||||
|             null, | ||||
|             true | ||||
|         ); | ||||
|  | ||||
|         $request = $this->getRequest(); | ||||
|         $request['attachment'] = [$file]; | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->post(route('invoices.store'), $request) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|  | ||||
|         Storage::disk('uploads')->assertExists('2021/05/15/1/invoices/invoices.png'); | ||||
|  | ||||
|         $this->assertDatabaseHas('documents', [ | ||||
|             'document_number' => $request['document_number'] | ||||
|         ]); | ||||
|         $this->assertDatabaseHas('mediables', [ | ||||
|             'mediable_type' => Document::class, | ||||
|             'tag'           => 'attachment', | ||||
|         ]); | ||||
|         $this->assertDatabaseHas('media', [ | ||||
|             'disk'           => 'uploads', | ||||
|             'directory'      => '2021/05/15/1/invoices', | ||||
|             'filename'       => 'invoices', | ||||
|             'extension'      => 'png', | ||||
|             'mime_type'      => 'image/png', | ||||
|             'aggregate_type' => 'image', | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldDuplicateInvoice() | ||||
|     { | ||||
|         $invoice = $this->dispatch(new CreateDocument($this->getRequest())); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user