Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make EntityMetadataValidator comply with entitySkipConstructor, …
- Loading branch information
1 parent
09f54e0
commit 3d6c5da
Showing
3 changed files
with
64 additions
and
1 deletion.
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
18 changes: 18 additions & 0 deletions
18
test/github-issues/8444/entity/StrictlyInitializedEntity.ts
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,18 @@ | ||
import {Column, Entity, PrimaryGeneratedColumn} from "../../../../src"; | ||
|
||
@Entity() | ||
export class StrictlyInitializedEntity { | ||
@PrimaryGeneratedColumn() | ||
id?: number; | ||
|
||
@Column() | ||
readonly someColumn: string; | ||
|
||
constructor(someColumn: string) { | ||
if (someColumn === undefined) { | ||
throw new Error("someColumn cannot be undefined."); | ||
} | ||
|
||
this.someColumn = someColumn; | ||
} | ||
} |
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,45 @@ | ||
import "reflect-metadata"; | ||
import { expect } from "chai"; | ||
import {closeTestingConnections, createTestingConnections} from "../../utils/test-utils"; | ||
import {StrictlyInitializedEntity} from "./entity/StrictlyInitializedEntity"; | ||
import { Connection } from "../../../src/connection/Connection"; | ||
|
||
describe("github issues > #8444 entitySkipConstructor not working", () => { | ||
|
||
describe("without entitySkipConstructor", () => { | ||
|
||
it("createTestingConnections should fail with 'someColumn cannot be undefined.'", async () => { | ||
async function bootstrapWithoutEntitySkipConstructor(): Promise<Connection[]> { | ||
return await createTestingConnections({ | ||
driverSpecific: { | ||
entitySkipConstructor: false, | ||
}, | ||
entities: [ StrictlyInitializedEntity ], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
}); | ||
} | ||
|
||
await expect(bootstrapWithoutEntitySkipConstructor()) | ||
.to.be.rejectedWith("someColumn cannot be undefined"); | ||
}); | ||
}); | ||
|
||
|
||
describe("with entitySkipConstructor", () => { | ||
|
||
let connections: Connection[] = []; | ||
afterEach(() => closeTestingConnections(connections)); | ||
|
||
it("createTestingConnections should succeed", async () => { | ||
connections = await createTestingConnections({ | ||
driverSpecific: { | ||
entitySkipConstructor: true, | ||
}, | ||
entities: [ StrictlyInitializedEntity ], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
}); | ||
}); | ||
}); | ||
}); |