Skip to content

Commit

Permalink
test: add test for typeorm#3685
Browse files Browse the repository at this point in the history
  • Loading branch information
haoyuhu committed Mar 11, 2020
1 parent 4c94257 commit 74a38a2
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/github-issues/3685/entity/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Column, Entity, PrimaryGeneratedColumn } from "../../../../src";

@Entity()
export class User {

@PrimaryGeneratedColumn()
id: number;

@Column()
firstName: string;

@Column()
lastName: string;

}
62 changes: 62 additions & 0 deletions test/github-issues/3685/issue-3685.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {expect} from "chai";
import {Brackets, Connection} from "../../../src";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
import {User} from "./entity/User";

describe("github issues > #3685 Brackets syntax failed when use where with object literal", () => {

let connections: Connection[];
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
dropSchema: true,
schemaCreate: true,
}));
beforeEach(() => reloadTestingDatabases(connections));
after(() => connections && closeTestingConnections(connections));

it("should accept objects in .where method (github issue #3685)", () => Promise.all(connections.map(async connection => {

await Promise.all([
connection.manager.save(Object.assign(new User(), {
firstName: "Jean",
lastName: "Doe",
})),

connection.manager.save(Object.assign(new User(), {
firstName: "John",
lastName: "Doe",
})),

connection.manager.save(Object.assign(new User(), {
firstName: "John",
lastName: "Dupont",
})),

connection.manager.save(Object.assign(new User(), {
firstName: "Fred",
lastName: "Doe",
}))
]);

const qb = connection.createQueryBuilder(User, "u")
.where(new Brackets(qb => {
qb.where({ firstName: "John" })
.orWhere("u.firstName = :firstName", { firstName: "Jean" });
}))
.andWhere("u.lastName = :lastName", { lastName: "Doe" })
.orderBy({
"u.firstName": "ASC",
"u.lastName": "ASC",
});

const results = await qb.getMany();

expect(results.length).to.equal(2);

expect(results[0].firstName).to.equal("Jean");
expect(results[0].lastName).to.equal("Doe");

expect(results[1].firstName).to.equal("John");
expect(results[1].lastName).to.equal("Doe");
})));
});

0 comments on commit 74a38a2

Please sign in to comment.