-
-
Notifications
You must be signed in to change notification settings - Fork 495
/
GH4080.test.ts
87 lines (68 loc) · 1.69 KB
/
GH4080.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { EntitySchema, SimpleLogger } from '@mikro-orm/core';
import { MikroORM } from '@mikro-orm/sqlite';
abstract class BaseClass {
id?: number;
}
interface BaseInterface {
id?: number;
}
class DerivedClass extends BaseClass {
name?: string;
}
class ImplementingClass implements BaseInterface {
id?: number;
name?: string;
}
const BaseClassSchema = new EntitySchema<BaseClass>({
name: 'BaseClass',
abstract: true,
properties: {
id: { type: Number, primary: true },
},
});
const BaseInterfaceSchema = new EntitySchema<BaseInterface>({
name: 'BaseInterface',
abstract: true,
properties: {
id: { type: Number, primary: true },
},
});
const DerivedClassSchema = new EntitySchema<DerivedClass>({
class: DerivedClass,
extends: 'BaseClass',
properties: {
name: { type: String },
},
});
const ImplementingClassSchema = new EntitySchema<ImplementingClass>({
class: ImplementingClass,
extends: 'BaseInterface',
properties: {
name: { type: String },
},
});
let orm: MikroORM;
beforeAll(async () => {
const logger = jest.fn();
orm = await MikroORM.init({
entities: [
BaseClassSchema,
DerivedClassSchema,
BaseInterfaceSchema,
ImplementingClassSchema,
],
dbName: `:memory:`,
logger: msg => logger(msg),
loggerFactory: options => new SimpleLogger(options),
debug: true,
});
expect(logger.mock.calls.toString()).not.toMatch('undefined');
await orm.schema.refreshDatabase();
});
afterAll(() => orm.close(true));
test('4080', async () => {
orm.em.create(DerivedClassSchema, { name: 'foo' });
await orm.em.flush();
orm.em.clear();
await orm.em.findOneOrFail(DerivedClassSchema, { name: 'foo' });
});