undeexcepturi
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.
81 lines (57 loc) • 1.61 kB
text/typescript
import { MikroORM } from '@mikro-orm/sqlite';
import { Embeddable, Embedded, Entity, OneToOne, PrimaryKey, Property, Rel } from '@mikro-orm/core';
import { v4 } from 'uuid';
import { mockLogger } from '../helpers';
()
class Course {
()
id: string = v4();
({ entity: () => Customization, nullable: true })
draft?: Rel<Customization>;
({ entity: () => Customization, nullable: true })
published?: Rel<Customization>;
}
()
class Customization {
()
id: string = v4();
(() => Topic, { array: true, nullable: true })
topics?: Topic[] = [];
}
()
class Topic {
()
private _name!: string;
get name(): string {
return this._name;
}
}
function createCustomization() {
const topic = new Topic();
const customization = new Customization();
customization.topics = [topic];
return customization;
}
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [Course, Customization, Topic],
dbName: ':memory:',
});
await orm.getSchemaGenerator().createSchema();
const course1 = new Course();
course1.published = createCustomization();
orm.em.persist(course1);
const course2 = new Course();
course2.draft = createCustomization();
orm.em.persist(course2);
await orm.em.flush();
orm.em.clear();
});
afterAll(() => orm.close(true));
test('json property hydration', async () => {
await orm.em.find(Course, {}, { populate: ['*'] });
const mock = mockLogger(orm);
await orm.em.flush();
expect(mock).not.toHaveBeenCalled();
});