|
| 1 | +import "reflect-metadata"; |
| 2 | +import { expect } from "chai"; |
| 3 | +import { closeTestingConnections, createTestingConnections, reloadTestingDatabases } from "../../utils/test-utils"; |
| 4 | +import { Connection } from "../../../src/connection/Connection"; |
| 5 | +import {User} from "../../functional/query-builder/update/entity/User"; |
| 6 | +import {EntityColumnNotFound} from "../../../src/error/EntityColumnNotFound"; |
| 7 | + |
| 8 | +describe("github issues > #3416 Unknown fields are stripped from WHERE clause", () => { |
| 9 | + |
| 10 | + let connections: Connection[]; |
| 11 | + before(async () => connections = await createTestingConnections({ |
| 12 | + entities: [User] |
| 13 | + })); |
| 14 | + beforeEach(() => reloadTestingDatabases(connections)); |
| 15 | + after(() => closeTestingConnections(connections)); |
| 16 | + |
| 17 | + describe("should throw EntityColumnNotFound when supplying unknown property in where criteria", () => { |
| 18 | + it("find", () => Promise.all(connections.map(async connection => { |
| 19 | + let error: Error | undefined; |
| 20 | + try { |
| 21 | + // @ts-ignore |
| 22 | + await connection.manager.findOne(User, {unknownProp: "John Doe"}); |
| 23 | + } catch (err) { |
| 24 | + error = err; |
| 25 | + } |
| 26 | + expect(error).to.be.an.instanceof(EntityColumnNotFound); |
| 27 | + }))); |
| 28 | + it("update", () => Promise.all(connections.map(async connection => { |
| 29 | + let error: Error | undefined; |
| 30 | + try { |
| 31 | + await connection.manager.update(User, { unknownProp: "Something" }, { name: "John doe "}); |
| 32 | + } catch (err) { |
| 33 | + error = err; |
| 34 | + } |
| 35 | + expect(error).to.be.an.instanceof(EntityColumnNotFound); |
| 36 | + }))); |
| 37 | + it("delete", () => Promise.all(connections.map(async connection => { |
| 38 | + let error: Error | undefined; |
| 39 | + try { |
| 40 | + await connection.manager.delete(User, { unknownProp: "Something" }); |
| 41 | + } catch (err) { |
| 42 | + error = err; |
| 43 | + } |
| 44 | + expect(error).to.be.an.instanceof(EntityColumnNotFound); |
| 45 | + }))); |
| 46 | + }); |
| 47 | +}); |
0 commit comments