98 lines
3.4 KiB
PHP
98 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Forms;
|
|
|
|
use App\Domains\Attachable\Enums\AttachmentType;
|
|
use App\Domains\Attachable\Models\Attachment;
|
|
use App\Domains\Auth\Models\User;
|
|
use App\Domains\Authorization\Enums\RoleCode;
|
|
use App\Domains\Purchase\Models\Purchase;
|
|
use App\Domains\Tenant\Models\Tenant;
|
|
use App\Domains\Tenant\Models\WebsiteType;
|
|
use Database\Seeders\AuthorizationSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use Tests\TestCase;
|
|
|
|
class AdminAppSaleFormControllerTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->seed(AuthorizationSeeder::class);
|
|
WebsiteType::query()->create([
|
|
'codigo' => 'onticket',
|
|
'nombre' => 'OnTicket',
|
|
]);
|
|
}
|
|
|
|
public function test_authentication_is_required(): void
|
|
{
|
|
$this->getJson('/api/v1/adminapp/forms/sale')->assertUnauthorized();
|
|
}
|
|
|
|
public function test_an_adminapp_user_can_get_the_sale_form(): void
|
|
{
|
|
$tenant = $this->createTenant('acme');
|
|
Sanctum::actingAs(User::factory()->create([
|
|
'rol_codigo' => RoleCode::AdminApp->value,
|
|
'tenant_codigo' => $tenant->codigo,
|
|
]));
|
|
|
|
$this->getJson('/api/v1/adminapp/forms/sale')
|
|
->assertOk()
|
|
->assertJsonCount(count(Purchase::adminStatusCodes()), 'data.statuses')
|
|
->assertJsonPath('data.statuses.0.value', Purchase::ADMIN_STATUS_INCOMPLETE)
|
|
->assertJsonPath('data.statuses.0.label', 'Por completar datos')
|
|
->assertJsonPath('data.statuses.0.real_statuses.0', Purchase::STATUS_CREATED)
|
|
->assertJsonPath('data.statuses.1.value', Purchase::ADMIN_STATUS_AWAITING_PAYMENT)
|
|
->assertJsonPath('data.statuses.1.real_statuses.0', Purchase::STATUS_PENDING_PAYMENT)
|
|
->assertJsonPath('data.statuses.1.real_statuses.1', Purchase::STATUS_IN_REVIEW)
|
|
->assertJsonPath('data.statuses.2.value', Purchase::ADMIN_STATUS_CONFIRMED)
|
|
->assertJsonPath('data.statuses.3.value', Purchase::ADMIN_STATUS_CANCELLED);
|
|
}
|
|
|
|
public function test_a_customer_cannot_get_the_sale_form(): void
|
|
{
|
|
Sanctum::actingAs(User::factory()->create([
|
|
'rol_codigo' => RoleCode::User->value,
|
|
'tenant_codigo' => null,
|
|
]));
|
|
|
|
$this->getJson('/api/v1/adminapp/forms/sale')->assertForbidden();
|
|
}
|
|
|
|
private function createTenant(string $code): Tenant
|
|
{
|
|
$headerLogo = $this->createAttachment("{$code}-header");
|
|
$footerLogo = $this->createAttachment("{$code}-footer");
|
|
|
|
return Tenant::query()->create([
|
|
'codigo' => $code,
|
|
'nombre' => ucfirst($code),
|
|
'dominio' => "{$code}.test",
|
|
'primary_color' => '#000000',
|
|
'secondary_color' => '#ffffff',
|
|
'danger_color' => '#dc3545',
|
|
'header_bg_color' => '#ffffff',
|
|
'footer_bg_color' => '#000000',
|
|
'header_logo_id' => $headerLogo->id,
|
|
'footer_logo_id' => $footerLogo->id,
|
|
'website_type_code' => 'onticket',
|
|
]);
|
|
}
|
|
|
|
private function createAttachment(string $name): Attachment
|
|
{
|
|
return Attachment::query()->create([
|
|
'path' => "test/{$name}.png",
|
|
'filename' => "{$name}.png",
|
|
'type' => AttachmentType::Image,
|
|
'mime_type' => 'image/png',
|
|
]);
|
|
}
|
|
}
|