chore: prepare project for server deployment
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
const Content = require('../src/models/Content');
|
||||
const Page = require('../src/models/Page');
|
||||
const { getDb, closeDb } = require('../src/config/database');
|
||||
const { migrate } = require('../src/database/migrate');
|
||||
|
||||
beforeAll(() => {
|
||||
migrate();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
closeDb();
|
||||
});
|
||||
|
||||
describe('Content Model', () => {
|
||||
let contentId;
|
||||
|
||||
test('应该创建内容', () => {
|
||||
const content = Content.create({
|
||||
title: '测试内容',
|
||||
body: '这是测试内容的主体',
|
||||
content_type: 'page',
|
||||
publish_status: 'draft'
|
||||
});
|
||||
|
||||
expect(content).toBeDefined();
|
||||
expect(content.content_id).toBeDefined();
|
||||
expect(content.title).toBe('测试内容');
|
||||
expect(content.body).toBe('这是测试内容的主体');
|
||||
expect(content.content_type).toBe('page');
|
||||
expect(content.publish_status).toBe('draft');
|
||||
|
||||
contentId = content.content_id;
|
||||
});
|
||||
|
||||
test('应该根据ID查找内容', () => {
|
||||
const content = Content.findById(contentId);
|
||||
expect(content).toBeDefined();
|
||||
expect(content.content_id).toBe(contentId);
|
||||
expect(content.title).toBe('测试内容');
|
||||
});
|
||||
|
||||
test('应该更新内容', () => {
|
||||
const updatedContent = Content.update(contentId, {
|
||||
title: '更新后的内容',
|
||||
body: '更新后的主体'
|
||||
});
|
||||
|
||||
expect(updatedContent.title).toBe('更新后的内容');
|
||||
expect(updatedContent.body).toBe('更新后的主体');
|
||||
});
|
||||
|
||||
test('应该进行状态流转', () => {
|
||||
// draft -> review
|
||||
const reviewContent = Content.transitionStatus(contentId, 'review');
|
||||
expect(reviewContent.publish_status).toBe('review');
|
||||
|
||||
// review -> published
|
||||
const publishedContent = Content.transitionStatus(contentId, 'published');
|
||||
expect(publishedContent.publish_status).toBe('published');
|
||||
expect(publishedContent.version_no).toBe(2);
|
||||
|
||||
// published -> unpublished
|
||||
const unpublishedContent = Content.transitionStatus(contentId, 'unpublished');
|
||||
expect(unpublishedContent.publish_status).toBe('unpublished');
|
||||
|
||||
// unpublished -> historical
|
||||
const historicalContent = Content.transitionStatus(contentId, 'historical');
|
||||
expect(historicalContent.publish_status).toBe('historical');
|
||||
expect(historicalContent.archived_at).toBeDefined();
|
||||
});
|
||||
|
||||
test('应该创建历史版本', () => {
|
||||
// 先创建一个新的内容
|
||||
const newContent = Content.create({
|
||||
title: '历史版本测试',
|
||||
body: '这是历史版本测试的主体',
|
||||
content_type: 'article',
|
||||
publish_status: 'draft'
|
||||
});
|
||||
|
||||
// 创建历史版本
|
||||
const historicalVersion = Content.createHistoricalVersion(newContent.content_id);
|
||||
expect(historicalVersion).toBeDefined();
|
||||
expect(historicalVersion.version_no).toBe(newContent.version_no + 1);
|
||||
expect(historicalVersion.publish_status).toBe('historical');
|
||||
});
|
||||
|
||||
test('应该删除内容', () => {
|
||||
const result = Content.delete(contentId);
|
||||
expect(result.changes).toBe(1);
|
||||
|
||||
const content = Content.findById(contentId);
|
||||
expect(content).toBeUndefined();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user