190 lines
6.4 KiB
PHP
190 lines
6.4 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([
|
|
'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('only allows tankcleaning products for only tankcleaning customers', function (): void {
|
|
api_test_covers('POST /order/items', 'customer_rules');
|
|
|
|
$customer = api_fixtures()->createUser(['display_name' => 'Only Tankcleaning Customer']);
|
|
api_fixtures()->addCustomerAttribute((int)$customer['id'], 'onlyTankCleaning');
|
|
$department = api_fixtures()->createDepartment();
|
|
$order = api_fixtures()->createOrder([
|
|
'customer_id' => $customer['customer_number'],
|
|
'department_id' => $department['id'],
|
|
'reference' => 'ONLY-TANK',
|
|
]);
|
|
$washProduct = api_fixtures()->createProduct([
|
|
'name' => 'Forvogn',
|
|
'price' => 649,
|
|
'category' => 4,
|
|
]);
|
|
$tankCleaningProduct = api_fixtures()->createProduct([
|
|
'name' => 'Saebe/kemi, 1-4 spulehoveder',
|
|
'price' => 299,
|
|
'category' => 5,
|
|
]);
|
|
$session = api_fixtures()->createUserSession([], ['group_id' => 1]);
|
|
|
|
api_client()
|
|
->post('/order/items', [
|
|
'order_id' => $order['id'],
|
|
'product_id' => $washProduct['id'],
|
|
'quantity' => 1,
|
|
], $session['headers'])
|
|
->assertStatus(400)
|
|
->assertEnvelope()
|
|
->assertSuccess(false)
|
|
->assertMessage(\classes\customer_order_product_policy::ONLY_TANKCLEANING_MESSAGE);
|
|
|
|
$response = api_client()->post('/order/items', [
|
|
'order_id' => $order['id'],
|
|
'product_id' => $tankCleaningProduct['id'],
|
|
'quantity' => 1,
|
|
], $session['headers']);
|
|
|
|
$response
|
|
->assertStatus(200)
|
|
->assertEnvelope()
|
|
->assertSuccess();
|
|
|
|
expect((int)($response->data()['product_id'] ?? 0))->toBe((int)$tankCleaningProduct['id']);
|
|
});
|
|
|
|
it('allows non-tankcleaning products for customers without the only tankcleaning attribute', function (): void {
|
|
api_test_covers('POST /order/items', 'customer_rules');
|
|
|
|
$customer = api_fixtures()->createUser(['display_name' => 'Regular Order Item Customer']);
|
|
$department = api_fixtures()->createDepartment();
|
|
$order = api_fixtures()->createOrder([
|
|
'customer_id' => $customer['customer_number'],
|
|
'department_id' => $department['id'],
|
|
'reference' => 'REGULAR-WASH',
|
|
]);
|
|
$washProduct = api_fixtures()->createProduct([
|
|
'name' => 'Forvogn',
|
|
'price' => 649,
|
|
'category' => 4,
|
|
]);
|
|
$session = api_fixtures()->createUserSession([], ['group_id' => 1]);
|
|
|
|
$response = api_client()->post('/order/items', [
|
|
'order_id' => $order['id'],
|
|
'product_id' => $washProduct['id'],
|
|
'quantity' => 1,
|
|
], $session['headers']);
|
|
|
|
$response
|
|
->assertStatus(200)
|
|
->assertEnvelope()
|
|
->assertSuccess();
|
|
|
|
expect((int)($response->data()['product_id'] ?? 0))->toBe((int)$washProduct['id']);
|
|
});
|
|
|
|
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([
|
|
'name' => 'API Note Required Product',
|
|
'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([
|
|
'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();
|
|
});
|