260320:1131 Refactor Overrall #01
Build and Deploy / deploy (push) Has been cancelled

This commit is contained in:
admin
2026-03-20 11:31:27 +07:00
parent f1b81a7d0d
commit 1d3479770b
147 changed files with 1745 additions and 1567 deletions
@@ -39,7 +39,7 @@ export class AuditLog {
entityId?: string;
@Column({ name: 'details_json', type: 'json', nullable: true })
detailsJson?: any;
detailsJson?: Record<string, unknown>;
@Column({ name: 'ip_address', length: 45, nullable: true })
ipAddress?: string;
@@ -0,0 +1,80 @@
// Mock uuid module to avoid ESM import issue with uuid@13
jest.mock('uuid', () => ({
validate: (str: string) =>
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(
str
),
v7: () => '01912345-6789-7abc-8def-0123456789ab',
}));
import { UuidBaseEntity } from './uuid-base.entity';
// Concrete subclass for testing the abstract base
class TestEntity extends UuidBaseEntity {
id!: number;
}
describe('UuidBaseEntity', () => {
// ==========================================================
// generateUuid() — @BeforeInsert hook
// ==========================================================
describe('generateUuid()', () => {
it('should generate a UUIDv7 when uuid is not set', () => {
const entity = new TestEntity();
expect(entity.uuid).toBeUndefined();
entity.generateUuid();
expect(entity.uuid).toBe('01912345-6789-7abc-8def-0123456789ab');
});
it('should not overwrite an existing uuid', () => {
const entity = new TestEntity();
entity.uuid = 'existing-uuid-value-should-be-kept';
entity.generateUuid();
expect(entity.uuid).toBe('existing-uuid-value-should-be-kept');
});
it('should not overwrite a pre-set UUIDv1 from DB default', () => {
const entity = new TestEntity();
entity.uuid = '550e8400-e29b-11d4-a716-446655440000';
entity.generateUuid();
expect(entity.uuid).toBe('550e8400-e29b-11d4-a716-446655440000');
});
it('should generate uuid when uuid is empty string', () => {
const entity = new TestEntity();
entity.uuid = '';
entity.generateUuid();
// Empty string is falsy, so generateUuid should assign a new value
expect(entity.uuid).toBe('01912345-6789-7abc-8def-0123456789ab');
});
});
// ==========================================================
// Inheritance
// ==========================================================
describe('inheritance', () => {
it('should be an instance of UuidBaseEntity', () => {
const entity = new TestEntity();
expect(entity).toBeInstanceOf(UuidBaseEntity);
});
it('should have uuid property accessible from subclass', () => {
const entity = new TestEntity();
entity.uuid = 'test-uuid';
entity.id = 42;
expect(entity.uuid).toBe('test-uuid');
expect(entity.id).toBe(42);
});
});
});