forked from typeorm/typeorm
/
issue-3111.ts
30 lines (26 loc) · 1.49 KB
/
issue-3111.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import "reflect-metadata";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
import {Connection} from "../../../src/connection/Connection";
import {expect} from "chai";
import {InsertValuesMissingError} from "../../../src/error/InsertValuesMissingError";
import {Test, DEFAULT_VALUE} from "./entity/Test";
describe("github issues > #3111 Inserting with query builder attempts to insert a default row when values is empty array", () => {
let connections: Connection[];
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchema: true,
}));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("should not insert with default values on .values([])", () => Promise.all(connections.map(async connection => {
const repo = connection.getRepository(Test);
await repo.createQueryBuilder().insert().values([]).execute();
const rowsWithDefaultValue = await repo.find({ where: {value: DEFAULT_VALUE}});
expect(rowsWithDefaultValue).to.have.lengthOf(0);
})));
it("should still error on missing .values()", () => Promise.all(connections.map(async connection => {
const repo = connection.getRepository(Test);
await repo.createQueryBuilder().insert().execute().should.be.rejectedWith(InsertValuesMissingError);
})));
});