/home/alixis5/integrate.sellofinance.com/tests/Unit/Services
Edit: /home/alixis5/integrate.sellofinance.com/tests/Unit/Services/CatalogAggregatorTest.php (8142B)
agg = new CatalogAggregator();
}
public function test_slugify_kebab_cases_english_name(): void
{
$this->assertSame('personal-loans', $this->agg->slugify('Personal Loans'));
$this->assertSame('home-finance', $this->agg->slugify('Home Finance'));
$this->assertSame('sme-finance', $this->agg->slugify('SME Finance'));
$this->assertSame('savings-deposits',$this->agg->slugify('Savings & Deposits'));
}
public function test_slugify_falls_back_to_category_when_input_is_empty_or_junk(): void
{
$this->assertSame('category', $this->agg->slugify(''));
$this->assertSame('category', $this->agg->slugify('&&&'));
$this->assertSame('category', $this->agg->slugify(' '));
}
public function test_shape_category_returns_id_slug_name_icon_sortorder(): void
{
$raw = [
'id' => 'cat-1',
'name' => 'Personal Loans',
'nameAr' => 'القروض الشخصية',
'iconClass' => 'pi-wallet',
'sortOrder' => 10,
'status' => 'active',
];
$shaped = $this->agg->shapeCategory($raw, productCount: 25);
$this->assertSame('cat-1', $shaped['id']);
$this->assertSame('personal-loans', $shaped['slug']);
$this->assertSame('Personal Loans', $shaped['name']);
$this->assertSame('القروض الشخصية', $shaped['nameAr']);
$this->assertSame('pi-wallet', $shaped['iconClass']);
$this->assertSame(10, $shaped['sortOrder']);
$this->assertSame(25, $shaped['productCount']);
}
public function test_shape_product_collapses_into_list_shape(): void
{
$raw = [
'id' => 'p1',
'name' => 'ADCB Personal Loan Classic',
'nameAr' => 'القرض الشخصي الكلاسيكي',
'productType' => 'personalLoan',
'financeType' => 'conventional',
'accountId' => '69d8390869f9620a2',
'categoryId' => 'cat-1',
'minAmount' => 5000,
'maxAmount' => 50000,
'minTenorMonths' => 6,
'maxTenorMonths' => 48,
'profitRateMin' => 3.99,
'profitRateMax' => 5.99,
'minSalary' => 5000,
'maxDbr' => 50,
'minCreditScore' => 600,
'processingFeePercent' => 1.0,
'createdAt' => '2026-04-20T19:36:00+00:00',
'modifiedAt' => '2026-04-22T12:00:00+00:00',
];
$category = [
'id' => 'cat-1', 'slug' => 'personal-loans', 'name' => 'Personal Loans',
'nameAr' => 'القروض الشخصية', 'iconClass' => 'pi-wallet', 'sortOrder' => 10, 'productCount' => 25,
];
$institution = ['id' => '69d8390869f9620a2', 'slug' => 'adcb', 'name' => 'ADCB Egypt', 'productCount' => 25];
$shaped = $this->agg->shapeProduct($raw, $category, $institution, requiredDocCount: 3);
$this->assertSame('p1', $shaped['id']);
$this->assertSame('ADCB Personal Loan Classic', $shaped['name']);
$this->assertSame('القرض الشخصي الكلاسيكي', $shaped['nameAr']);
$this->assertSame('personalLoan', $shaped['productType']);
$this->assertSame('conventional', $shaped['financeType']);
$this->assertSame($category, $shaped['category']);
$this->assertSame($institution, $shaped['institution']);
$this->assertSame(5000, $shaped['minAmount']);
$this->assertSame(50000, $shaped['maxAmount']);
$this->assertSame('AED', $shaped['currency']);
$this->assertSame(6, $shaped['minTenorMonths']);
$this->assertSame(48, $shaped['maxTenorMonths']);
$this->assertSame(3.99, $shaped['profitRateMin']);
$this->assertSame(5.99, $shaped['profitRateMax']);
$this->assertSame(5000, $shaped['minSalary']);
$this->assertSame(50, $shaped['maxDbr']);
$this->assertSame(600, $shaped['minCreditScore']);
$this->assertSame(1.0, $shaped['processingFeePercent']);
$this->assertSame(3, $shaped['requiredDocCount']);
$this->assertSame('2026-04-20T19:36:00+00:00', $shaped['createdAt']);
$this->assertSame('2026-04-22T12:00:00+00:00', $shaped['updatedAt']);
}
public function test_shape_pricing_band(): void
{
$raw = [
'id' => 'pr-1',
'name' => 'Fair Credit',
'nameAr' => 'ائتمان جيد',
'ruleType' => 'creditScoreBand',
'minValue' => 550,
'maxValue' => 649,
'profitRate' => 8.75,
'rateType' => 'fixed',
'margin' => 1.5,
'processingFee' => 0.75,
];
$shaped = $this->agg->shapePricingBand($raw);
$this->assertSame('pr-1', $shaped['id']);
$this->assertSame('Fair Credit', $shaped['name']);
$this->assertSame('creditScoreBand', $shaped['ruleType']);
$this->assertSame(550.0, $shaped['minValue']);
$this->assertSame(649.0, $shaped['maxValue']);
$this->assertSame(8.75, $shaped['profitRate']);
$this->assertSame('fixed', $shaped['rateType']);
$this->assertSame(1.5, $shaped['margin']);
$this->assertSame(0.75, $shaped['processingFee']);
}
public function test_shape_required_document_resolves_doc_type(): void
{
$rule = [
'id' => 'rd-1',
'applicantType' => 'individual',
'isMandatory' => true,
'documentTypeId' => 'dt-1',
'financialProductId' => 'p1',
];
$docType = [
'id' => 'dt-1',
'name' => 'Emirates ID',
'nameAr' => 'الهوية الإماراتية',
'category' => 'identity',
];
$shaped = $this->agg->shapeRequiredDocument($rule, $docType);
$this->assertSame('rd-1', $shaped['id']);
$this->assertSame('individual', $shaped['applicantType']);
$this->assertTrue($shaped['mandatory']);
$this->assertSame('Emirates ID', $shaped['documentType']['name']);
$this->assertSame('identity', $shaped['documentType']['category']);
}
public function test_shape_program_context(): void
{
$program = [
'id' => 'prog-1',
'name' => 'ADCB Salaried Personal Finance',
'nameAr' => 'التمويل الشخصي للموظفين',
'description' => 'Personal lending for salaried employees',
];
$shaped = $this->agg->shapeProgramContext($program, siblingProductCount: 4);
$this->assertSame('prog-1', $shaped['id']);
$this->assertSame('ADCB Salaried Personal Finance', $shaped['name']);
$this->assertSame('Personal lending for salaried employees', $shaped['description']);
$this->assertSame(4, $shaped['siblingProductCount']);
}
}