@prenta/admin 1.14.0 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/__tests__/lib/api.test.d.ts +2 -0
- package/dist/__tests__/lib/api.test.d.ts.map +1 -0
- package/dist/__tests__/lib/api.test.js +58 -0
- package/dist/__tests__/lib/api.test.js.map +1 -0
- package/dist/__tests__/lib/seo-service-autopilot.test.d.ts +2 -0
- package/dist/__tests__/lib/seo-service-autopilot.test.d.ts.map +1 -0
- package/dist/__tests__/lib/seo-service-autopilot.test.js +171 -0
- package/dist/__tests__/lib/seo-service-autopilot.test.js.map +1 -0
- package/dist/__tests__/lib/seo-service-proposals.test.js +28 -0
- package/dist/__tests__/lib/seo-service-proposals.test.js.map +1 -1
- package/dist/__tests__/views/redirects-pane.render.test.js +30 -12
- package/dist/__tests__/views/redirects-pane.render.test.js.map +1 -1
- package/dist/__tests__/views/seo-autopilot-applied.render.test.d.ts +2 -0
- package/dist/__tests__/views/seo-autopilot-applied.render.test.d.ts.map +1 -0
- package/dist/__tests__/views/seo-autopilot-applied.render.test.js +330 -0
- package/dist/__tests__/views/seo-autopilot-applied.render.test.js.map +1 -0
- package/dist/__tests__/views/seo-autopilot-card.render.test.d.ts +2 -0
- package/dist/__tests__/views/seo-autopilot-card.render.test.d.ts.map +1 -0
- package/dist/__tests__/views/seo-autopilot-card.render.test.js +512 -0
- package/dist/__tests__/views/seo-autopilot-card.render.test.js.map +1 -0
- package/dist/__tests__/views/seo-proposals-tab.render.test.js +139 -0
- package/dist/__tests__/views/seo-proposals-tab.render.test.js.map +1 -1
- package/dist/__tests__/views/seo-settings.render.test.js +41 -4
- package/dist/__tests__/views/seo-settings.render.test.js.map +1 -1
- package/dist/lib/api.d.ts +13 -2
- package/dist/lib/api.d.ts.map +1 -1
- package/dist/lib/api.js +1 -2
- package/dist/lib/api.js.map +1 -1
- package/dist/lib/seo-service.d.ts +206 -2
- package/dist/lib/seo-service.d.ts.map +1 -1
- package/dist/lib/seo-service.js +139 -5
- package/dist/lib/seo-service.js.map +1 -1
- package/dist/prenta-admin.css +1 -1
- package/dist/views/SEO.js +1 -1
- package/dist/views/SEO.js.map +1 -1
- package/dist/views/seo/AutopilotAppliedSection.d.ts +10 -0
- package/dist/views/seo/AutopilotAppliedSection.d.ts.map +1 -0
- package/dist/views/seo/AutopilotAppliedSection.js +295 -0
- package/dist/views/seo/AutopilotAppliedSection.js.map +1 -0
- package/dist/views/seo/ProposalsTab.d.ts.map +1 -1
- package/dist/views/seo/ProposalsTab.js +53 -17
- package/dist/views/seo/ProposalsTab.js.map +1 -1
- package/dist/views/seo/RedirectsTab.d.ts +3 -1
- package/dist/views/seo/RedirectsTab.d.ts.map +1 -1
- package/dist/views/seo/RedirectsTab.js +14 -19
- package/dist/views/seo/RedirectsTab.js.map +1 -1
- package/dist/views/seo/relative-age.d.ts +7 -0
- package/dist/views/seo/relative-age.d.ts.map +1 -0
- package/dist/views/seo/relative-age.js +20 -0
- package/dist/views/seo/relative-age.js.map +1 -0
- package/dist/views/settings/SeoAutopilotCard.d.ts +30 -0
- package/dist/views/settings/SeoAutopilotCard.d.ts.map +1 -0
- package/dist/views/settings/SeoAutopilotCard.js +375 -0
- package/dist/views/settings/SeoAutopilotCard.js.map +1 -0
- package/dist/views/settings/SeoSettingsTab.d.ts.map +1 -1
- package/dist/views/settings/SeoSettingsTab.js +2 -1
- package/dist/views/settings/SeoSettingsTab.js.map +1 -1
- package/dist/views/settings/components.d.ts +3 -1
- package/dist/views/settings/components.d.ts.map +1 -1
- package/dist/views/settings/components.js +2 -2
- package/dist/views/settings/components.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/lib/api.test.ts +76 -0
- package/src/__tests__/lib/seo-service-autopilot.test.ts +196 -0
- package/src/__tests__/lib/seo-service-proposals.test.ts +29 -0
- package/src/__tests__/views/redirects-pane.render.test.tsx +36 -16
- package/src/__tests__/views/seo-autopilot-applied.render.test.tsx +382 -0
- package/src/__tests__/views/seo-autopilot-card.render.test.tsx +610 -0
- package/src/__tests__/views/seo-proposals-tab.render.test.tsx +161 -0
- package/src/__tests__/views/seo-settings.render.test.tsx +47 -7
- package/src/lib/api.ts +19 -3
- package/src/lib/seo-service.ts +334 -6
- package/src/views/SEO.tsx +1 -1
- package/src/views/seo/AutopilotAppliedSection.tsx +597 -0
- package/src/views/seo/ProposalsTab.tsx +92 -12
- package/src/views/seo/RedirectsTab.tsx +39 -60
- package/src/views/seo/relative-age.ts +15 -0
- package/src/views/settings/SeoAutopilotCard.tsx +826 -0
- package/src/views/settings/SeoSettingsTab.tsx +2 -0
- package/src/views/settings/components.tsx +10 -1
|
@@ -3,6 +3,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
3
3
|
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
4
4
|
|
|
5
5
|
import type {
|
|
6
|
+
SeoAutoApplyList,
|
|
6
7
|
SeoProposal,
|
|
7
8
|
SeoProposalBulkApplyResult,
|
|
8
9
|
SeoProposalsPayload,
|
|
@@ -57,11 +58,24 @@ function payload(over: Partial<SeoProposalsPayload> = {}): SeoProposalsPayload {
|
|
|
57
58
|
],
|
|
58
59
|
counts: { issueFixes: 2, redirects: 1, stale: 0, eligibleForGeneration: 5 },
|
|
59
60
|
governance: { issueFixBulk: true, redirectBulk: true },
|
|
61
|
+
autopilot: { enabled: false, pausedReason: null, lastRunAt: null, appliedLast7d: 0 },
|
|
60
62
|
...over,
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
const fetchSeoProposals = vi.fn(async () => payload())
|
|
67
|
+
const fetchAutopilotApplied = vi.fn(
|
|
68
|
+
async (_params: unknown): Promise<SeoAutoApplyList> => ({
|
|
69
|
+
docs: [],
|
|
70
|
+
total: 0,
|
|
71
|
+
page: 1,
|
|
72
|
+
pageSize: 20,
|
|
73
|
+
canRevert: false,
|
|
74
|
+
}),
|
|
75
|
+
)
|
|
76
|
+
const revertAutopilotChange = vi.fn(async (_id: string, _force?: boolean) => ({
|
|
77
|
+
ok: true as const,
|
|
78
|
+
}))
|
|
65
79
|
const generateSeoProposals = vi.fn(async () => ({
|
|
66
80
|
result: { generated: 2, skipped: 0, failed: 0, remaining: 0, haltedReason: null },
|
|
67
81
|
}))
|
|
@@ -79,6 +93,8 @@ vi.mock('../../lib/seo-service.js', () => ({
|
|
|
79
93
|
bulkApplySeoProposals: (items: unknown) => bulkApplySeoProposals(items),
|
|
80
94
|
dismissSeoIssueFix: (id: string) => dismissSeoIssueFix(id),
|
|
81
95
|
dismissRedirectSuggestion: (id: string) => dismissRedirectSuggestion(id),
|
|
96
|
+
fetchAutopilotApplied: (params: unknown) => fetchAutopilotApplied(params),
|
|
97
|
+
revertAutopilotChange: (id: string, force?: boolean) => revertAutopilotChange(id, force),
|
|
82
98
|
}))
|
|
83
99
|
vi.mock('sonner', () => ({
|
|
84
100
|
toast: { success: vi.fn(), error: vi.fn(), info: vi.fn(), loading: vi.fn() },
|
|
@@ -109,6 +125,8 @@ beforeEach(() => {
|
|
|
109
125
|
bulkApplySeoProposals.mockClear()
|
|
110
126
|
dismissSeoIssueFix.mockClear()
|
|
111
127
|
dismissRedirectSuggestion.mockClear()
|
|
128
|
+
fetchAutopilotApplied.mockClear()
|
|
129
|
+
revertAutopilotChange.mockClear()
|
|
112
130
|
vi.mocked(toast.success).mockClear()
|
|
113
131
|
vi.mocked(toast.error).mockClear()
|
|
114
132
|
})
|
|
@@ -361,6 +379,149 @@ describe('ProposalsTab', () => {
|
|
|
361
379
|
)
|
|
362
380
|
})
|
|
363
381
|
|
|
382
|
+
it('renders the applied-by-autopilot section under the proposals card', async () => {
|
|
383
|
+
render(<ProposalsTab planInfo={null} />)
|
|
384
|
+
await screen.findByText('Duplicate meta title')
|
|
385
|
+
expect(await screen.findByText('Applied by autopilot')).toBeTruthy()
|
|
386
|
+
await waitFor(() => expect(fetchAutopilotApplied).toHaveBeenCalledTimes(1))
|
|
387
|
+
expect(await screen.findByText('Autopilot has not applied anything yet')).toBeTruthy()
|
|
388
|
+
})
|
|
389
|
+
|
|
390
|
+
it('shows no autopilot chip while autopilot is disabled', async () => {
|
|
391
|
+
render(<ProposalsTab planInfo={null} />)
|
|
392
|
+
await screen.findByText('Duplicate meta title')
|
|
393
|
+
expect(screen.queryByRole('button', { name: /autopilot (on|paused)/i })).toBeNull()
|
|
394
|
+
})
|
|
395
|
+
|
|
396
|
+
it('shows an "Autopilot on" chip with the weekly count that opens SEO settings', async () => {
|
|
397
|
+
fetchSeoProposals.mockImplementationOnce(async () =>
|
|
398
|
+
payload({
|
|
399
|
+
autopilot: {
|
|
400
|
+
enabled: true,
|
|
401
|
+
pausedReason: null,
|
|
402
|
+
lastRunAt: '2026-09-07T03:00:00.000Z',
|
|
403
|
+
appliedLast7d: 4,
|
|
404
|
+
},
|
|
405
|
+
}),
|
|
406
|
+
)
|
|
407
|
+
const onNavigate = vi.fn()
|
|
408
|
+
render(<ProposalsTab planInfo={null} onNavigate={onNavigate} />)
|
|
409
|
+
await screen.findByText('Duplicate meta title')
|
|
410
|
+
const chip = screen.getByRole('button', { name: 'Autopilot on · 4 applied this week' })
|
|
411
|
+
fireEvent.click(chip)
|
|
412
|
+
expect(onNavigate).toHaveBeenCalledWith('/settings?tab=seo')
|
|
413
|
+
})
|
|
414
|
+
|
|
415
|
+
it('shows a paused chip with a short reason when autopilot is paused', async () => {
|
|
416
|
+
fetchSeoProposals.mockImplementationOnce(async () =>
|
|
417
|
+
payload({
|
|
418
|
+
autopilot: {
|
|
419
|
+
enabled: true,
|
|
420
|
+
pausedReason: 'outcome_regression',
|
|
421
|
+
lastRunAt: null,
|
|
422
|
+
appliedLast7d: 1,
|
|
423
|
+
},
|
|
424
|
+
}),
|
|
425
|
+
)
|
|
426
|
+
render(<ProposalsTab planInfo={null} />)
|
|
427
|
+
await screen.findByText('Duplicate meta title')
|
|
428
|
+
expect(
|
|
429
|
+
screen.getByRole('button', { name: 'Autopilot paused — traffic regression' }),
|
|
430
|
+
).toBeTruthy()
|
|
431
|
+
expect(screen.queryByRole('button', { name: /applied this week/ })).toBeNull()
|
|
432
|
+
})
|
|
433
|
+
|
|
434
|
+
it.each([
|
|
435
|
+
['owner_unavailable', 'Autopilot paused — owner unavailable'],
|
|
436
|
+
['manual', 'Autopilot paused — paused by admin'],
|
|
437
|
+
['some_future_reason', 'Autopilot paused — some_future_reason'],
|
|
438
|
+
])('labels the %s pause reason as "%s"', async (pausedReason, name) => {
|
|
439
|
+
fetchSeoProposals.mockImplementationOnce(async () =>
|
|
440
|
+
payload({ autopilot: { enabled: true, pausedReason, lastRunAt: null, appliedLast7d: 0 } }),
|
|
441
|
+
)
|
|
442
|
+
render(<ProposalsTab planInfo={null} />)
|
|
443
|
+
await screen.findByText('Duplicate meta title')
|
|
444
|
+
expect(screen.getByRole('button', { name })).toBeTruthy()
|
|
445
|
+
})
|
|
446
|
+
|
|
447
|
+
it('shows no chip when autopilot was disabled while still paused', async () => {
|
|
448
|
+
// `PUT { enabled: false }` does not clear the pause; a disabled engine is
|
|
449
|
+
// simply off, not "paused".
|
|
450
|
+
fetchSeoProposals.mockImplementationOnce(async () =>
|
|
451
|
+
payload({
|
|
452
|
+
autopilot: { enabled: false, pausedReason: 'manual', lastRunAt: null, appliedLast7d: 0 },
|
|
453
|
+
}),
|
|
454
|
+
)
|
|
455
|
+
render(<ProposalsTab planInfo={null} />)
|
|
456
|
+
await screen.findByText('Duplicate meta title')
|
|
457
|
+
expect(screen.queryByRole('button', { name: /autopilot/i })).toBeNull()
|
|
458
|
+
})
|
|
459
|
+
|
|
460
|
+
it('shows no chip and does not throw when the payload predates autopilot', async () => {
|
|
461
|
+
fetchSeoProposals.mockImplementationOnce(async () => {
|
|
462
|
+
// A `@prenta/core` deployed before autopilot shipped omits the field entirely.
|
|
463
|
+
const legacy: Partial<SeoProposalsPayload> = payload()
|
|
464
|
+
delete legacy.autopilot
|
|
465
|
+
return legacy as SeoProposalsPayload
|
|
466
|
+
})
|
|
467
|
+
render(<ProposalsTab planInfo={null} />)
|
|
468
|
+
expect(await screen.findByText('Duplicate meta title')).toBeTruthy()
|
|
469
|
+
expect(screen.queryByRole('button', { name: /autopilot (on|paused)/i })).toBeNull()
|
|
470
|
+
expect(screen.getByRole('button', { name: 'Generate proposals (5 eligible)' })).toBeTruthy()
|
|
471
|
+
})
|
|
472
|
+
|
|
473
|
+
it('refreshes the applied section after a proposal is approved', async () => {
|
|
474
|
+
render(<ProposalsTab planInfo={null} />)
|
|
475
|
+
await screen.findByText('Duplicate meta title')
|
|
476
|
+
await waitFor(() => expect(fetchAutopilotApplied).toHaveBeenCalledTimes(1))
|
|
477
|
+
fireEvent.click(screen.getByRole('button', { name: 'Approve Duplicate meta title' }))
|
|
478
|
+
await waitFor(() => expect(bulkApplySeoProposals).toHaveBeenCalledTimes(1))
|
|
479
|
+
await waitFor(() => expect(fetchAutopilotApplied).toHaveBeenCalledTimes(2))
|
|
480
|
+
})
|
|
481
|
+
|
|
482
|
+
it('refetches the inbox and notifies the parent after an autopilot change is reverted', async () => {
|
|
483
|
+
fetchAutopilotApplied.mockImplementation(async () => ({
|
|
484
|
+
docs: [
|
|
485
|
+
{
|
|
486
|
+
id: 'la-1',
|
|
487
|
+
kind: 'issue-fix',
|
|
488
|
+
issueType: 'missing-meta-title',
|
|
489
|
+
entityId: 'd1',
|
|
490
|
+
collection: 'pages',
|
|
491
|
+
entityTitle: 'Pricing',
|
|
492
|
+
entityUrl: '/pricing',
|
|
493
|
+
path: '/pricing',
|
|
494
|
+
before: { metaTitle: null },
|
|
495
|
+
after: { metaTitle: 'Pricing for growing teams' },
|
|
496
|
+
gate: { source: 'ai', brandAlignment: 92, confidence: null, checks: {} },
|
|
497
|
+
status: 'applied',
|
|
498
|
+
outcome: 'pending',
|
|
499
|
+
outcomeMetrics: null,
|
|
500
|
+
appliedAt: new Date().toISOString(),
|
|
501
|
+
revertedAt: null,
|
|
502
|
+
revertReason: null,
|
|
503
|
+
},
|
|
504
|
+
],
|
|
505
|
+
total: 1,
|
|
506
|
+
page: 1,
|
|
507
|
+
pageSize: 20,
|
|
508
|
+
canRevert: true,
|
|
509
|
+
}))
|
|
510
|
+
const onChanged = vi.fn()
|
|
511
|
+
render(<ProposalsTab planInfo={null} onChanged={onChanged} />)
|
|
512
|
+
await screen.findByText('Duplicate meta title')
|
|
513
|
+
fireEvent.click(await screen.findByRole('button', { name: 'Revert change to Pricing' }))
|
|
514
|
+
fireEvent.click(await screen.findByRole('button', { name: 'Revert change' }))
|
|
515
|
+
await waitFor(() => expect(revertAutopilotChange).toHaveBeenCalledWith('la-1', false))
|
|
516
|
+
// The revert reopened the issue server-side: the inbox and the SEO page must both refresh.
|
|
517
|
+
await waitFor(() => expect(fetchSeoProposals).toHaveBeenCalledTimes(2))
|
|
518
|
+
await waitFor(() => expect(onChanged).toHaveBeenCalledTimes(1))
|
|
519
|
+
// The ledger reloads itself once; the parent must not bump `refreshKey` on top.
|
|
520
|
+
await waitFor(() => expect(fetchAutopilotApplied).toHaveBeenCalledTimes(2))
|
|
521
|
+
await flushMicrotasks()
|
|
522
|
+
expect(fetchAutopilotApplied).toHaveBeenCalledTimes(2)
|
|
523
|
+
})
|
|
524
|
+
|
|
364
525
|
it('hides Generate behind the plan callout when seo.inlineApply is off', async () => {
|
|
365
526
|
render(<ProposalsTab planInfo={{ tier: 'starter', features: [], upgradeUrl: null }} />)
|
|
366
527
|
await screen.findByText('Duplicate meta title')
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
3
|
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react'
|
|
4
4
|
|
|
5
|
-
// The SEO defaults tab reads
|
|
5
|
+
// The SEO defaults tab reads seven shared backends: /seo/config (meta defaults +
|
|
6
6
|
// verification), /seo/crawl-settings (sitemap toggles), /seo/sitemap/status
|
|
7
7
|
// (read-only summary), /seo/index-status (environment), /seo/search-console
|
|
8
|
-
// (Search data card),
|
|
8
|
+
// (Search data card), /seo/autopilot/settings (SEO Autopilot card), and
|
|
9
|
+
// /seo/digest-settings (Weekly SEO digest card).
|
|
9
10
|
// `defaultApi` is the per-path route map; individual tests override the mock
|
|
10
11
|
// implementation and delegate back to it for unrelated paths.
|
|
11
12
|
type MockApiResponse = { data?: unknown; error?: string; status: number }
|
|
@@ -80,6 +81,28 @@ async function defaultApi(
|
|
|
80
81
|
status: 200,
|
|
81
82
|
}
|
|
82
83
|
}
|
|
84
|
+
if (endpoint === '/seo/autopilot/settings' && method === 'GET') {
|
|
85
|
+
return {
|
|
86
|
+
data: {
|
|
87
|
+
enabled: false,
|
|
88
|
+
enabledById: null,
|
|
89
|
+
pausedAt: null,
|
|
90
|
+
pausedReason: null,
|
|
91
|
+
types: {},
|
|
92
|
+
pausedTypes: {},
|
|
93
|
+
minBrandAlignment: 85,
|
|
94
|
+
redirectMinConfidence: 85,
|
|
95
|
+
maxPerRun: 5,
|
|
96
|
+
maxPerDay: 20,
|
|
97
|
+
verifyFailuresPerRun: 2,
|
|
98
|
+
outcomeWatch: { enabled: true, days: 14, dropRatio: 0.4, minPriorClicks: 50 },
|
|
99
|
+
lastRunAt: null,
|
|
100
|
+
lastRun: null,
|
|
101
|
+
governance: { issueFixApprovalRequired: false, redirectApprovalRequired: false },
|
|
102
|
+
},
|
|
103
|
+
status: 200,
|
|
104
|
+
}
|
|
105
|
+
}
|
|
83
106
|
return { data: {}, status: 200 }
|
|
84
107
|
}
|
|
85
108
|
|
|
@@ -98,6 +121,7 @@ vi.mock('sonner', () => ({
|
|
|
98
121
|
success: (...args: unknown[]) => toastSuccess(...args),
|
|
99
122
|
error: (...args: unknown[]) => toastError(...args),
|
|
100
123
|
warning: vi.fn(),
|
|
124
|
+
info: vi.fn(),
|
|
101
125
|
loading: vi.fn(),
|
|
102
126
|
},
|
|
103
127
|
}))
|
|
@@ -331,6 +355,23 @@ describe('SeoSettingsTab', () => {
|
|
|
331
355
|
expect(body.serviceAccountKey).toContain('svc@acme.iam.gserviceaccount.com')
|
|
332
356
|
})
|
|
333
357
|
|
|
358
|
+
it('renders the SEO Autopilot card between Search data and the digest', async () => {
|
|
359
|
+
render(<SeoSettingsTab role="ADMIN" />)
|
|
360
|
+
// The title also renders in the card's skeleton state; wait for a control
|
|
361
|
+
// that only exists once the settings have loaded.
|
|
362
|
+
const toggle = await screen.findByRole('switch', { name: 'Enable autopilot' })
|
|
363
|
+
expect(toggle.getAttribute('aria-checked')).toBe('false')
|
|
364
|
+
const regions = screen
|
|
365
|
+
.getAllByRole('region')
|
|
366
|
+
.map((r) => r.getAttribute('aria-labelledby'))
|
|
367
|
+
.map((id) => (id ? document.getElementById(id)?.textContent : null))
|
|
368
|
+
const order = ['Search data', 'SEO Autopilot', 'Weekly SEO digest'].map((t) =>
|
|
369
|
+
regions.indexOf(t),
|
|
370
|
+
)
|
|
371
|
+
expect(order.every((i) => i >= 0)).toBe(true)
|
|
372
|
+
expect(order).toEqual([...order].sort((a, b) => a - b))
|
|
373
|
+
})
|
|
374
|
+
|
|
334
375
|
it('renders the Weekly SEO digest card with the toggle off by default', async () => {
|
|
335
376
|
render(<SeoSettingsTab role="ADMIN" />)
|
|
336
377
|
expect(await screen.findByText('Weekly SEO digest')).toBeTruthy()
|
|
@@ -342,12 +383,13 @@ describe('SeoSettingsTab', () => {
|
|
|
342
383
|
|
|
343
384
|
it('saves recipients as a trimmed, comma-split list', async () => {
|
|
344
385
|
render(<SeoSettingsTab role="ADMIN" />)
|
|
345
|
-
|
|
386
|
+
// 'Weekly SEO digest' is also the loading-state title; wait for the form.
|
|
387
|
+
const save = await screen.findByRole('button', { name: 'Save recipients' })
|
|
346
388
|
|
|
347
389
|
fireEvent.change(screen.getByLabelText('Recipients'), {
|
|
348
390
|
target: { value: ' a@x.com , b@x.com ' },
|
|
349
391
|
})
|
|
350
|
-
fireEvent.click(
|
|
392
|
+
fireEvent.click(save)
|
|
351
393
|
|
|
352
394
|
await waitFor(() =>
|
|
353
395
|
expect(cmsApi).toHaveBeenCalledWith(
|
|
@@ -370,9 +412,7 @@ describe('SeoSettingsTab', () => {
|
|
|
370
412
|
return defaultApi(endpoint, options)
|
|
371
413
|
})
|
|
372
414
|
render(<SeoSettingsTab role="ADMIN" />)
|
|
373
|
-
await screen.
|
|
374
|
-
|
|
375
|
-
fireEvent.click(screen.getByRole('button', { name: /Send test digest/ }))
|
|
415
|
+
fireEvent.click(await screen.findByRole('button', { name: /Send test digest/ }))
|
|
376
416
|
|
|
377
417
|
await waitFor(() =>
|
|
378
418
|
expect(toastError).toHaveBeenCalledWith('No completed SEO audit yet — run an audit first'),
|
package/src/lib/api.ts
CHANGED
|
@@ -62,10 +62,27 @@ function appendLocaleParam(endpoint: string): string {
|
|
|
62
62
|
return `${endpoint}${separator}locale=${encodeURIComponent(locale)}`
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
export interface CmsApiResult<T> {
|
|
66
|
+
data?: T
|
|
67
|
+
error?: string
|
|
68
|
+
/**
|
|
69
|
+
* Machine-readable error discriminator (e.g. IP_LOCKOUT_RISK, conflict) set
|
|
70
|
+
* by guard responses so callers can branch without parsing the message.
|
|
71
|
+
*/
|
|
72
|
+
code?: string
|
|
73
|
+
/**
|
|
74
|
+
* The parsed non-2xx body, for the few endpoints that return structured
|
|
75
|
+
* detail beyond `error` / `code` (e.g. the 409 `fields` list from
|
|
76
|
+
* `/seo/autopilot/applied/:id/revert`). Callers must narrow it themselves.
|
|
77
|
+
*/
|
|
78
|
+
errorBody?: unknown
|
|
79
|
+
status: number
|
|
80
|
+
}
|
|
81
|
+
|
|
65
82
|
export async function cmsApi<T = unknown>(
|
|
66
83
|
endpoint: string,
|
|
67
84
|
options: RequestInit = {},
|
|
68
|
-
): Promise<
|
|
85
|
+
): Promise<CmsApiResult<T>> {
|
|
69
86
|
const url = `${basePath}${appendLocaleParam(endpoint)}`
|
|
70
87
|
const isFormData = typeof FormData !== 'undefined' && options.body instanceof FormData
|
|
71
88
|
|
|
@@ -98,9 +115,8 @@ export async function cmsApi<T = unknown>(
|
|
|
98
115
|
if (!res.ok) {
|
|
99
116
|
return {
|
|
100
117
|
error: json.error || `Request failed (${res.status})`,
|
|
101
|
-
// Machine-readable error discriminator (e.g. IP_LOCKOUT_RISK) set by
|
|
102
|
-
// guard responses so callers can branch without parsing the message.
|
|
103
118
|
code: typeof json.code === 'string' ? json.code : undefined,
|
|
119
|
+
errorBody: json,
|
|
104
120
|
status: res.status,
|
|
105
121
|
}
|
|
106
122
|
}
|