Skip to content

test(tree): simplify tree test entities and remove unused fields - #12260

Merged
pkuczynski merged 2 commits into
masterfrom
fix/tree-test-cleanup
Mar 24, 2026
Merged

pkuczynski merged 2 commits into
masterfrom
fix/tree-test-cleanup

Conversation

@pkuczynski

@pkuczynski pkuczynski commented Mar 24, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #12259 which was prematurely merged before these cleanups were applied.

  • Remove commented-out @TreeLevelColumn / level lines
  • Fix UUID entity type mismatch (id: number → id: string for @PrimaryGeneratedColumn("uuid"))
  • Simplify @Entity("custom_name") to @Entity() where custom name is not relevant to the test
  • Remove redundant decorator options that match defaults (nullable: false, name matching property, referencedColumnName: "id", type: "int" for numbers, type: "varchar" for strings)
  • Remove unused entity fields (created/modified date columns not referenced in tests)
  • Remove empty @JoinColumn() where TypeORM auto-creates the join column
  • Remove unnecessary ! and ? modifiers from entity properties
  • Replace raw table name query with entity class reference
  • Standardize describe titles to tree-tables > <type> > <feature> format (no "basic" suffix)
  • Rename MySQL closure test from mysql > tree tables > closure-table to tree-tables > closure-table > closure column metadata
  • Convert flat it("X > Y", ...) patterns to nested describe/it blocks
  • Replace vague test titles (should work correctly) with descriptive behavior statements

@pkuczynski pkuczynski self-assigned this Mar 24, 2026
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Review Summary by Qodo

Simplify tree test entities and remove unused fields

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Remove commented-out @TreeLevelColumn decorators from test entities
• Fix UUID entity type mismatch: id: number → id: string
• Simplify @Entity("custom_name") to @Entity() where unnecessary
• Remove redundant decorator options matching TypeORM defaults
• Remove unused created/modified date columns from test entities
• Remove empty @JoinColumn() and redundant referencedColumnName options
Diagram
flowchart LR
  A["Test Entity Decorators"] -->|Remove commented code| B["Clean entities"]
  A -->|Fix UUID type mismatch| B
  A -->|Simplify @Entity names| B
  A -->|Remove redundant options| B
  A -->|Remove unused columns| B
  B -->|Cleaner test code| C["Improved maintainability"]
Loading

Grey Divider

File Changes

1. test/functional/tree-tables/closure-table/basic/entity/Category.ts Formatting +0/-3

Remove commented TreeLevelColumn decorator

test/functional/tree-tables/closure-table/basic/entity/Category.ts


2. test/functional/tree-tables/closure-table/basic/entity/Foo2.ts ✨ Enhancement +1/-1

Remove redundant referencedColumnName from JoinColumn

test/functional/tree-tables/closure-table/basic/entity/Foo2.ts


3. test/functional/tree-tables/closure-table/basic/entity/Foo3.ts ✨ Enhancement +1/-1

Remove redundant referencedColumnName from JoinColumn

test/functional/tree-tables/closure-table/basic/entity/Foo3.ts


View more (10)
4. test/functional/tree-tables/closure-table/insert-without-level-column/entity/Category.ts ✨ Enhancement +1/-1

Simplify Entity decorator by removing custom name

test/functional/tree-tables/closure-table/insert-without-level-column/entity/Category.ts


5. test/functional/tree-tables/closure-table/relation-id-property/entity/file.entity.ts ✨ Enhancement +2/-17

Remove unused date columns and simplify decorators

test/functional/tree-tables/closure-table/relation-id-property/entity/file.entity.ts


6. test/functional/tree-tables/closure-table/uuid-primary-key/entity-3783/Category.ts 🐞 Bug fix +1/-1

Fix UUID primary key type from number to string

test/functional/tree-tables/closure-table/uuid-primary-key/entity-3783/Category.ts


7. test/functional/tree-tables/closure-table/uuid-primary-key/entity/Group.ts ✨ Enhancement +1/-1

Remove redundant nullable false option from Column

test/functional/tree-tables/closure-table/uuid-primary-key/entity/Group.ts


