mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
added tests for #306
This commit is contained in:
parent
ee83f509a0
commit
04d287b23f
16
test/github-issues/306/entity/Duration.ts
Normal file
16
test/github-issues/306/entity/Duration.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import {Column} from "../../../../src/decorator/columns/Column";
|
||||
import {EmbeddableEntity} from "../../../../src/decorator/entity/EmbeddableEntity";
|
||||
|
||||
@EmbeddableEntity()
|
||||
export class Duration {
|
||||
|
||||
@Column({ name: "duration_minutes" })
|
||||
durationMinutes: number;
|
||||
|
||||
@Column({ name: "duration_hours" })
|
||||
durationHours: number;
|
||||
|
||||
@Column({ name: "duration_days" })
|
||||
durationDays: number;
|
||||
|
||||
}
|
||||
19
test/github-issues/306/entity/Race.ts
Normal file
19
test/github-issues/306/entity/Race.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import {Entity} from "../../../../src/decorator/entity/Entity";
|
||||
import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn";
|
||||
import {Column} from "../../../../src/decorator/columns/Column";
|
||||
import {Embedded} from "../../../../src/decorator/Embedded";
|
||||
import {Duration} from "./Duration";
|
||||
|
||||
@Entity()
|
||||
export class Race {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Embedded(type => Duration)
|
||||
duration: Duration;
|
||||
|
||||
}
|
||||
42
test/github-issues/306/issue-306.ts
Normal file
42
test/github-issues/306/issue-306.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import "reflect-metadata";
|
||||
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
|
||||
import {Connection} from "../../../src/connection/Connection";
|
||||
import {expect} from "chai";
|
||||
import {Race} from "./entity/Race";
|
||||
import {Duration} from "./entity/Duration";
|
||||
|
||||
describe.only("github issues > embeddeds with custom column name don't work", () => {
|
||||
|
||||
let connections: Connection[];
|
||||
before(async () => connections = await createTestingConnections({
|
||||
entities: [__dirname + "/entity/*{.js,.ts}"],
|
||||
schemaCreate: true,
|
||||
dropSchemaOnConnection: true,
|
||||
}));
|
||||
beforeEach(() => reloadTestingDatabases(connections));
|
||||
after(() => closeTestingConnections(connections));
|
||||
|
||||
it("embedded with custom column name should persist and load without errors", () => Promise.all(connections.map(async connection => {
|
||||
|
||||
const race = new Race();
|
||||
race.name = "National Race";
|
||||
race.duration = new Duration();
|
||||
race.duration.durationDays = 1;
|
||||
race.duration.durationHours = 10;
|
||||
race.duration.durationMinutes = 30;
|
||||
|
||||
await connection.entityManager.persist(race);
|
||||
|
||||
const loadedRace = await connection.entityManager.findOne(Race, { name: "National Race" });
|
||||
expect(loadedRace).to.be.not.empty;
|
||||
expect(loadedRace!.id).to.be.not.empty;
|
||||
expect(loadedRace!.duration).to.be.not.empty;
|
||||
loadedRace!.name.should.be.equal("National Race");
|
||||
loadedRace!.duration.should.be.instanceOf(Duration);
|
||||
loadedRace!.duration.durationDays.should.be.equal(1);
|
||||
loadedRace!.duration.durationHours.should.be.equal(10);
|
||||
loadedRace!.duration.durationMinutes.should.be.equal(30);
|
||||
|
||||
})));
|
||||
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user