/
geometry-column.ts
108 lines (84 loc) · 4.53 KB
/
geometry-column.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { expect } from "chai";
import "reflect-metadata";
import { Connection } from "../../../../src";
import {
closeTestingConnections,
createTestingConnections,
reloadTestingDatabases,
} from "../../../utils/test-utils";
import { FeatureWithoutSRID, FeatureWithSRID } from "./entity/Feature";
describe("column kinds > geometry column", () => {
let connections: Connection[];
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
enabledDrivers: ["mssql"]
}));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("geometry column with SRID defined should be saved without error for valid WKT input", () => Promise.all(connections.map(async connection => {
const featureRepository = connection.getRepository(FeatureWithSRID);
// save a new feature
const feature = new FeatureWithSRID();
feature.name = "feature";
feature.shape = "POINT (828365.16700000037 823377.14699999988)";
await featureRepository.save(feature);
// load and check if createdAt was a value set by us
const loadedfeature = await featureRepository.findOne();
expect(loadedfeature).to.be.not.empty;
expect(loadedfeature!.name).to.be.eql("feature");
expect(loadedfeature!.shape).to.be.eql("POINT (828365.16700000037 823377.14699999988)");
})));
it("geometry column with SRID defined should be updated without error for valid WKT input", () => Promise.all(connections.map(async connection => {
const featureRepository = connection.getRepository(FeatureWithSRID);
// save a new feature
const feature = new FeatureWithSRID();
feature.name = "feature";
feature.shape = "POINT (828365.16700000037 823377.14699999988)";
await featureRepository.save(feature);
// load and check if createdAt was a value set by us
const loadedfeature = await featureRepository.findOne();
expect(loadedfeature).to.be.not.empty;
expect(loadedfeature!.name).to.be.eql("feature");
expect(loadedfeature!.shape).to.be.eql("POINT (828365.16700000037 823377.14699999988)");
feature.shape = "POINT (728365.16700000037 723377.14699999988)";
await featureRepository.save(feature);
// load and check if createdAt is a date (generated by db)
const updatedfeature = await featureRepository.findOne();
expect(updatedfeature).to.be.not.empty;
expect(updatedfeature!.name).to.be.eql("feature");
expect(updatedfeature!.shape).to.be.eql("POINT (728365.16700000037 723377.14699999988)");
})));
it("geometry column with no SRID should be saved without error for valid WKT input", () => Promise.all(connections.map(async connection => {
const featureRepository = connection.getRepository(FeatureWithoutSRID);
// save a new feature
const feature = new FeatureWithoutSRID();
feature.name = "feature";
feature.shape = "POINT (0 0)";
await featureRepository.save(feature);
// load and check if createdAt is a date (generated by db)
const loadedfeature = await featureRepository.findOne();
expect(loadedfeature).to.be.not.empty;
expect(loadedfeature!.name).to.be.eql("feature");
expect(loadedfeature!.shape).to.be.eql("POINT (0 0)");
})));
it("geometry column with no SRID should be updated without error for valid WKT input", () => Promise.all(connections.map(async connection => {
const featureRepository = connection.getRepository(FeatureWithoutSRID);
// save a new feature
const feature = new FeatureWithoutSRID();
feature.name = "feature";
feature.shape = "POINT (0 0)";
await featureRepository.save(feature);
// load and check if createdAt is a date (generated by db)
const loadedfeature = await featureRepository.findOne();
expect(loadedfeature).to.be.not.empty;
expect(loadedfeature!.name).to.be.eql("feature");
expect(loadedfeature!.shape).to.be.eql("POINT (0 0)");
feature.shape = "POINT (0.5 0.5)";
await featureRepository.save(feature);
// load and check if createdAt is a date (generated by db)
const updatedfeature = await featureRepository.findOne();
expect(updatedfeature).to.be.not.empty;
expect(updatedfeature!.name).to.be.eql("feature");
expect(updatedfeature!.shape).to.be.eql("POINT (0.5 0.5)");
})));
});