8. test/functional/tree-tables/materialized-path/basic/entity/Category.ts ✨ Enhancement +0/-2

Remove empty JoinColumn decorator and unused import

test/functional/tree-tables/materialized-path/basic/entity/Category.ts


9. test/functional/tree-tables/materialized-path/custom-join-column/entity-9534/Category.ts ✨ Enhancement +3/-11

Simplify Entity name and remove redundant Column options

test/functional/tree-tables/materialized-path/custom-join-column/entity-9534/Category.ts


10. test/functional/tree-tables/materialized-path/query-strategy-relations/entity/Fact.ts ✨ Enhancement +2/-2

Simplify Entity name and Column type specification

test/functional/tree-tables/materialized-path/query-strategy-relations/entity/Fact.ts


11. test/functional/tree-tables/materialized-path/query-strategy-relations/entity/Node.ts ✨ Enhancement +2/-2

Simplify Entity name and Column type specification

test/functional/tree-tables/materialized-path/query-strategy-relations/entity/Node.ts


12. test/functional/tree-tables/materialized-path/query-strategy-relations/entity/Rule.ts ✨ Enhancement +2/-2

Simplify Entity name and Column type specification

test/functional/tree-tables/materialized-path/query-strategy-relations/entity/Rule.ts


13. test/functional/tree-tables/materialized-path/soft-delete-parent/entity/node.ts ✨ Enhancement +5/-8

Simplify decorators and remove redundant options

test/functional/tree-tables/materialized-path/soft-delete-parent/entity/node.ts


Grey Divider

Qodo Logo

@pkuczynski pkuczynski changed the title style(test): simplify tree test entities and remove unused fields test(tree): simplify tree test entities and remove unused fields Mar 24, 2026
@coveralls

coveralls commented Mar 24, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 73.427%. remained the same
when pulling e3bdf6f on fix/tree-test-cleanup
into a746e48 on master.

@pkuczynski
pkuczynski force-pushed the fix/tree-test-cleanup branch from 275fd37 to e3bdf6f Compare March 24, 2026 11:47
parentId: number

@TreeParent()
@JoinColumn({ name: "parent_id", referencedColumnName: "id" })

@alumni alumni Mar 24, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such options might have had a purpose in the test (e.g. test without inferring the default), I hope you checked :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I checked. This was not relevant for the test scope... Test pass even without this...

@sonarqubecloud

Copy link
Copy Markdown

@pkuczynski
pkuczynski enabled auto-merge (squash) March 24, 2026 11:49
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 📐 Spec deviations (0)

Grey Divider


Action required

1. Union column type lost 🐞 Bug ✓ Correctness
Description
parentUid?: string | null no longer provides an explicit column type, so TypeORM will infer
design:type as Object and may generate an invalid/driver-specific column type during schema
sync. This can fail schema creation or behave inconsistently across drivers when running the non-pk
parent column tree tests.
Code

test/functional/tree-tables/materialized-path/custom-join-column/entity-9534/Category.ts[R15-22]

+    @Column({ unique: true })
    uid: string

    @Column()
    name: string

-    @Column({
-        type: "varchar",
-        name: "parentUid",
-        nullable: true,
-    })
+    @Column({ nullable: true })
    parentUid?: string | null
Evidence
TypeORM’s @Column() infers options.type from Reflect.getMetadata("design:type", ...) when the
type is not explicitly provided. For union types like string | null, reflect-metadata returns
Object, not String, so drivers normalizeType can’t map it to a valid DB type (e.g.,
PostgresDriver falls back to casting the function to string / empty). The codebase already
demonstrates the required pattern: union-typed nullable string columns specify an explicit type
(e.g., type: String or type: "varchar").

test/functional/tree-tables/materialized-path/custom-join-column/entity-9534/Category.ts[15-22]
src/decorator/columns/Column.ts[157-216]
src/driver/postgres/PostgresDriver.ts[1124-1171]
test/github-issues/6950/entity/post_with_null_2.entity.ts[21-27]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`parentUid?: string | null` in `entity-9534/Category.ts` uses `@Column({ nullable: true })` without an explicit `type`. Because `string | null` is a union type, reflect-metadata reports its design type as `Object`, so TypeORM cannot reliably infer a database column type and schema sync may fail or differ by driver.

