Skip to content

Commit

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

@Entity()
export class Post {

@PrimaryGeneratedColumn()
id?: number;

@Column()
title: string;

@CreateDateColumn()
readonly createdAt?: Date;
}
60 changes: 60 additions & 0 deletions test/github-issues/6266/issue-6266.ts
@@ -0,0 +1,60 @@
import "reflect-metadata";
import {
closeTestingConnections,
createTestingConnections,
reloadTestingDatabases,
} from "../../utils/test-utils";
import { Connection } from "../../../src/connection/Connection";
import { Post } from "./entity/Post";
import sinon from "sinon";
import { SelectQueryBuilder } from "../../../src";
import { assert } from "chai";

describe("github issues > #6266 Many identical selects after insert bunch of items", () => {
let connections: Connection[];
const posts: Post[] = [
{
title: "Post 1",
},
{
title: "Post 2",
},
{
title: "Post 3",
},
{
title: "Post 4",
},
];

before(
async () =>
(connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
enabledDrivers: ["mysql"],
}))
);
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));

it("should execute a single SELECT to get inserted default and generated values of multiple entities", () =>
Promise.all(
connections.map(async (connection) => {
const selectSpy = sinon.spy(
SelectQueryBuilder.prototype,
"select"
);

await connection
.createQueryBuilder()
.insert()
.into(Post)
.values(posts)
.execute();

assert.strictEqual(selectSpy.calledOnce, true);

selectSpy.restore();
})
));
});

0 comments on commit 34d2790

Please sign in to comment.