- Return empty arrays for empty inputs in Redis `mget`, `db_object_t`, and `users_o` operations. - Refactor safety seal validation logic to handle numeric strings and improve clarity. - Add unit and API tests to verify handling of empty inputs and numeric safety seal strings.
49 lines
1.8 KiB
PHP
49 lines
1.8 KiB
PHP
<?php
|
|
|
|
app_require('classes/customer_name_cache_payload_builder.php');
|
|
app_require('objects/users_o.php');
|
|
|
|
use classes\customer_name_cache_payload_builder;
|
|
use objects\users_o;
|
|
|
|
it('builds customer name cache payloads from economic data or display-name fallbacks', function (): void {
|
|
expect(customer_name_cache_payload_builder::build(
|
|
(object)['name' => 'Truckwash ApS'],
|
|
'Fallback Name'
|
|
))->toBe(['name' => 'Truckwash ApS']);
|
|
|
|
expect(customer_name_cache_payload_builder::build(
|
|
null,
|
|
'Fallback Name'
|
|
))->toBe(['name' => 'Fallback Name']);
|
|
|
|
expect(customer_name_cache_payload_builder::build(
|
|
(object)['name' => ' '],
|
|
null
|
|
))->toBeNull();
|
|
});
|
|
|
|
it('guards bulk customer-name cache writes behind a resolved payload check', function (): void {
|
|
$usersFile = app_path('objects/users_o.php');
|
|
$content = file_get_contents($usersFile);
|
|
|
|
expect($content)->not->toBeFalse();
|
|
expect($content)->toContain('use classes\customer_name_cache_payload_builder;');
|
|
expect($content)->toContain('return customer_name_cache_payload_builder::build($cached_name, $fallback_name);');
|
|
expect($content)->toContain('$cache_payload = self::buildCustomerNameCachePayload($cached_name, $fallback_name);');
|
|
expect($content)->toContain('if ($cache_payload !== null) {');
|
|
expect($content)->toContain("\$this->cache('economic_customer_name', \$cache_payload, \$customer_number);");
|
|
});
|
|
|
|
it('returns an empty customer name map without touching cache for empty input', function (): void {
|
|
$users = new users_o();
|
|
|
|
expect($users->getCustomerNames([]))->toBe([]);
|
|
});
|
|
|
|
it('returns no rows for empty array field filters', function (): void {
|
|
$users = new users_o();
|
|
|
|
expect($users->getFieldsWhere(['id' => []], ['customer_number']))->toBe([]);
|
|
});
|