Skip to content

Commit

Permalink
test: add test for issue typeorm#8450
Browse files Browse the repository at this point in the history
  • Loading branch information
maartensijmkens committed Jan 15, 2024
1 parent d44325d commit f9bfaf3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/github-issues/8450/entity/UserEntity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Entity } from "../../../../src/decorator/entity/Entity"
import { PrimaryColumn } from "../../../../src/decorator/columns/PrimaryColumn"
import { Column } from "../../../../src/decorator/columns/Column"

@Entity("user")
export class UserEntity {
@PrimaryColumn("int")
id: number

@Column({
type: "int",
generatedType: "STORED",
asExpression: "id * 2",
})
generated: number
}
38 changes: 38 additions & 0 deletions test/github-issues/8450/issue-8450.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import "reflect-metadata"
import {
closeTestingConnections,
createTestingConnections,
reloadTestingDatabases,
} from "../../utils/test-utils"
import { UserEntity } from "./entity/UserEntity"
import { expect } from "chai"
import { DataSource } from "../../../src"

describe("github issues > #8450 Generated column not in RETURNING clause on save", () => {
let connections: DataSource[]

before(
async () =>
(connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
enabledDrivers: ["postgres", "mysql"],
})),
)
beforeEach(() => reloadTestingDatabases(connections))
after(() => closeTestingConnections(connections))

it("should populate an object with generated column values after saving", () =>
Promise.all(
connections.map(async (connection) => {
const user = new UserEntity()
user.id = 100

expect(user.generated).to.be.undefined

await connection.manager.save(user)

expect(user.generated).to.be.a("number")
expect(user.generated).to.be.equal(user.id * 2)
}),
))
})

0 comments on commit f9bfaf3

Please sign in to comment.