feat: publication IA (magazine/brief/essay) + fixes critique
Publication IA: - 4 templates (magazine, brief, essay, simple) avec CSS riche - Rewrite IA (article/exercises/tutorial/reference/mixed) - Modération avec timeout 12s + fallback safe - Quotas publish_enhance par tier (basic=2, pro=15, business=100) - Détection contenu stale (hash) - Migration DB publishedContent/publishedTemplate/publishedSourceHash Fixes: - cheerio v1.2: Element -> AnyNode (domhandler), decodeEntities cast - _isShared ajouté au type Note (champ virtuel serveur) - callout colors PDF export: extraction fonction pure testable - admin/published: guard note.userId null - Cmd+S fonctionne en mode dialog (pas seulement fullPage) i18n: - 23 clés publish* traduites dans les 15 locales - Extension Web Clipper: 13 locales mise à jour Tests: - callout-colors.test.ts (6 tests) - note-visible-in-view.test.ts (5 tests) - entitlements.test.ts + byok-entitlements.test.ts: mock usageLog + unstubAllEnvs - 199/199 tests passent Tracker: user-stories.md sync avec sprint-status.yaml
This commit is contained in:
@@ -13,6 +13,8 @@ vi.mock('@/lib/prisma', () => ({
|
||||
prisma: {
|
||||
subscription: { findUnique: vi.fn() },
|
||||
userAPIKey: { count: vi.fn() },
|
||||
planEntitlement: { findMany: vi.fn().mockResolvedValue([]) },
|
||||
usageLog: { findMany: vi.fn().mockResolvedValue([]) },
|
||||
},
|
||||
}));
|
||||
|
||||
|
||||
42
memento-note/tests/unit/callout-colors.test.ts
Normal file
42
memento-note/tests/unit/callout-colors.test.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { describe, test, expect } from 'vitest'
|
||||
import { getCalloutColors } from '../../lib/editor/callout-colors'
|
||||
|
||||
describe('getCalloutColors', () => {
|
||||
test('returns correct colors for each known type', () => {
|
||||
expect(getCalloutColors('info')).toEqual({ bg: '#eff6ff', border: '#93c5fd' })
|
||||
expect(getCalloutColors('warning')).toEqual({ bg: '#fffbeb', border: '#fcd34d' })
|
||||
expect(getCalloutColors('tip')).toEqual({ bg: '#faf5ff', border: '#c4b5fd' })
|
||||
expect(getCalloutColors('success')).toEqual({ bg: '#f0fdf4', border: '#86efac' })
|
||||
expect(getCalloutColors('danger')).toEqual({ bg: '#fef2f2', border: '#fca5a5' })
|
||||
})
|
||||
|
||||
test('falls back to info for null', () => {
|
||||
expect(getCalloutColors(null)).toEqual({ bg: '#eff6ff', border: '#93c5fd' })
|
||||
})
|
||||
|
||||
test('falls back to info for undefined', () => {
|
||||
expect(getCalloutColors(undefined)).toEqual({ bg: '#eff6ff', border: '#93c5fd' })
|
||||
})
|
||||
|
||||
test('falls back to info for unknown type', () => {
|
||||
expect(getCalloutColors('unknown')).toEqual({ bg: '#eff6ff', border: '#93c5fd' })
|
||||
expect(getCalloutColors('')).toEqual({ bg: '#eff6ff', border: '#93c5fd' })
|
||||
})
|
||||
|
||||
test('returned object always has bg and border as strings', () => {
|
||||
const types = ['info', 'warning', 'tip', 'success', 'danger', null, undefined, 'unknown']
|
||||
for (const t of types) {
|
||||
const c = getCalloutColors(t)
|
||||
expect(typeof c.bg).toBe('string')
|
||||
expect(typeof c.border).toBe('string')
|
||||
expect(c.bg.length).toBeGreaterThan(0)
|
||||
expect(c.border.length).toBeGreaterThan(0)
|
||||
}
|
||||
})
|
||||
|
||||
test('returns consistent references for same input', () => {
|
||||
const a = getCalloutColors('info')
|
||||
const b = getCalloutColors('info')
|
||||
expect(a).toEqual(b)
|
||||
})
|
||||
})
|
||||
@@ -25,6 +25,9 @@ vi.mock('@/lib/prisma', () => ({
|
||||
planEntitlement: {
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
usageLog: {
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -44,6 +47,7 @@ function mockActiveSubscription(tier: string) {
|
||||
describe('entitlements', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
describe('canUseFeature', () => {
|
||||
|
||||
53
memento-note/tests/unit/note-visible-in-view.test.ts
Normal file
53
memento-note/tests/unit/note-visible-in-view.test.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { describe, test, expect } from 'vitest'
|
||||
|
||||
interface ViewFilterInput {
|
||||
notebookId?: string | null
|
||||
_isShared?: boolean
|
||||
}
|
||||
|
||||
type FilterParams = {
|
||||
notebook: string | null
|
||||
sharedOnly: boolean
|
||||
}
|
||||
|
||||
export function noteVisibleInCurrentView(note: ViewFilterInput, params: FilterParams): boolean {
|
||||
if (params.sharedOnly) return !!note._isShared
|
||||
if (params.notebook) return note.notebookId === params.notebook && !note._isShared
|
||||
return !note.notebookId && !note._isShared
|
||||
}
|
||||
|
||||
describe('noteVisibleInCurrentView', () => {
|
||||
const ownNote = { notebookId: 'nb1', _isShared: false }
|
||||
const sharedNote = { notebookId: null, _isShared: true }
|
||||
const orphanNote = { notebookId: null, _isShared: false }
|
||||
|
||||
test('sharedOnly=true shows only shared notes', () => {
|
||||
expect(noteVisibleInCurrentView(sharedNote, { notebook: null, sharedOnly: true })).toBe(true)
|
||||
expect(noteVisibleInCurrentView(ownNote, { notebook: null, sharedOnly: true })).toBe(false)
|
||||
expect(noteVisibleInCurrentView(orphanNote, { notebook: null, sharedOnly: true })).toBe(false)
|
||||
})
|
||||
|
||||
test('notebook filter shows only own notes in that notebook', () => {
|
||||
expect(noteVisibleInCurrentView(ownNote, { notebook: 'nb1', sharedOnly: false })).toBe(true)
|
||||
expect(noteVisibleInCurrentView(ownNote, { notebook: 'nb2', sharedOnly: false })).toBe(false)
|
||||
expect(noteVisibleInCurrentView(sharedNote, { notebook: 'nb1', sharedOnly: false })).toBe(false)
|
||||
})
|
||||
|
||||
test('no filter shows only orphan notes (no notebook, not shared)', () => {
|
||||
expect(noteVisibleInCurrentView(orphanNote, { notebook: null, sharedOnly: false })).toBe(true)
|
||||
expect(noteVisibleInCurrentView(ownNote, { notebook: null, sharedOnly: false })).toBe(false)
|
||||
expect(noteVisibleInCurrentView(sharedNote, { notebook: null, sharedOnly: false })).toBe(false)
|
||||
})
|
||||
|
||||
test('_isShared undefined is treated as false', () => {
|
||||
const noSharedField = { notebookId: null }
|
||||
expect(noteVisibleInCurrentView(noSharedField, { notebook: null, sharedOnly: false })).toBe(true)
|
||||
expect(noteVisibleInCurrentView(noSharedField, { notebook: null, sharedOnly: true })).toBe(false)
|
||||
})
|
||||
|
||||
test('moving a note to null notebook keeps it visible in default view', () => {
|
||||
const moved = { ...ownNote, notebookId: null }
|
||||
expect(noteVisibleInCurrentView(moved, { notebook: null, sharedOnly: false })).toBe(true)
|
||||
expect(noteVisibleInCurrentView(moved, { notebook: 'nb1', sharedOnly: false })).toBe(false)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user