36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import 'reflect-metadata';
|
|
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { validate } from 'class-validator';
|
|
import { CreateAssetDto } from '../../src/asset-master/dto/create-asset.dto';
|
|
import { CreateAssetTypeDto } from '../../src/asset-master/dto/create-asset-type.dto';
|
|
|
|
const TYPE_ID = '16e54e65-60cf-4739-b0d1-ccdd904fbfd5';
|
|
|
|
test('CreateAssetTypeDto accepts a root type without fixed hierarchy levels', async () => {
|
|
const dto = Object.assign(new CreateAssetTypeDto(), {
|
|
code: 'empresa_operadora',
|
|
name: 'Empresa operadora',
|
|
description: 'Entidad administrable raíz',
|
|
canBeRoot: true,
|
|
allowedParentTypeIds: [],
|
|
});
|
|
assert.deepEqual(await validate(dto), []);
|
|
});
|
|
|
|
test('CreateAssetDto validates identity, type and the attributes object', async () => {
|
|
const dto = Object.assign(new CreateAssetDto(), {
|
|
code: 'ACT-001',
|
|
name: 'Activo de prueba',
|
|
typeId: TYPE_ID,
|
|
parentId: null,
|
|
description: null,
|
|
attributes: {},
|
|
});
|
|
assert.deepEqual(await validate(dto), []);
|
|
|
|
dto.code = 'código con espacios';
|
|
const properties = new Set((await validate(dto)).map((error) => error.property));
|
|
assert.equal(properties.has('code'), true);
|
|
});
|