chore: prepare project for server deployment
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
const Entity = require('../src/models/Entity');
|
||||
const { getDb, closeDb } = require('../src/config/database');
|
||||
const { migrate } = require('../src/database/migrate');
|
||||
|
||||
beforeAll(() => {
|
||||
migrate();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
closeDb();
|
||||
});
|
||||
|
||||
describe('Entity Model', () => {
|
||||
let entityId;
|
||||
|
||||
test('应该创建实体', () => {
|
||||
const entity = Entity.create({
|
||||
name: '测试实体',
|
||||
definition: '这是一个测试实体',
|
||||
description: '测试实体的描述'
|
||||
});
|
||||
|
||||
expect(entity).toBeDefined();
|
||||
expect(entity.entity_id).toBeDefined();
|
||||
expect(entity.name).toBe('测试实体');
|
||||
expect(entity.definition).toBe('这是一个测试实体');
|
||||
expect(entity.description).toBe('测试实体的描述');
|
||||
|
||||
entityId = entity.entity_id;
|
||||
});
|
||||
|
||||
test('应该根据ID查找实体', () => {
|
||||
const entity = Entity.findById(entityId);
|
||||
expect(entity).toBeDefined();
|
||||
expect(entity.entity_id).toBe(entityId);
|
||||
expect(entity.name).toBe('测试实体');
|
||||
});
|
||||
|
||||
test('应该更新实体', () => {
|
||||
const updatedEntity = Entity.update(entityId, {
|
||||
name: '更新后的实体',
|
||||
description: '更新后的描述'
|
||||
});
|
||||
|
||||
expect(updatedEntity.name).toBe('更新后的实体');
|
||||
expect(updatedEntity.description).toBe('更新后的描述');
|
||||
});
|
||||
|
||||
test('应该获取所有实体', () => {
|
||||
const entities = Entity.findAll();
|
||||
expect(Array.isArray(entities)).toBe(true);
|
||||
expect(entities.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test('应该删除实体', () => {
|
||||
const result = Entity.delete(entityId);
|
||||
expect(result.changes).toBe(1);
|
||||
|
||||
const entity = Entity.findById(entityId);
|
||||
expect(entity).toBeUndefined();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user