forked from typeorm/typeorm
/
issue-2131.ts
53 lines (49 loc) · 1.54 KB
/
issue-2131.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
import "reflect-metadata";
import {
closeTestingConnections,
createTestingConnections,
reloadTestingDatabases,
} from "../../utils/test-utils";
import { Connection } from "../../../src/connection/Connection";
import { expect } from "chai";
import { Post } from "./entity/Post";
describe("github issues > #2131 InsertResult return the same primary key", () => {
let connections: Connection[];
const posts: Post[] = [{
id: null,
title: "Post 1",
}, {
id: null,
title: "Post 2",
}, {
id: null,
title: "Post 3",
}, {
id: null,
title: "Post 4",
}];
before(
async () =>
(connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
enabledDrivers: ["sqlite", "mysql"],
}))
);
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("should get correct insert ids for multiple entities inserted", () =>
Promise.all(
connections.map(async (connection) => {
await connection
.createQueryBuilder()
.insert()
.into(Post)
.values(posts)
.execute();
expect(posts[0].id).to.equal(1);
expect(posts[1].id).to.equal(2);
expect(posts[2].id).to.equal(3);
expect(posts[3].id).to.equal(4);
})
));
});