Skip to content

Commit c57b8bb

Browse files
author
Gonçalo Alves
committed
move tests fo functional tab.
implement remaining tests. implement remaining fields.
1 parent cab14b3 commit c57b8bb

File tree

6 files changed

+223
-72
lines changed

6 files changed

+223
-72
lines changed

src/metadata-builder/ClosureJunctionEntityMetadataBuilder.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ export class ClosureJunctionEntityMetadataBuilder {
6363
primary: true,
6464
length: primaryColumn.length,
6565
type: primaryColumn.type,
66-
unsigned: primaryColumn.unsigned ?? false,
66+
unsigned: primaryColumn.unsigned,
67+
width: primaryColumn.width,
68+
precision: primaryColumn.precision,
69+
scale: primaryColumn.scale,
70+
zerofill: primaryColumn.zerofill,
71+
charset: primaryColumn.charset,
72+
collation: primaryColumn.collation,
6773
},
6874
},
6975
}),
@@ -89,7 +95,13 @@ export class ClosureJunctionEntityMetadataBuilder {
8995
primary: true,
9096
length: primaryColumn.length,
9197
type: primaryColumn.type,
92-
unsigned: primaryColumn.unsigned ?? false,
98+
unsigned: primaryColumn.unsigned,
99+
width: primaryColumn.width,
100+
precision: primaryColumn.precision,
101+
scale: primaryColumn.scale,
102+
zerofill: primaryColumn.zerofill,
103+
charset: primaryColumn.charset,
104+
collation: primaryColumn.collation,
93105
},
94106
},
95107
}),

test/functional/tree-tables/closure-table/closure-table.ts

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import "reflect-metadata"
22
import { Category } from "./entity/Category"
3+
import { Foo1Entity } from "./entity/Foo1"
4+
import { Foo2Entity } from "./entity/Foo2"
5+
import { Foo3Entity } from "./entity/Foo3"
36
import { DataSource } from "../../../../src/data-source/DataSource"
47
import {
58
closeTestingConnections,
69
createTestingConnections,
710
reloadTestingDatabases,
811
} from "../../../utils/test-utils"
12+
import { expect } from "chai"
913

1014
describe("tree tables > closure-table", () => {
1115
let connections: DataSource[]
1216
before(
1317
async () =>
1418
(connections = await createTestingConnections({
15-
entities: [Category],
19+
entities: [Category, Foo1Entity, Foo2Entity, Foo3Entity],
1620
})),
1721
)
1822
beforeEach(() => reloadTestingDatabases(connections))
@@ -728,4 +732,115 @@ describe("tree tables > closure-table", () => {
728732
})
729733
}),
730734
))
735+
736+
it("foo1 should create closure columns unsigned", () =>
737+
Promise.all(
738+
connections.map(async (dataSource) => {
739+
const fooMetadata = dataSource.entityMetadatas.find(
740+
(el) => el.tableName === "foo1",
741+
)!
742+
743+
expect(fooMetadata).to.exist
744+
745+
const fooClosureMetadata = dataSource.entityMetadatas.find(
746+
(el) => el.tableName === "foo1_closure",
747+
)!
748+
749+
expect(fooClosureMetadata).to.exist
750+
751+
const ancestorCol = fooClosureMetadata.columns.find(
752+
(col) => col.databaseName === "ancestor_id",
753+
)!
754+
755+
expect(ancestorCol).to.exist
756+
757+
const descendantCol = fooClosureMetadata.columns.find(
758+
(col) => col.databaseName === "descendant_id",
759+
)!
760+
761+
expect(descendantCol).to.exist
762+
763+
expect(ancestorCol.unsigned).to.be.true
764+
expect(descendantCol.unsigned).to.be.true
765+
}),
766+
))
767+
768+
it("foo2 should create closure columns with specified zerofill, width, precision and scale", () =>
769+
Promise.all(
770+
connections.map(async (dataSource) => {
771+
const fooMetadata = dataSource.entityMetadatas.find(
772+
(el) => el.tableName === "foo2",
773+
)!
774+
775+
expect(fooMetadata).to.exist
776+
777+
const fooClosureMetadata = dataSource.entityMetadatas.find(
778+
(el) => el.tableName === "foo2_closure",
779+
)!
780+
781+
expect(fooClosureMetadata).to.exist
782+
783+
const ancestorCol = fooClosureMetadata.columns.find(
784+
(col) => col.databaseName === "ancestor_id",
785+
)!
786+
787+
expect(ancestorCol).to.exist
788+
789+
const descendantCol = fooClosureMetadata.columns.find(
790+
(col) => col.databaseName === "descendant_id",
791+
)!
792+
793+
expect(descendantCol).to.exist
794+
795+
expect(ancestorCol.zerofill).to.be.true
796+
expect(descendantCol.zerofill).to.be.true
797+
798+
expect(ancestorCol.width).to.be.eq(13)
799+
expect(descendantCol.width).to.be.eq(13)
800+
801+
expect(ancestorCol.precision).to.be.eq(9)
802+
expect(descendantCol.precision).to.be.eq(9)
803+
804+
expect(ancestorCol.scale).to.be.eq(3)
805+
expect(descendantCol.scale).to.be.eq(3)
806+
}),
807+
))
808+
809+
it("foo3 should create closure columns with specified length, charset and collation", () =>
810+
Promise.all(
811+
connections.map(async (dataSource) => {
812+
const fooMetadata = dataSource.entityMetadatas.find(
813+
(el) => el.tableName === "foo3",
814+
)!
815+
816+
expect(fooMetadata).to.exist
817+
818+
const fooClosureMetadata = dataSource.entityMetadatas.find(
819+
(el) => el.tableName === "foo3_closure",
820+
)!
821+
822+
expect(fooClosureMetadata).to.exist
823+
824+
const ancestorCol = fooClosureMetadata.columns.find(
825+
(col) => col.databaseName === "ancestor_id",
826+
)!
827+
828+
expect(ancestorCol).to.exist
829+
830+
const descendantCol = fooClosureMetadata.columns.find(
831+
(col) => col.databaseName === "descendant_id",
832+
)!
833+
834+
expect(descendantCol).to.exist
835+
836+
expect(ancestorCol.length).to.be.eq('201')
837+
expect(descendantCol.length).to.be.eq('201')
838+
839+
expect(ancestorCol.charset).to.be.eq("latin1")
840+
expect(descendantCol.charset).to.be.eq("latin1")
841+
842+
expect(ancestorCol.collation).to.be.eq("latin1_bin")
843+
expect(descendantCol.collation).to.be.eq("latin1_bin")
844+
}),
845+
))
731846
})