## Issue Context
This entity is used by `materialized-path/custom-join-column/non-pk-parent-column.test.ts` and is intended to store a nullable string foreign-key-like value (`parentUid`).

## Fix Focus Areas
- test/functional/tree-tables/materialized-path/custom-join-column/entity-9534/Category.ts[15-22]

## Suggested change
Set an explicit string column type again, e.g.:
- `@Column({ type: "varchar", nullable: true })`
 or
- `@Column({ type: String, nullable: true })`
(keep `nullable: true`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@pkuczynski
pkuczynski merged commit a4d6573 into master Mar 24, 2026
42 checks passed
@pkuczynski
pkuczynski deleted the fix/tree-test-cleanup branch March 24, 2026 12:00
@github-actions github-actions Bot added this to the 1.0 milestone Mar 24, 2026
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 📐 Spec deviations (0)

Grey Divider


Action required

1. Nullable fields typed non-null 🐞 Bug ✓ Correctness
Description
In the soft-delete-parent Node entity, deletedAt, parentId, and parent are declared as
always-present even though the corresponding column/relation can be null for non-deleted and/or root
records. This makes the entity type incorrect and can cause runtime errors when code assumes these
fields are defined (e.g., calling Date methods on a null deletedAt).
Code

test/functional/tree-tables/materialized-path/soft-delete-parent/entity/node.ts[R15-32]

+    @PrimaryGeneratedColumn()
+    id: number

    @DeleteDateColumn()
-    deletedAt?: Date
+    deletedAt: Date

-    @Column("varchar")
-    name!: string
+    @Column()
+    name: string

    @TreeChildren({ cascade: true })
-    children?: Node[]
+    children: Node[]

-    @Column({ type: "int", nullable: true, name: "parentId" })
-    parentId?: number
+    @Column({ nullable: true })
+    parentId: number

    @TreeParent()
-    @JoinColumn({
-        name: "parentId",
-        referencedColumnName: "id",
-    })
-    parent?: Node
+    @JoinColumn({ name: "parentId" })
+    parent: Node
Evidence
The PR changes make deletedAt non-optional and non-null (deletedAt: Date), but soft-delete
columns are null for non-deleted rows; the repo has tests explicitly expecting delete-date columns
to be null when not deleted, and other entities model this as Date | null or optional. The PR
also makes a nullable FK column (@Column({ nullable: true })) be typed as number (non-null) and
the TreeParent relation parent typed as Node (non-null), even though root nodes have no parent
and therefore these values are null/undefined in practice.

test/functional/tree-tables/materialized-path/soft-delete-parent/entity/node.ts[12-33]
test/github-issues/10517/issue-10517.test.ts[74-85]
test/functional/relations/join-strategy/entity/SoftDeletedEditor.ts[8-18]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`test/functional/tree-tables/materialized-path/soft-delete-parent/entity/node.ts` declares fields as non-null that are nullable at runtime:
- `@DeleteDateColumn()` is `null` for non-deleted rows.
- `@Column({ nullable: true }) parentId` can be `null` for root nodes.
- `@TreeParent() parent` can be `null`/`undefined` for root nodes.

This makes the entity’s TypeScript types incorrect and can lead to runtime errors if the test/entity code assumes these are always defined.

### Issue Context
The repo contains tests that expect delete-date columns to be `null` when not deleted (e.g., `deletedDate: null` assertions), and other entities model delete-date columns as `Date | null`.

### Fix Focus Areas
- test/functional/tree-tables/materialized-path/soft-delete-parent/entity/node.ts[15-32]

### Suggested change
Adjust types to reflect nullability, for example:
- `deletedAt: Date | null` (or `deletedAt?: Date` depending on convention)
- `parentId: number | null` (or `parentId?: number`)
- `parent: Node | null` (or `parent?: Node | null`)

Keep the column decorators as-is (`nullable: true` remains correct).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants