Skip to content

Commit

Permalink
test: added failing test for github issue typeorm#6948
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyasfoo committed Oct 28, 2020
1 parent a5eb946 commit b8b5e9b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/github-issues/6948/entity/Category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Entity, PrimaryGeneratedColumn, Column, Tree, TreeParent, TreeChildren } from "../../../../src";

@Entity()
@Tree("materialized-path")
export class Category {
@PrimaryGeneratedColumn()
cat_id: number;

@Column()
cat_name: string;

@TreeParent()
cat_parent: Category;

@TreeChildren({ cascade: true })
cat_children: Category[];
}
38 changes: 38 additions & 0 deletions test/github-issues/6948/issue-6948.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import "reflect-metadata";
import { Category } from "./entity/Category";
import { Connection } from "../../../src/connection/Connection";
import {
closeTestingConnections,
createTestingConnections,
reloadTestingDatabases,
} from "../../../test/utils/test-utils";

describe("github issues > #6948 TreeRepository's findRoots query incorrectly when using a custom primary key", () => {
let connections: Connection[];
before(
async () =>
(connections = await createTestingConnections({
entities: [Category],
}))
);
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));

it("entity parent column should work with custom primary column names ", () =>
Promise.all(
connections.map(async (connection) => {
const categoryRepository = connection.getTreeRepository(
Category
);
await categoryRepository.save(
categoryRepository.create({
cat_name: "Root node",
})
);
const rootNodes = await categoryRepository.findRoots();
rootNodes[0].should.deep.include({
cat_name: "Root node",
});
})
));
});

0 comments on commit b8b5e9b

Please sign in to comment.