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

81 lines
2.4 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
]);
$response = $this->actingAs($user)
->getJson(route('api.v1.me.sales.receipt', $sale->id));
$response->assertOk()
->assertHeader('Content-Type', 'application/pdf');
}
public function test_it_cannot_download_others_receipt()
{
$user1 = User::factory()->create(['role' => 'resident']);
$household1 = Household::factory()->create(['head_user_id' => $user1->id]);
$user2 = User::factory()->create(['role' => 'resident']);
$household2 = Household::factory()->create(['head_user_id' => $user2->id]);
$store = PartnerStore::factory()->create();
$saleOfUser2 = StoreSale::factory()->create([
'household_id' => $household2->id,
'store_id' => $store->id
]);
$response = $this->actingAs($user1)
->getJson(route('api.v1.me.sales.receipt', $saleOfUser2->id));
$response->assertStatus(403);
}
}