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: add test for issue typeorm#8450
- Loading branch information
1 parent
d44325d
commit f9bfaf3
Showing
2 changed files
with
54 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,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 | ||
} |
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 { | ||
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) | ||
}), | ||
)) | ||
}) |