-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
/
issue-8681.ts
45 lines (39 loc) · 1.61 KB
/
issue-8681.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
import "../../utils/test-setup"
import {
closeTestingConnections,
createTestingConnections,
reloadTestingDatabases,
} from "../../utils/test-utils"
import { DataSource, DeepPartial } from "../../../src"
import { expect } from "chai"
import { Thing } from "./entity/thing.entity"
import { Item } from "./entity/item.entity"
describe("github issues > #8681 DeepPartial simplification breaks the .create() and .save() method in certain cases.", () => {
let connections: DataSource[]
before(
async () =>
(connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchema: true,
})),
)
beforeEach(() => reloadTestingDatabases(connections))
after(() => closeTestingConnections(connections))
it("should .save() and .create() complex deep partial entities", () =>
Promise.all(
connections.map(async (connection) => {
const myThing: DeepPartial<Thing> = {
items: [{ id: 1 }, { id: 2 }],
}
const thing = connection.manager.create(Thing, myThing)
await connection.getRepository(Thing).save(myThing)
const items = connection.manager.create(Item, myThing.items)
if (myThing.items)
await connection.getRepository(Item).save(myThing.items)
const dbItems = await connection.manager.find(Item)
expect(dbItems).to.have.length(2)
return { thing, items }
}),
))
})