Skip to content

Commit

Permalink
test: adds test to prevent #4958 from recurring (#6835)
Browse files Browse the repository at this point in the history
in #4958 we found that the PR #4804 caused issues in a variety
of situations.  this adds a test to prevent the issue from recurring
where similar classes get mixed up in our metadata resolver
  • Loading branch information
imnotjames committed Oct 7, 2020
1 parent 990442e commit 4a0faf0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/github-issues/4958/entity/first.ts
@@ -0,0 +1,11 @@
import { Column, Entity } from "../../../../src";

@Entity({ name: "first" })
export default class Testing {
@Column("int", {
nullable: false,
primary: true,
unique: true,
})
public id!: number;
}
11 changes: 11 additions & 0 deletions test/github-issues/4958/entity/second.ts
@@ -0,0 +1,11 @@
import { Column, Entity } from "../../../../src";

@Entity({ name: "second" })
export default class Testing {
@Column("int", {
nullable: false,
primary: true,
unique: true,
})
public notId!: number;
}
24 changes: 24 additions & 0 deletions test/github-issues/4958/issue-4958.ts
@@ -0,0 +1,24 @@
import {expect} from "chai";
import {Connection} from "../../../src/connection/Connection";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
import First from "./entity/first";
import Second from "./entity/second";

describe("github issues > #4958 getRepository returns results from another Repo", () => {
let connections: Connection[];
before(async () => connections = await createTestingConnections({
entities: [First, Second],
enabledDrivers: ["sqlite"]
}));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));

it("sql generated is for correct model", () => Promise.all(connections.map(async connection => {
const rawSql = await connection
.getRepository(Second)
.createQueryBuilder("a")
.getSql();

expect(rawSql).to.be.equal('SELECT "a"."notId" AS "a_notId" FROM "second" "a"');
})));
});

0 comments on commit 4a0faf0

Please sign in to comment.