From 159e4a4cbf7a85b4ac27f9ec502c5f118430c2e9 Mon Sep 17 00:00:00 2001 From: devops Date: Tue, 20 Oct 2026 07:52:07 +0000 Subject: [PATCH] fix(blog): separate Canina author and editorial team --- .../app/blog/[slug]/blog-slug-page.test.tsx | 14 +++++++------- frontend/application/app/blog/blog-page.test.tsx | 2 +- .../application/app/blog/rss.xml/route.test.ts | 2 +- frontend/application/app/blog/rss.xml/route.ts | 5 +++-- .../__tests__/BlogPreviewSection.test.tsx | 3 ++- frontend/application/lib/blogAuthor.ts | 6 ++++-- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/frontend/application/app/blog/[slug]/blog-slug-page.test.tsx b/frontend/application/app/blog/[slug]/blog-slug-page.test.tsx index 1beeb247..3ae90e4a 100644 --- a/frontend/application/app/blog/[slug]/blog-slug-page.test.tsx +++ b/frontend/application/app/blog/[slug]/blog-slug-page.test.tsx @@ -79,7 +79,7 @@ describe('BlogPostPage FAQPage Schema injection (SEO-P1-07)', () => { it('omits dateModified for invalid technical updates and uses matching Organization fallback author', async () => { vi.stubGlobal('fetch', vi.fn().mockResolvedValue({ok:true,json:async()=>({slug:'fresh',title:'Fresh',content:'

x

',publishedAt:'2026-01-01T01:00:00Z',contentUpdatedAt:'2026-01-01T12:00:00Z'})})); - const jsx=await BlogPostPage({params:Promise.resolve({slug:'fresh'})}); const script:any=React.Children.toArray(jsx.props.children)[0]; const json=JSON.parse(script.props.dangerouslySetInnerHTML.__html); expect(json.dateModified).toBeUndefined(); expect(json.author['@type']).toBe('Organization'); expect(json.author.name).toBe('تیم پژوهش و محتوای علمی کنینا'); + const jsx=await BlogPostPage({params:Promise.resolve({slug:'fresh'})}); const script:any=React.Children.toArray(jsx.props.children)[0]; const json=JSON.parse(script.props.dangerouslySetInnerHTML.__html); expect(json.dateModified).toBeUndefined(); expect(json.author['@type']).toBe('Organization'); expect(json.author.name).toBe('کنینا'); }); it('uses the stable Organization fallback visibly and in metadata', async () => { @@ -88,16 +88,16 @@ describe('BlogPostPage FAQPage Schema injection (SEO-P1-07)', () => { }) })); const metadata = await generateMetadata({ params: Promise.resolve({ slug: 'authorless' }) }); - expect((metadata.openGraph as any)?.authors).toEqual(['تیم پژوهش و محتوای علمی کنینا']); + expect((metadata.openGraph as any)?.authors).toEqual(['کنینا']); const jsx = await BlogPostPage({ params: Promise.resolve({ slug: 'authorless' }) }); const children = React.Children.toArray(jsx.props.children) as any[]; const client = children.find((child) => child?.props?.authorName); - expect(client.props.authorName).toBe('تیم پژوهش و محتوای علمی کنینا'); + expect(client.props.authorName).toBe('کنینا'); const article = JSON.parse(children[0].props.dangerouslySetInnerHTML.__html); expect(article.author).toMatchObject({ '@type': 'Organization', - name: 'تیم پژوهش و محتوای علمی کنینا', + name: 'کنینا', }); }); @@ -113,15 +113,15 @@ describe('BlogPostPage FAQPage Schema injection (SEO-P1-07)', () => { }) })); const metadata = await generateMetadata({ params: Promise.resolve({ slug: 'custom-team' }) }); - expect((metadata.openGraph as any)?.authors).toEqual([organizationName]); + expect((metadata.openGraph as any)?.authors).toEqual(['کنینا']); const jsx = await BlogPostPage({ params: Promise.resolve({ slug: 'custom-team' }) }); const children = React.Children.toArray(jsx.props.children) as any[]; const article = JSON.parse(children[0].props.dangerouslySetInnerHTML.__html); - expect(article.author).toMatchObject({ '@type': 'Organization', name: organizationName }); + expect(article.author).toMatchObject({ '@type': 'Organization', name: 'کنینا' }); const html = renderToStaticMarkup(jsx); - expect(html).toContain(`نویسنده: ${organizationName}`); + expect(html).toContain('نویسنده: کنینا'); expect(html).toContain(`تیم: ${organizationName}`); }); diff --git a/frontend/application/app/blog/blog-page.test.tsx b/frontend/application/app/blog/blog-page.test.tsx index 8e3a2ce3..92ca62a1 100644 --- a/frontend/application/app/blog/blog-page.test.tsx +++ b/frontend/application/app/blog/blog-page.test.tsx @@ -28,6 +28,6 @@ describe("blog page author identity", () => { element.type(element.props); const props = blogPageSpy.mock.calls[0][0] as { blogs: Array<{ author: string }> }; - expect(props.blogs[0].author).toBe("تیم پژوهش و محتوای علمی کنینا"); + expect(props.blogs[0].author).toBe("کنینا"); }); }); diff --git a/frontend/application/app/blog/rss.xml/route.test.ts b/frontend/application/app/blog/rss.xml/route.test.ts index 258e53f8..73241448 100644 --- a/frontend/application/app/blog/rss.xml/route.test.ts +++ b/frontend/application/app/blog/rss.xml/route.test.ts @@ -1,4 +1,4 @@ import { afterEach,describe,expect,it,vi } from "vitest"; import { GET } from "./route"; afterEach(()=>{vi.unstubAllGlobals();vi.unstubAllEnvs()}); -describe("blog RSS dates",()=>{it("keeps pubDate immutable and derives lastBuildDate from real valid dates",async()=>{vi.stubEnv("NEXT_PUBLIC_SITE_URL","https://canina.ir");vi.stubGlobal("fetch",vi.fn().mockResolvedValue({ok:true,json:async()=>({data:[{slug:"a",title:"A",status:"PUBLISHED",publishedAt:"2026-01-01T00:00:00Z",contentUpdatedAt:"2026-01-03T00:00:00Z",updatedAt:"2026-01-04T00:00:00Z"}]})}));const xml=await (await GET()).text();expect(xml).toContain(`${new Date("2026-01-01T00:00:00Z").toUTCString()}`);expect(xml).toContain(`${new Date("2026-01-03T00:00:00Z").toUTCString()}`);});it("uses the stable fallback author for authorless posts",async()=>{vi.stubGlobal("fetch",vi.fn().mockResolvedValue({ok:true,json:async()=>({data:[{slug:"a",title:"A",status:"PUBLISHED",publishedAt:"2026-01-01T00:00:00Z",author:{firstName:"",lastName:""}}]})}));const xml=await (await GET()).text();expect(xml).toContain("تیم پژوهش و محتوای علمی کنینا");});}); +describe("blog RSS dates",()=>{it("keeps pubDate immutable and derives lastBuildDate from real valid dates",async()=>{vi.stubEnv("NEXT_PUBLIC_SITE_URL","https://canina.ir");vi.stubGlobal("fetch",vi.fn().mockResolvedValue({ok:true,json:async()=>({data:[{slug:"a",title:"A",status:"PUBLISHED",publishedAt:"2026-01-01T00:00:00Z",contentUpdatedAt:"2026-01-03T00:00:00Z",updatedAt:"2026-01-04T00:00:00Z"}]})}));const xml=await (await GET()).text();expect(xml).toContain(`${new Date("2026-01-01T00:00:00Z").toUTCString()}`);expect(xml).toContain(`${new Date("2026-01-03T00:00:00Z").toUTCString()}`);});it("uses the stable fallback author for authorless posts",async()=>{vi.stubGlobal("fetch",vi.fn().mockResolvedValue({ok:true,json:async()=>({data:[{slug:"a",title:"A",status:"PUBLISHED",publishedAt:"2026-01-01T00:00:00Z",author:{firstName:"",lastName:""}}]})}));const xml=await (await GET()).text();expect(xml).toContain("کنینا");});}); diff --git a/frontend/application/app/blog/rss.xml/route.ts b/frontend/application/app/blog/rss.xml/route.ts index dce545f1..76c5153f 100644 --- a/frontend/application/app/blog/rss.xml/route.ts +++ b/frontend/application/app/blog/rss.xml/route.ts @@ -1,4 +1,5 @@ -import { BLOG_TEAM_FALLBACK, validContentUpdatedAt, publicationDate } from '../../../lib/blogDates'; +import { validContentUpdatedAt, publicationDate } from '../../../lib/blogDates'; +import { BLOG_AUTHOR_FALLBACK } from '../../../lib/blogAuthor'; import { NextResponse } from 'next/server'; export const dynamic = 'force-dynamic'; @@ -26,7 +27,7 @@ export async function GET() { const description = escapeXml(b.excerpt || b.metaDescription || ''); const pubDate = new Date(publicationDate(b)!).toUTCString(); const personName = b.author ? `${b.author.firstName || ''} ${b.author.lastName || ''}`.trim() : ''; - const author = escapeXml(personName || BLOG_TEAM_FALLBACK); + const author = escapeXml(personName || BLOG_AUTHOR_FALLBACK); const category = escapeXml(b.category?.name || 'دانشنامه سلامت حیوانات'); return ` diff --git a/frontend/application/components/__tests__/BlogPreviewSection.test.tsx b/frontend/application/components/__tests__/BlogPreviewSection.test.tsx index 219d3f4a..77b1191e 100644 --- a/frontend/application/components/__tests__/BlogPreviewSection.test.tsx +++ b/frontend/application/components/__tests__/BlogPreviewSection.test.tsx @@ -112,7 +112,8 @@ describe("BlogPreviewSection Component", () => { // Author display expect(screen.getByText("نویسنده: دکتر مریم اکبری")).toBeInTheDocument(); // Default fallback author - expect(screen.getByText("نویسنده: تیم پژوهش و محتوای علمی کنینا")).toBeInTheDocument(); + expect(screen.getByText("نویسنده: کنینا")).toBeInTheDocument(); + expect(screen.getAllByText("تیم: تیم پژوهش و محتوای علمی کنینا")).toHaveLength(2); // Verify aria-label links with full title context const link1 = screen.getByLabelText("مطالعه مقاله: اهمیت کلسیم و مفاصل در رشد توله سگ ژرمن شپرد"); diff --git a/frontend/application/lib/blogAuthor.ts b/frontend/application/lib/blogAuthor.ts index c485580c..dad45cb9 100644 --- a/frontend/application/lib/blogAuthor.ts +++ b/frontend/application/lib/blogAuthor.ts @@ -1,5 +1,7 @@ import { BLOG_TEAM_FALLBACK } from './blogDates'; +export const BLOG_AUTHOR_FALLBACK = 'کنینا'; + type BlogAuthor = { firstName?: string | null; lastName?: string | null; @@ -20,7 +22,7 @@ export function resolveBlogAuthor(author?: BlogAuthor | null): string { const name = author ? `${author.firstName || ''} ${author.lastName || ''}`.trim() : ''; - return name || BLOG_TEAM_FALLBACK; + return name || BLOG_AUTHOR_FALLBACK; } export function resolveBlogAuthorIdentity(blog: BlogAuthorInput): ResolvedBlogAuthor { @@ -33,5 +35,5 @@ export function resolveBlogAuthorIdentity(blog: BlogAuthorInput): ResolvedBlogAu return { type: 'Person', name: personName, teamName }; } - return { type: 'Organization', name: teamName, teamName }; + return { type: 'Organization', name: BLOG_AUTHOR_FALLBACK, teamName }; }