fix: 5 bugs critiques de l'éditeur (Phase 1 audit)
1. replaceAll (Find & Replace) — une seule transaction ProseMirror au lieu d'un forEach cassé. Tous les matchs sont maintenant remplacés. 2. Link Preview unwrap — deleteNode() au lieu de clearer les attrs qui laissaient un nœud fantôme invisible dans le document. 3. Conversion Markdown → richtext — breaks: true dans marked.parse() Les simple newlines sont maintenant convertis en <br>. + préserve les blocs custom (toggle, callout, math, columns, outline, link-preview) en commentaires HTML lors de l'export MD. 4. emitNoteChange exercices — shape corrigée (type:'created' attend un objet Note, pas noteId/notebookId séparés). 5. Raccourcis clavier sans conflit : Cmd+Shift+C → Cmd+Alt+C (callout, avant: copier) Cmd+Shift+O → Cmd+Alt+O (outline, avant: historique/signets) Cmd+Shift+L → Cmd+Alt+L (colonnes, avant: lock screen macOS)
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
||||
import { resolvePriceId, priceIdToTier } from '@/lib/billing/stripe-prices';
|
||||
|
||||
vi.mock('@/lib/prisma', () => ({
|
||||
default: {
|
||||
systemConfig: {
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
describe('billing-price-map', () => {
|
||||
const originalEnv = process.env;
|
||||
|
||||
@@ -19,55 +27,55 @@ describe('billing-price-map', () => {
|
||||
});
|
||||
|
||||
describe('resolvePriceId', () => {
|
||||
it('returns PRO monthly price ID', () => {
|
||||
expect(resolvePriceId('PRO', 'month')).toBe('price_pro_monthly_test');
|
||||
it('returns PRO monthly price ID', async () => {
|
||||
expect(await resolvePriceId('PRO', 'month')).toBe('price_pro_monthly_test');
|
||||
});
|
||||
|
||||
it('returns PRO annual price ID', () => {
|
||||
expect(resolvePriceId('PRO', 'year')).toBe('price_pro_annual_test');
|
||||
it('returns PRO annual price ID', async () => {
|
||||
expect(await resolvePriceId('PRO', 'year')).toBe('price_pro_annual_test');
|
||||
});
|
||||
|
||||
it('returns BUSINESS monthly price ID', () => {
|
||||
expect(resolvePriceId('BUSINESS', 'month')).toBe('price_business_monthly_test');
|
||||
it('returns BUSINESS monthly price ID', async () => {
|
||||
expect(await resolvePriceId('BUSINESS', 'month')).toBe('price_business_monthly_test');
|
||||
});
|
||||
|
||||
it('returns BUSINESS annual price ID', () => {
|
||||
expect(resolvePriceId('BUSINESS', 'year')).toBe('price_business_annual_test');
|
||||
it('returns BUSINESS annual price ID', async () => {
|
||||
expect(await resolvePriceId('BUSINESS', 'year')).toBe('price_business_annual_test');
|
||||
});
|
||||
|
||||
it('throws if env variable is not set', () => {
|
||||
it('throws if env variable is not set', async () => {
|
||||
delete process.env.STRIPE_PRICE_PRO_MONTHLY;
|
||||
expect(() => resolvePriceId('PRO', 'month')).toThrow();
|
||||
await expect(resolvePriceId('PRO', 'month')).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('priceIdToTier', () => {
|
||||
it('resolves PRO monthly price ID to PRO tier', () => {
|
||||
expect(priceIdToTier('price_pro_monthly_test')).toBe('PRO');
|
||||
it('resolves PRO monthly price ID to PRO tier', async () => {
|
||||
expect(await priceIdToTier('price_pro_monthly_test')).toBe('PRO');
|
||||
});
|
||||
|
||||
it('resolves PRO annual price ID to PRO tier', () => {
|
||||
expect(priceIdToTier('price_pro_annual_test')).toBe('PRO');
|
||||
it('resolves PRO annual price ID to PRO tier', async () => {
|
||||
expect(await priceIdToTier('price_pro_annual_test')).toBe('PRO');
|
||||
});
|
||||
|
||||
it('resolves BUSINESS monthly price ID to BUSINESS tier', () => {
|
||||
expect(priceIdToTier('price_business_monthly_test')).toBe('BUSINESS');
|
||||
it('resolves BUSINESS monthly price ID to BUSINESS tier', async () => {
|
||||
expect(await priceIdToTier('price_business_monthly_test')).toBe('BUSINESS');
|
||||
});
|
||||
|
||||
it('resolves BUSINESS annual price ID to BUSINESS tier', () => {
|
||||
expect(priceIdToTier('price_business_annual_test')).toBe('BUSINESS');
|
||||
it('resolves BUSINESS annual price ID to BUSINESS tier', async () => {
|
||||
expect(await priceIdToTier('price_business_annual_test')).toBe('BUSINESS');
|
||||
});
|
||||
|
||||
it('returns null for unknown price ID', () => {
|
||||
expect(priceIdToTier('price_unknown_xyz')).toBeNull();
|
||||
it('returns null for unknown price ID', async () => {
|
||||
expect(await priceIdToTier('price_unknown_xyz')).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null when env variables are not set', () => {
|
||||
it('returns null when env variables are not set', async () => {
|
||||
delete process.env.STRIPE_PRICE_PRO_MONTHLY;
|
||||
delete process.env.STRIPE_PRICE_PRO_ANNUAL;
|
||||
delete process.env.STRIPE_PRICE_BUSINESS_MONTHLY;
|
||||
delete process.env.STRIPE_PRICE_BUSINESS_ANNUAL;
|
||||
expect(priceIdToTier('price_pro_monthly_test')).toBeNull();
|
||||
expect(await priceIdToTier('price_pro_monthly_test')).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,6 +22,9 @@ vi.mock('@/lib/prisma', () => ({
|
||||
subscription: {
|
||||
findUnique: vi.fn(),
|
||||
},
|
||||
planEntitlement: {
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user