Add custom-only department pricing enforcement
This commit is contained in:
@@ -222,6 +222,85 @@ it('fails price setup gaps without exposing product defaults', function (): void
|
||||
expect($response->data()['missing_products'][0]['id'] ?? null)->toBe((int)$product['id']);
|
||||
});
|
||||
|
||||
it('defaults missing custom-only department prices to sentinel without exposing fallback prices', function (): void {
|
||||
api_test_covers('GET /limited-backoffice/departments', 'happy');
|
||||
api_test_covers('GET /limited-backoffice/departments/{departmentId}/prices', 'happy');
|
||||
api_test_covers('PUT /limited-backoffice/departments/{departmentId}/prices', 'happy');
|
||||
|
||||
$department = api_fixtures()->createDepartment([
|
||||
'name' => 'Limited Custom Pricing Only',
|
||||
'custom_pricing_only' => 1,
|
||||
]);
|
||||
$otherDepartment = api_fixtures()->createDepartment(['name' => 'Limited Other Pricing']);
|
||||
$category = api_fixtures()->createCategory(['name' => 'Limited Custom Pricing Category']);
|
||||
$product = api_fixtures()->createProduct([
|
||||
'name' => 'Custom Missing Product',
|
||||
'category' => $category['id'],
|
||||
'price' => 87654,
|
||||
]);
|
||||
$otherProduct = api_fixtures()->createProduct([
|
||||
'name' => 'Custom Missing Other Product',
|
||||
'category' => $category['id'],
|
||||
'price' => 76543,
|
||||
]);
|
||||
api_fixtures()->linkDepartmentCategory((int)$department['id'], (int)$category['id']);
|
||||
api_fixtures()->linkDepartmentCategory((int)$otherDepartment['id'], (int)$category['id']);
|
||||
limited_backoffice_price_insert((int)$otherDepartment['id'], (int)$product['id'], 4321);
|
||||
limited_backoffice_price_insert((int)$otherDepartment['id'], (int)$otherProduct['id'], 5432);
|
||||
|
||||
$session = limited_backoffice_manager_session([(int)$department['id']]);
|
||||
|
||||
$departments = api_client()->get('/limited-backoffice/departments', $session['headers']);
|
||||
$departments
|
||||
->assertStatus(200)
|
||||
->assertEnvelope()
|
||||
->assertSuccess();
|
||||
expect($departments->data()[0]['custom_pricing_only'] ?? null)->toBeTrue();
|
||||
|
||||
$response = api_client()->get('/limited-backoffice/departments/' . (int)$department['id'] . '/prices', $session['headers']);
|
||||
$response
|
||||
->assertStatus(200)
|
||||
->assertEnvelope()
|
||||
->assertSuccess();
|
||||
|
||||
expect($response->body)->not->toContain('87654');
|
||||
expect($response->body)->not->toContain('76543');
|
||||
expect($response->body)->not->toContain('4321');
|
||||
expect($response->body)->not->toContain('5432');
|
||||
expect($response->data()['department']['custom_pricing_only'] ?? null)->toBeTrue();
|
||||
$products = [];
|
||||
foreach ($response->data()['categories'] as $departmentCategory) {
|
||||
foreach ($departmentCategory['products'] as $departmentProduct) {
|
||||
$products[(int)$departmentProduct['id']] = $departmentProduct;
|
||||
}
|
||||
}
|
||||
expect($products[(int)$product['id']]['price'] ?? null)->toBe(\objects\products_o::CUSTOM_PRICING_MISSING_PRICE);
|
||||
expect($products[(int)$otherProduct['id']]['price'] ?? null)->toBe(\objects\products_o::CUSTOM_PRICING_MISSING_PRICE);
|
||||
|
||||
$updated = api_client()->put('/limited-backoffice/departments/' . (int)$department['id'] . '/prices', [
|
||||
'prices' => [
|
||||
['product_id' => (int)$product['id'], 'price' => 2222],
|
||||
],
|
||||
], $session['headers']);
|
||||
$updated
|
||||
->assertStatus(200)
|
||||
->assertEnvelope()
|
||||
->assertSuccess();
|
||||
|
||||
$updatedProducts = [];
|
||||
foreach ($updated->data()['categories'] as $departmentCategory) {
|
||||
foreach ($departmentCategory['products'] as $departmentProduct) {
|
||||
$updatedProducts[(int)$departmentProduct['id']] = $departmentProduct;
|
||||
}
|
||||
}
|
||||
expect($updated->body)->not->toContain('87654');
|
||||
expect($updated->body)->not->toContain('76543');
|
||||
expect($updated->body)->not->toContain('4321');
|
||||
expect($updated->body)->not->toContain('5432');
|
||||
expect($updatedProducts[(int)$product['id']]['price'] ?? null)->toBe(2222);
|
||||
expect($updatedProducts[(int)$otherProduct['id']]['price'] ?? null)->toBe(\objects\products_o::CUSTOM_PRICING_MISSING_PRICE);
|
||||
});
|
||||
|
||||
it('rejects invalid price batches and leaves existing prices unchanged', function (): void {
|
||||
api_test_covers('PUT /limited-backoffice/departments/{departmentId}/prices', 'validation');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user