fix(blog): separate Canina author and editorial team
Deploy Canina / deploy (push) Successful in 2m47s

This commit is contained in:
devops committed 2026-10-20 07:52:07 +00:00
1 parent 13a7919c91
commit 159e4a4cbf
6 files changed
+18 -14

No files matched your search

@@ -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:'<p>x</p>',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}`);
});
@@ -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("کنینا");
});
});
@@ -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(`<pubDate>${new Date("2026-01-01T00:00:00Z").toUTCString()}</pubDate>`);expect(xml).toContain(`<lastBuildDate>${new Date("2026-01-03T00:00:00Z").toUTCString()}</lastBuildDate>`);});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("<author>تیم پژوهش و محتوای علمی کنینا</author>");});});
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(`<pubDate>${new Date("2026-01-01T00:00:00Z").toUTCString()}</pubDate>`);expect(xml).toContain(`<lastBuildDate>${new Date("2026-01-03T00:00:00Z").toUTCString()}</lastBuildDate>`);});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("<author>کنینا</author>");});});
@@ -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 `