Skip to content

Commit

Permalink
test: add test case for fix of typeorm#2131
Browse files Browse the repository at this point in the history
  • Loading branch information
dolsup committed Sep 4, 2020
1 parent 29ee43d commit 277a0de
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/github-issues/2131/entity/Post.ts
@@ -0,0 +1,12 @@
import { PrimaryGeneratedColumn, Entity, Column } from "../../../../src";

@Entity()
export class Post {

@PrimaryGeneratedColumn()
id: number | null;

@Column()
title: string;

}
53 changes: 53 additions & 0 deletions test/github-issues/2131/issue-2131.ts
@@ -0,0 +1,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);
})
));
});

0 comments on commit 277a0de

Please sign in to comment.