175 lines
5.9 KiB
PHP
175 lines
5.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
usesApiSuite();
|
|
|
|
it('requires notes when adding the extraordinary chemistry product to an order', function (): void {
|
|
api_test_covers('POST /order/items', 'validation');
|
|
|
|
$customer = api_fixtures()->createUser(['display_name' => 'Order Item Customer']);
|
|
$department = api_fixtures()->createDepartment();
|
|
$order = api_fixtures()->createOrder([
|
|
'customer_id' => $customer['customer_number'],
|
|
'department_id' => $department['id'],
|
|
'reference' => 'NOTE-REQUIRED',
|
|
]);
|
|
$product = api_fixtures()->createProduct([
|
|
'id' => 902701,
|
|
'name' => \objects\products_o::EXTRAORDINARY_CHEMISTRY_PRODUCT_NAME,
|
|
'price' => 299,
|
|
'requires_note' => 0,
|
|
]);
|
|
$session = api_fixtures()->createUserSession([], ['group_id' => 1]);
|
|
|
|
api_client()
|
|
->post('/order/items', [
|
|
'order_id' => $order['id'],
|
|
'product_id' => $product['id'],
|
|
'quantity' => 1,
|
|
'notes' => ' ',
|
|
], $session['headers'])
|
|
->assertStatus(400)
|
|
->assertEnvelope()
|
|
->assertSuccess(false)
|
|
->assertMessage('Notes is required for this product');
|
|
|
|
$response = api_client()->post('/order/items', [
|
|
'order_id' => $order['id'],
|
|
'product_id' => $product['id'],
|
|
'quantity' => 1,
|
|
'notes' => 'Graffiti removal on left side',
|
|
], $session['headers']);
|
|
|
|
$response
|
|
->assertStatus(200)
|
|
->assertEnvelope()
|
|
->assertSuccess();
|
|
|
|
expect($response->data()['notes'] ?? null)->toBe('Graffiti removal on left side');
|
|
});
|
|
|
|
it('uses a product fixed price instead of the best discount when adding an order item', function (): void {
|
|
api_test_covers('POST /order/items', 'pricing');
|
|
api_test_covers('GET /products', 'pricing');
|
|
|
|
$customer = api_fixtures()->createUser(['display_name' => 'Fixed Price Customer']);
|
|
$department = api_fixtures()->createDepartment();
|
|
$cashier = api_fixtures()->createUser(['display_name' => 'Fixed Price Cashier']);
|
|
$category = api_fixtures()->createCategory(['name' => 'Fixed Price Category']);
|
|
$product = api_fixtures()->createProduct([
|
|
'name' => 'Fixed Price Product',
|
|
'price' => 1000,
|
|
'category' => $category['id'],
|
|
'apply_category_discount' => 1,
|
|
]);
|
|
|
|
api_fixtures()->createPriceOverride([
|
|
'user_id' => $customer['id'],
|
|
'is_category' => 1,
|
|
'product_or_category_id' => (string)$category['id'],
|
|
'percentage' => 80,
|
|
]);
|
|
api_fixtures()->createPriceOverride([
|
|
'user_id' => $customer['id'],
|
|
'is_category' => 0,
|
|
'product_or_category_id' => (string)$product['id'],
|
|
'percentage' => 10,
|
|
'fixed_price' => 350,
|
|
]);
|
|
|
|
$order = api_fixtures()->createOrder([
|
|
'customer_id' => $customer['customer_number'],
|
|
'department_id' => $department['id'],
|
|
'cashier_id' => $cashier['id'],
|
|
'reference' => 'FIXED-PRICE',
|
|
]);
|
|
$session = api_fixtures()->createUserSession(['add_order_items', 'list_products']);
|
|
|
|
$productResponse = api_client()->get(
|
|
'/products?final_price=true&id=' . $product['id'] . '&customer_id=' . $customer['customer_number'],
|
|
$session['headers']
|
|
);
|
|
$productResponse
|
|
->assertStatus(200)
|
|
->assertEnvelope()
|
|
->assertSuccess();
|
|
expect($productResponse->data()['price'] ?? null)->toBe(350);
|
|
|
|
$response = api_client()->post('/order/items', [
|
|
'order_id' => $order['id'],
|
|
'product_id' => $product['id'],
|
|
'quantity' => 1,
|
|
], $session['headers']);
|
|
|
|
$response
|
|
->assertStatus(200)
|
|
->assertEnvelope()
|
|
->assertSuccess();
|
|
|
|
expect($response->data()['price'] ?? null)->toBe(350);
|
|
});
|
|
|
|
it('does not allow clearing notes for order items whose product requires notes', function (): void {
|
|
api_test_covers('PUT /order/items', 'validation');
|
|
|
|
$customer = api_fixtures()->createUser(['display_name' => 'Order Item Edit Customer']);
|
|
$department = api_fixtures()->createDepartment();
|
|
$cashier = api_fixtures()->createUser(['display_name' => 'Order Item Cashier']);
|
|
$order = api_fixtures()->createOrder([
|
|
'customer_id' => $customer['customer_number'],
|
|
'department_id' => $department['id'],
|
|
'cashier_id' => $cashier['id'],
|
|
'reference' => 'NOTE-EDIT',
|
|
]);
|
|
$product = api_fixtures()->createProduct([
|
|
'id' => 902702,
|
|
'name' => \objects\products_o::EXTRAORDINARY_CHEMISTRY_PRODUCT_NAME,
|
|
'price' => 199,
|
|
'requires_note' => 1,
|
|
]);
|
|
$orderItem = api_fixtures()->createOrderItem([
|
|
'order_id' => $order['id'],
|
|
'product_id' => $product['id'],
|
|
'cashier_id' => $cashier['id'],
|
|
'price' => 199,
|
|
'quantity' => 1,
|
|
'notes' => 'Initial note',
|
|
]);
|
|
$session = api_fixtures()->createUserSession(['edit_order_items', 'list_order_items']);
|
|
|
|
api_client()
|
|
->put('/order/items', [
|
|
'id' => $orderItem['id'],
|
|
'price' => 199,
|
|
'quantity' => 1,
|
|
'reference' => '',
|
|
'notes' => '',
|
|
], $session['headers'])
|
|
->assertStatus(400)
|
|
->assertEnvelope()
|
|
->assertSuccess(false)
|
|
->assertMessage('Notes is required for this product');
|
|
});
|
|
|
|
it('returns the extraordinary chemistry product with requires_note enabled', function (): void {
|
|
api_test_covers('GET /products', 'happy');
|
|
|
|
$product = api_fixtures()->createProduct([
|
|
'id' => 902703,
|
|
'name' => \objects\products_o::EXTRAORDINARY_CHEMISTRY_PRODUCT_NAME,
|
|
'price' => 299,
|
|
'requires_note' => 0,
|
|
]);
|
|
$session = api_fixtures()->createUserSession([], ['group_id' => 1]);
|
|
|
|
$response = api_client()->get('/products?id=' . $product['id'], $session['headers']);
|
|
|
|
$response
|
|
->assertStatus(200)
|
|
->assertEnvelope()
|
|
->assertSuccess();
|
|
|
|
expect($response->data()['requires_note'] ?? null)->toBeTrue();
|
|
});
|