chore: remediate CI blockers for production readiness

This commit is contained in:
Ho Ngoc Hai
2026-05-07 13:08:20 +07:00
parent f82806e06d
commit b35ec55126
32 changed files with 401 additions and 113 deletions

View File

@@ -15,6 +15,13 @@ vi.mock('next/link', () => ({
),
}));
// Mock locale-aware navigation links
vi.mock('@/i18n/navigation', () => ({
Link: ({ children, href }: { children: React.ReactNode; href: string }) => (
<a href={href}>{children}</a>
),
}));
// Mock next/dynamic to render children directly
vi.mock('next/dynamic', () => ({
default: () => {

View File

@@ -1,7 +1,6 @@
'use client';
import dynamic from 'next/dynamic';
import Link from 'next/link';
import * as React from 'react';
import { AddToCompareButton } from '@/components/comparison/add-to-compare-button';
import { AiAdviceCards } from '@/components/listings/ai-advice-cards';
@@ -16,6 +15,7 @@ import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { AiEstimateButton } from '@/components/valuation/ai-estimate-button';
import { Link } from '@/i18n/navigation';
import { analyticsApi, type NearbyPOI } from '@/lib/analytics-api';
import { formatPrice, formatPricePerM2 } from '@/lib/currency';
import { composeWhyThisLocation, derivePersonas } from '@/lib/listing-personas';

View File

@@ -132,6 +132,32 @@ describe('CheckoutModal', () => {
provider: 'VNPAY',
type: 'SUBSCRIPTION',
amountVND: 499000,
returnUrl: 'http://localhost:3000/vi/payment/return',
}),
);
});
});
it('uses the locale root payment return route from dashboard checkout', async () => {
Object.defineProperty(window, 'location', {
writable: true,
value: {
...window.location,
href: 'http://localhost:3000/vi/dashboard/subscription',
origin: 'http://localhost:3000',
pathname: '/vi/dashboard/subscription',
},
});
render(
<CheckoutModal open={true} onOpenChange={onOpenChange} plan={basePlan} billingCycle="monthly" />,
);
await userEvent.click(screen.getByRole('button', { name: /thanh toán/i }));
await waitFor(() => {
expect(mockCreatePayment).toHaveBeenCalledWith(
expect.objectContaining({
returnUrl: 'http://localhost:3000/vi/payment/return',
}),
);
});

View File

@@ -120,7 +120,9 @@ function CheckoutModalInner({
}
// Step 2: Create payment and redirect to gateway
const returnUrl = `${window.location.origin}${window.location.pathname.replace(/\/pricing$/, '')}/payment/return`;
const localeMatch = window.location.pathname.match(/^\/(vi|en)(\/|$)/);
const localePrefix = localeMatch?.[1] ? `/${localeMatch[1]}` : '';
const returnUrl = `${window.location.origin}${localePrefix}/payment/return`;
const idempotencyKey = `sub-${plan.tier}-${billingCycle}-${Date.now()}`;