fix: insert and update query builder to handle mssql geometry column … · typeorm/typeorm@87cc6f4
1+import { expect } from "chai";
2+import "reflect-metadata";
3+import { Connection } from "../../../../src";
4+import {
5+closeTestingConnections,
6+createTestingConnections,
7+reloadTestingDatabases,
8+} from "../../../utils/test-utils";
9+import { FeatureWithoutSRID, FeatureWithSRID } from "./entity/Feature";
10+11+describe("column kinds > geometry column", () => {
12+13+let connections: Connection[];
14+before(async () => connections = await createTestingConnections({
15+entities: [__dirname + "/entity/*{.js,.ts}"],
16+enabledDrivers: ["mssql"]
17+}));
18+beforeEach(() => reloadTestingDatabases(connections));
19+after(() => closeTestingConnections(connections));
20+21+22+23+it("geometry column with SRID defined should be saved without error for valid WKT input", () => Promise.all(connections.map(async connection => {
24+const featureRepository = connection.getRepository(FeatureWithSRID);
25+26+// save a new feature
27+const feature = new FeatureWithSRID();
28+feature.name = "feature";
29+feature.shape = "POINT (828365.16700000037 823377.14699999988)";
30+await featureRepository.save(feature);
31+32+// load and check if createdAt was a value set by us
33+const loadedfeature = await featureRepository.findOne();
34+expect(loadedfeature).to.be.not.empty;
35+expect(loadedfeature!.name).to.be.eql("feature");
36+expect(loadedfeature!.shape).to.be.eql("POINT (828365.16700000037 823377.14699999988)");
37+38+})));
39+40+it("geometry column with SRID defined should be updated without error for valid WKT input", () => Promise.all(connections.map(async connection => {
41+const featureRepository = connection.getRepository(FeatureWithSRID);
42+43+// save a new feature
44+const feature = new FeatureWithSRID();
45+feature.name = "feature";
46+feature.shape = "POINT (828365.16700000037 823377.14699999988)";
47+await featureRepository.save(feature);
48+49+// load and check if createdAt was a value set by us
50+const loadedfeature = await featureRepository.findOne();
51+expect(loadedfeature).to.be.not.empty;
52+expect(loadedfeature!.name).to.be.eql("feature");
53+expect(loadedfeature!.shape).to.be.eql("POINT (828365.16700000037 823377.14699999988)");
54+55+feature.shape = "POINT (728365.16700000037 723377.14699999988)";
56+await featureRepository.save(feature);
57+58+// load and check if createdAt is a date (generated by db)
59+const updatedfeature = await featureRepository.findOne();
60+expect(updatedfeature).to.be.not.empty;
61+expect(updatedfeature!.name).to.be.eql("feature");
62+expect(updatedfeature!.shape).to.be.eql("POINT (728365.16700000037 723377.14699999988)");
63+64+})));
65+66+it("geometry column with no SRID should be saved without error for valid WKT input", () => Promise.all(connections.map(async connection => {
67+const featureRepository = connection.getRepository(FeatureWithoutSRID);
68+69+// save a new feature
70+const feature = new FeatureWithoutSRID();
71+feature.name = "feature";
72+feature.shape = "POINT (0 0)";
73+await featureRepository.save(feature);
74+75+// load and check if createdAt is a date (generated by db)
76+const loadedfeature = await featureRepository.findOne();
77+expect(loadedfeature).to.be.not.empty;
78+expect(loadedfeature!.name).to.be.eql("feature");
79+expect(loadedfeature!.shape).to.be.eql("POINT (0 0)");
80+})));
81+82+it("geometry column with no SRID should be updated without error for valid WKT input", () => Promise.all(connections.map(async connection => {
83+const featureRepository = connection.getRepository(FeatureWithoutSRID);
84+85+// save a new feature
86+const feature = new FeatureWithoutSRID();
87+feature.name = "feature";
88+feature.shape = "POINT (0 0)";
89+await featureRepository.save(feature);
90+91+// load and check if createdAt is a date (generated by db)
92+const loadedfeature = await featureRepository.findOne();
93+expect(loadedfeature).to.be.not.empty;
94+expect(loadedfeature!.name).to.be.eql("feature");
95+expect(loadedfeature!.shape).to.be.eql("POINT (0 0)");
96+97+feature.shape = "POINT (0.5 0.5)";
98+await featureRepository.save(feature);
99+100+// load and check if createdAt is a date (generated by db)
101+const updatedfeature = await featureRepository.findOne();
102+expect(updatedfeature).to.be.not.empty;
103+expect(updatedfeature!.name).to.be.eql("feature");
104+expect(updatedfeature!.shape).to.be.eql("POINT (0.5 0.5)");
105+106+})));
107+108+});