Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf3334878a |
No files matched your search
@@ -274,6 +274,42 @@ describe("Admin BlogsService", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("explicit author contract", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mockPrisma.blog.create.mockResolvedValue({ id: "b1", slug: "post" });
|
||||||
|
mockPrisma.blog.findUnique.mockResolvedValue({ id: "b1", slug: "post" });
|
||||||
|
mockPrisma.blog.update.mockResolvedValue({ id: "b1", slug: "post" });
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
["omitted", {}, { connect: { id: "current-user" } }],
|
||||||
|
["legacy empty", { authorId: "" }, { connect: { id: "current-user" } }],
|
||||||
|
["selected", { authorId: "selected-user" }, { connect: { id: "selected-user" } }],
|
||||||
|
["authorless", { authorId: null }, undefined],
|
||||||
|
])("creates with %s author without inventing an identity", async (_label, input, expected) => {
|
||||||
|
await service.createBlog({ title: "Post", slug: "post", content: "Content", ...input }, "current-user");
|
||||||
|
const payload = mockPrisma.blog.create.mock.calls[0][0].data;
|
||||||
|
expect(payload.author).toEqual(expected);
|
||||||
|
if (expected === undefined) expect(payload).not.toHaveProperty("author");
|
||||||
|
expect(payload).not.toHaveProperty("authorId");
|
||||||
|
expect(mockRevalidationService.revalidateBlog).toHaveBeenCalledWith("post");
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
["omitted", {}, undefined],
|
||||||
|
["legacy empty", { authorId: "" }, undefined],
|
||||||
|
["selected", { authorId: "selected-user" }, { connect: { id: "selected-user" } }],
|
||||||
|
["authorless", { authorId: null }, { disconnect: true }],
|
||||||
|
])("updates with %s author while preserving omitted values", async (_label, input, expected) => {
|
||||||
|
await service.updateBlog("b1", input);
|
||||||
|
const payload = mockPrisma.blog.update.mock.calls[0][0].data;
|
||||||
|
expect(payload.author).toEqual(expected);
|
||||||
|
if (expected === undefined) expect(payload).not.toHaveProperty("author");
|
||||||
|
expect(payload).not.toHaveProperty("authorId");
|
||||||
|
expect(mockRevalidationService.revalidateBlog).toHaveBeenCalledWith("post");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("updateBlog", () => {
|
describe("updateBlog", () => {
|
||||||
it("should throw NotFoundException if blog does not exist", async () => {
|
it("should throw NotFoundException if blog does not exist", async () => {
|
||||||
mockPrisma.blog.findUnique.mockResolvedValue(null);
|
mockPrisma.blog.findUnique.mockResolvedValue(null);
|
||||||
|
|||||||
@@ -185,7 +185,9 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetAuthorId = authorId || currentUserId;
|
// Explicit null requests Organization attribution; omission/legacy empty
|
||||||
|
// retains the authenticated-author default. No synthetic User is created.
|
||||||
|
const targetAuthorId = authorId === null ? null : authorId || currentUserId;
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const isFutureSchedule = parsedScheduledAt && parsedScheduledAt > now;
|
const isFutureSchedule = parsedScheduledAt && parsedScheduledAt > now;
|
||||||
|
|
||||||
@@ -239,7 +241,9 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
|||||||
publishedAt: finalPublishedAt,
|
publishedAt: finalPublishedAt,
|
||||||
scheduledAt: parsedScheduledAt,
|
scheduledAt: parsedScheduledAt,
|
||||||
contentUpdatedAt: parsedContentUpdatedAt,
|
contentUpdatedAt: parsedContentUpdatedAt,
|
||||||
author: { connect: { id: targetAuthorId } },
|
...(targetAuthorId !== null
|
||||||
|
? { author: { connect: { id: targetAuthorId } } }
|
||||||
|
: {}),
|
||||||
...(categoryId ? { category: { connect: { id: categoryId } } } : {}),
|
...(categoryId ? { category: { connect: { id: categoryId } } } : {}),
|
||||||
...(tagConnectOrCreate.length > 0
|
...(tagConnectOrCreate.length > 0
|
||||||
? { tags: { connectOrCreate: tagConnectOrCreate } }
|
? { tags: { connectOrCreate: tagConnectOrCreate } }
|
||||||
@@ -344,7 +348,12 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
|||||||
...(readingTime !== undefined
|
...(readingTime !== undefined
|
||||||
? { readingTime: Number(readingTime) }
|
? { readingTime: Number(readingTime) }
|
||||||
: {}),
|
: {}),
|
||||||
...(authorId ? { author: { connect: { id: authorId } } } : {}),
|
// null clears attribution; omitted/legacy empty leaves it unchanged.
|
||||||
|
...(authorId === null
|
||||||
|
? { author: { disconnect: true } }
|
||||||
|
: authorId
|
||||||
|
? { author: { connect: { id: authorId } } }
|
||||||
|
: {}),
|
||||||
...(categoryId !== undefined
|
...(categoryId !== undefined
|
||||||
? categoryId
|
? categoryId
|
||||||
? { category: { connect: { id: categoryId } } }
|
? { category: { connect: { id: categoryId } } }
|
||||||
|
|||||||
@@ -87,9 +87,9 @@ describe('BlogPostPage FAQPage Schema injection (SEO-P1-07)', () => {
|
|||||||
const jsx=await BlogPostPage({params:Promise.resolve({slug:'technical'})}); const script:any=React.Children.toArray(jsx.props.children)[0]; const json=JSON.parse(script.props.dangerouslySetInnerHTML.__html); expect(json.dateModified).toBeUndefined();
|
const jsx=await BlogPostPage({params:Promise.resolve({slug:'technical'})}); const script:any=React.Children.toArray(jsx.props.children)[0]; const json=JSON.parse(script.props.dangerouslySetInnerHTML.__html); expect(json.dateModified).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses the stable Organization fallback visibly and in metadata', async () => {
|
it.each([null, { firstName: '', lastName: '' }])('uses the stable Organization fallback for author %j visibly and in metadata', async (author) => {
|
||||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({ ok: true, json: async () => ({
|
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({ ok: true, json: async () => ({
|
||||||
slug: 'authorless', title: 'Authorless', content: '<p>x</p>', publishedAt: '2026-01-01T00:00:00Z', author: { firstName: '', lastName: '' },
|
slug: 'authorless', title: 'Authorless', content: '<p>x</p>', publishedAt: '2026-01-01T00:00:00Z', author, authorTeam: null,
|
||||||
}) }));
|
}) }));
|
||||||
|
|
||||||
const metadata = await generateMetadata({ params: Promise.resolve({ slug: 'authorless' }) });
|
const metadata = await generateMetadata({ params: Promise.resolve({ slug: 'authorless' }) });
|
||||||
@@ -106,7 +106,7 @@ describe('BlogPostPage FAQPage Schema injection (SEO-P1-07)', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses a custom authorTeam as the authorless Organization identity in metadata and rendering', async () => {
|
it('keeps custom team attribution separate from the Organization author identity', async () => {
|
||||||
const organizationName = 'تیم دامپزشکی کنینا';
|
const organizationName = 'تیم دامپزشکی کنینا';
|
||||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({ ok: true, json: async () => ({
|
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({ ok: true, json: async () => ({
|
||||||
slug: 'custom-team',
|
slug: 'custom-team',
|
||||||
|
|||||||
Reference in new issue
Block a user