Files
Verde-Web/tests/Feature/Api/V1/Me/MySalesControllerTest.php

63 lines
1.8 KiB
PHP

<?php
namespace Tests\Feature\Api\V1\Me;
use App\Models\Household;
use App\Models\PartnerStore;
use App\Models\StoreSale;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class MySalesControllerTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->seed();
}
public function test_it_can_list_my_sales_history()
{
$user = User::factory()->create(['role' => 'resident']);
$household = Household::factory()->create(['head_user_id' => $user->id]);
$store = PartnerStore::factory()->create();
StoreSale::factory()->count(3)->create([
'household_id' => $household->id,
'store_id' => $store->id,
'retail_price_centavos' => 2500,
'quantity' => 1,
]);
$response = $this->actingAs($user)
->getJson(route('api.v1.me.sales.index'));
$response->assertOk()
->assertJsonCount(3, 'data');
$this->assertNotNull($response->json('data.0.receipt_url'));
}
public function test_it_can_download_my_receipt()
{
$user = User::factory()->create(['role' => 'resident']);
$household = Household::factory()->create(['head_user_id' => $user->id]);
$store = PartnerStore::factory()->create();
$sale = StoreSale::factory()->create([
'household_id' => $household->id,
'store_id' => $store->id,
]);
$url = \Illuminate\Support\Facades\URL::signedRoute('api.v1.me.sales.receipt', ['sale' => $sale->id]);
$response = $this->actingAs($user)
->getJson($url);
$response->assertOk()
->assertHeader('Content-Type', 'application/pdf');
}
}