Files
Verde-Web/tests/Feature/Api/V1/Store/StorePortalEnhancementsTest.php

67 lines
2.4 KiB
PHP

<?php
namespace Tests\Feature\Api\V1\Store;
use App\Models\PartnerStore;
use App\Models\StoreSale;
use App\Models\Tenant;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class StorePortalEnhancementsTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->seed();
}
public function test_it_can_get_tenant_specific_pricing_settings()
{
$tenant = Tenant::factory()->create(['qr_retail_price_centavos' => 2500]);
$user = User::factory()->create(['role' => User::ROLE_STORE_PARTNER, 'tenant_id' => $tenant->id]);
$store = PartnerStore::factory()->create(['owner_user_id' => $user->id, 'tenant_id' => $tenant->id, 'commission_rate_percent' => 15]);
$response = $this->actingAs($user)
->withHeader('X-Tenant-Code', $tenant->code)
->getJson(route('api.v1.store.settings'));
$response->assertOk()
->assertJsonPath('data.retail_price_centavos', 2500)
->assertJsonPath('data.retail_price_pesos', 25)
->assertJsonPath('data.commission_rate_percent', 15);
}
public function test_it_can_download_sale_receipt()
{
$user = User::factory()->create(['role' => User::ROLE_STORE_PARTNER]);
$store = PartnerStore::factory()->create(['owner_user_id' => $user->id, 'tenant_id' => $user->tenant_id]);
$sale = StoreSale::factory()->create(['store_id' => $store->id]);
$response = $this->actingAs($user)
->getJson(route('api.v1.store.sales.receipt', $sale));
$response->assertOk()
->assertHeader('Content-Type', 'application/pdf');
}
public function test_it_cannot_download_receipt_from_another_store()
{
$user1 = User::factory()->create(['role' => User::ROLE_STORE_PARTNER]);
$store1 = PartnerStore::factory()->create(['owner_user_id' => $user1->id, 'tenant_id' => $user1->tenant_id]);
$user2 = User::factory()->create(['role' => User::ROLE_STORE_PARTNER]);
$store2 = PartnerStore::factory()->create(['owner_user_id' => $user2->id, 'tenant_id' => $user2->tenant_id]);
$saleFromStore2 = StoreSale::factory()->create(['store_id' => $store2->id]);
$response = $this->actingAs($user1)
->getJson(route('api.v1.store.sales.receipt', $saleFromStore2));
$response->assertStatus(403);
}
}