forked from typeorm/typeorm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added failing test for github issue typeorm#6948
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}); | ||
}) | ||
)); | ||
}); |