Wire blogEnabled into shop render locals and expose public blog index and detail routes when the shop toggle is on.
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import { NotFoundException } from '@nestjs/common';
|
|
import type { Repository } from 'typeorm';
|
|
import { BlogPost } from '../../blog/entities/BlogPost';
|
|
import { StorefrontBlogPostsService } from './StorefrontBlogPostsService';
|
|
|
|
describe('StorefrontBlogPostsService', () => {
|
|
let service: StorefrontBlogPostsService;
|
|
let blogPostRepo: {
|
|
find: jest.Mock;
|
|
findOne: jest.Mock;
|
|
};
|
|
|
|
beforeEach(() => {
|
|
blogPostRepo = {
|
|
find: jest.fn().mockResolvedValue([]),
|
|
findOne: jest.fn().mockResolvedValue(null)
|
|
};
|
|
|
|
service = new StorefrontBlogPostsService(blogPostRepo as unknown as Repository<BlogPost>);
|
|
});
|
|
|
|
it('lists live posts ordered by createdAt descending', async () => {
|
|
await service.listLivePosts();
|
|
|
|
expect(blogPostRepo.find).toHaveBeenCalledWith({
|
|
where: { isDraft: false },
|
|
order: { createdAt: 'DESC' }
|
|
});
|
|
});
|
|
|
|
it('returns a live post by id', async () => {
|
|
const post = { id: 'post-1', title: 'Hello', isDraft: false } as BlogPost;
|
|
|
|
blogPostRepo.findOne.mockResolvedValue(post);
|
|
|
|
await expect(service.getLivePost('post-1')).resolves.toBe(post);
|
|
});
|
|
|
|
it('throws when a draft or missing post is requested', async () => {
|
|
await expect(service.getLivePost('missing-id')).rejects.toThrow(NotFoundException);
|
|
});
|
|
});
|