80 lines
2.5 KiB
PHP
80 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Material;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Tests\TestCase;
|
|
|
|
class CustomModelOrderTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_customer_can_order_custom_model_via_file_upload(): void
|
|
{
|
|
Storage::fake('public');
|
|
|
|
Material::updateOrCreate(['code' => 'pla'], [
|
|
'name' => 'PLA+ Premium',
|
|
'code' => 'pla',
|
|
'price_multiplier' => 1.0,
|
|
'is_active' => true,
|
|
]);
|
|
|
|
$file = UploadedFile::fake()->create('custom_pikachu.stl', 1500, 'application/sla');
|
|
|
|
$response = $this->post(route('custom.cart.add'), [
|
|
'model_name' => 'Mijn Custom Pikachu',
|
|
'model_file' => $file,
|
|
'size' => 'medium',
|
|
'material' => 'pla',
|
|
'color' => 'Zon Geel (Pikachu)',
|
|
'quantity' => 2,
|
|
]);
|
|
|
|
$response->assertRedirect(route('cart.index'));
|
|
$response->assertSessionHas('success');
|
|
|
|
$cart = session('cart');
|
|
$this->assertNotEmpty($cart);
|
|
|
|
$item = array_values($cart)[0];
|
|
$this->assertTrue($item['is_custom']);
|
|
$this->assertEquals('Custom Print: Mijn Custom Pikachu', $item['name']);
|
|
$this->assertEquals(16.95, $item['price']);
|
|
$this->assertEquals(2, $item['quantity']);
|
|
$this->assertEquals('custom_pikachu.stl', $item['custom_file_name']);
|
|
$this->assertNotNull($item['custom_file_path']);
|
|
|
|
Storage::disk('public')->assertExists($item['custom_file_path']);
|
|
}
|
|
|
|
public function test_customer_can_order_custom_model_via_makerworld_url(): void
|
|
{
|
|
Material::updateOrCreate(['code' => 'pla'], [
|
|
'name' => 'PLA+ Premium',
|
|
'code' => 'pla',
|
|
'price_multiplier' => 1.0,
|
|
'is_active' => true,
|
|
]);
|
|
|
|
$response = $this->post(route('custom.cart.add'), [
|
|
'model_url' => 'https://makerworld.com/nl/models/55866',
|
|
'size' => 'klein',
|
|
'material' => 'pla',
|
|
'color' => 'Vurig Rood (Charizard)',
|
|
'quantity' => 1,
|
|
]);
|
|
|
|
$response->assertRedirect(route('cart.index'));
|
|
|
|
$cart = session('cart');
|
|
$item = array_values($cart)[0];
|
|
$this->assertTrue($item['is_custom']);
|
|
$this->assertEquals(9.95, $item['price']);
|
|
$this->assertEquals('https://makerworld.com/nl/models/55866', $item['custom_model_url']);
|
|
}
|
|
}
|