expeditavoluptas
Version:
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.
48 lines (34 loc) • 992 B
text/typescript
import { Embeddable, Embedded, Entity, PrimaryKey, Property, serialize } from '@mikro-orm/core';
import { MikroORM } from '@mikro-orm/sqlite';
()
export class DetailsEntity {
()
code!: number;
({ nullable: true })
details?: string;
}
()
export class ListEntity2Test {
()
id!: string;
({ nullable: true })
title!: string;
(() => DetailsEntity)
details!: DetailsEntity;
}
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [ListEntity2Test],
dbName: ':memory:',
});
await orm.schema.createSchema();
});
afterAll(() => orm.close(true));
test('serialization with nulls', async () => {
const expDto = { id: '1', details: { code: 2 } };
await orm.em.nativeInsert(ListEntity2Test, expDto);
const entity = await orm.em.findOneOrFail(ListEntity2Test, { id: '1' });
const dto = serialize(entity, { skipNull: true });
expect(dto).toEqual(expDto);
});