test/github-issues/9600/entity/Foo.ts renamed to test/functional/tree-tables/closure-table/entity/Foo1.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,25 @@ import {
66
Tree,
77
TreeChildren,
88
TreeParent,
9-
} from "../../../../src"
9+
} from "../../../../../src"
1010

11-
// won't work if bug exists
12-
13-
@Entity({ name: "foo" })
11+
@Entity({ name: "foo1" })
1412
@Tree("closure-table", {
15-
closureTableName: "foo",
13+
closureTableName: "foo1",
1614
ancestorColumnName: () => "ancestor_id",
1715
descendantColumnName: () => "descendant_id",
1816
})
19-
export class FooEntity {
17+
export class Foo1Entity {
2018
@PrimaryGeneratedColumn({ type: "int", name: "id", unsigned: true })
2119
id: number
2220

23-
@Column("int", { name: "parent_id", unsigned: true })
21+
@Column({ type: "int", name: "parent_id", unsigned: true })
2422
parentId: number
2523

2624
@TreeParent()
2725
@JoinColumn({ name: "parent_id", referencedColumnName: "id" })
28-
parent: FooEntity
26+
parent: Foo1Entity
2927

3028
@TreeChildren()
31-
children: FooEntity[]
29+
children: Foo1Entity[]
3230
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {
2+
Column,
3+
Entity,
4+
JoinColumn,
5+
PrimaryColumn,
6+
Tree,
7+
TreeChildren,
8+
TreeParent,
9+
} from "../../../../../src"
10+
11+
@Entity({ name: "foo2" })
12+
@Tree("closure-table", {
13+
closureTableName: "foo2",
14+
ancestorColumnName: () => "ancestor_id",
15+
descendantColumnName: () => "descendant_id",
16+
})
17+
export class Foo2Entity {
18+
@PrimaryColumn({
19+
type: "decimal",
20+
name: "id",
21+
zerofill: true,
22+
width: 13,
23+
precision: 9,
24+
scale: 3,
25+
})
26+
id: number
27+
28+
@Column({
29+
type: "decimal",
30+
name: "parent_id",
31+
zerofill: true,
32+
width: 13,
33+
precision: 9,
34+
scale: 3,
35+
})
36+
parentId: number
37+
38+
@TreeParent()
39+
@JoinColumn({ name: "parent_id", referencedColumnName: "id" })
40+
parent: Foo2Entity
41+
42+
@TreeChildren()
43+
children: Foo2Entity[]
44+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {
2+
Column,
3+
Entity,
4+
JoinColumn,
5+
PrimaryColumn,
6+
Tree,
7+
TreeChildren,
8+
TreeParent,
9+
} from "../../../../../src"
10+
11+
@Entity({ name: "foo3" })
12+
@Tree("closure-table", {
13+
closureTableName: "foo3",
14+
ancestorColumnName: () => "ancestor_id",
15+
descendantColumnName: () => "descendant_id",
16+
})
17+
export class Foo3Entity {
18+
@PrimaryColumn({
19+
type: "varchar",
20+
name: "id",
21+
length: 201,
22+
charset: "latin1",
23+
collation: "latin1_bin",
24+
})
25+
id: number
26+
27+
@Column({
28+
type: "varchar",
29+
name: "parent_id",
30+
length: 201,
31+
charset: "latin1",
32+
collation: "latin1_bin",
33+
})
34+
parentId: number
35+
36+
@TreeParent()
37+
@JoinColumn({ name: "parent_id", referencedColumnName: "id" })
38+
parent: Foo3Entity
39+
40+
@TreeChildren()
41+
children: Foo3Entity[]
42+
}

test/github-issues/9600/issue-9600.ts

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)