-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
82 lines (77 loc) · 2.74 KB
/
index.test.js
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
const path = require("path");
const fs = require("fs");
const { createPool, sql } = require("slonik");
const { union } = require("./dist/index");
const { getExamplesCollection } = require("./scripts/debugging");
const EXAMPLES_DIR = "examples";
const connectionString =
process.env.DB || "postgres://docker:docker@localhost:54322/gis";
const pool = createPool(connectionString);
jest.setTimeout(10000);
describe("Run all examples", () => {
const examplesCollection = getExamplesCollection();
for (const feature of getExamplesCollection().features) {
test(feature.properties.name, async () => {
const filePath = path.join(
EXAMPLES_DIR,
`${feature.properties.name}.geojson`
);
const collection = JSON.parse(fs.readFileSync(filePath).toString());
expect(collection.features.length).toBeGreaterThan(0);
const output = union(collection, "_oid");
expect(output.features.length).toBeGreaterThan(0);
await pool.connect(async (connection) => {
await connection.transaction(async (t1) => {
await t1.query(sql`create table jest_input (geom Geometry);`);
await t1.query(
sql`create table jest_input_error_locations (location text);`
);
await t1.query(sql`create table jest_output (geom Geometry);`);
await t1.query(sql`
insert into jest_input (geom)
values ${sql.join(
collection.features.map(
(feature) =>
sql`(st_geomfromgeojson(${JSON.stringify(
feature.geometry
)}))`
),
", "
)}
`);
await t1.query(
sql`
insert into jest_input_error_locations (location)
select
ST_AsText(location(ST_IsValidDetail(geom)))
from jest_input where st_isvalid(geom) = false`
);
await t1.query(sql`
insert into jest_output (geom)
values ${sql.join(
output.features.map(
(feature) =>
sql`(st_geomfromgeojson(${JSON.stringify(
feature.geometry
)}))`
),
", "
)}
`);
const errors = await t1.oneFirst(
sql`select
count(*)
from jest_output
where
st_isvalid(geom) = false and
ST_AsText(location(ST_IsValidDetail(geom))) not in (
select location from jest_input_error_locations
)`
);
expect(errors).toBe(0);
await t1.query(sql`rollback`);
});
});
});
}
});