@opengis/gis 0.2.208 → 0.2.209

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/README.md +181 -181
  2. package/dist/{CardIcon-iGo8QJu9.js → CardIcon-B6rIgAoD.js} +1 -1
  3. package/dist/{EntityTablePage-BiVoVAhN.js → EntityTablePage-CfLq5znM.js} +2 -2
  4. package/dist/{ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-BdL5cQgN.js → ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-CB_4eJz9.js} +1 -1
  5. package/dist/{MapSettings-CXqiYxV4.js → MapSettings-fwcVWgdK.js} +2 -2
  6. package/dist/{MapToolbarRight.vue_vue_type_script_setup_true_lang-BHCChxmg.js → MapToolbarRight.vue_vue_type_script_setup_true_lang-BWqBARGq.js} +1 -1
  7. package/dist/{RastersTablePage-Dgk1wp3d.js → RastersTablePage-XHV40tf_.js} +2 -2
  8. package/dist/{cartocss-BIpgQU6F.js → cartocss-BjGlng_r.js} +526 -503
  9. package/dist/{import-utils-CfXKgZFd.js → import-utils-WfWvX9B5.js} +1 -1
  10. package/dist/{index-CM_DTEUa.js → index-CDy0MSfg.js} +3509 -3461
  11. package/dist/index.css +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/index.umd.cjs +42 -48
  14. package/dist/{raster-D_vEBha8.js → raster-D2X_jR9m.js} +3 -3
  15. package/dist/{register-C5_Un1Ms.js → register-Ctn9pgUE.js} +3 -3
  16. package/dist/service-CiUwLEwY.js +3484 -0
  17. package/dist/{vs-datatable--K-DxayK.js → vs-datatable-BixMLOv-.js} +4 -3
  18. package/module/gis/card/gis.metadata.table/index.yml +22 -22
  19. package/module/gis/card/gis.rasters.table/index.yml +11 -11
  20. package/module/gis/card/gis.registers.table/index.yml +23 -23
  21. package/module/gis/card/gis.services.table/index.yml +25 -25
  22. package/module/gis/cls/bool.yes_no.json +12 -12
  23. package/module/gis/cls/encoding.json +14 -14
  24. package/module/gis/cls/geom_type.json +14 -14
  25. package/module/gis/cls/gis.column_type.json +34 -34
  26. package/module/gis/cls/gis.column_view_type.json +26 -26
  27. package/module/gis/cls/gis.filter_type.json +22 -22
  28. package/module/gis/cls/language.json +10 -10
  29. package/module/gis/cls/meta.service_type.json +42 -42
  30. package/module/gis/cls/ogc.service.json +21 -21
  31. package/module/gis/cls/service_type.json +42 -42
  32. package/module/gis/cls/source_type.json +10 -10
  33. package/module/gis/cls/standarts.json +6 -6
  34. package/module/gis/cls/topic_category.json +106 -106
  35. package/module/gis/cls/update_frequency.json +29 -29
  36. package/module/gis/cls/view.json +21 -21
  37. package/module/gis/form/feedback.answer.form.json +10 -10
  38. package/module/gis/form/gis.cartocss.form.json +64 -64
  39. package/module/gis/form/gis.group_list.form.json +17 -17
  40. package/module/gis/form/gis.maps.form.json +61 -61
  41. package/module/gis/form/gis.metadata.form.json +240 -240
  42. package/module/gis/form/gis.metadata_new.form.json +195 -195
  43. package/module/gis/form/gis.ogc_service.form.json +51 -51
  44. package/module/gis/form/gis.rasters.form.json +76 -76
  45. package/module/gis/form/gis.registers.form.json +127 -127
  46. package/module/gis/form/gis.registers_column.form.json +84 -84
  47. package/module/gis/form/gis.registers_filter.form.json +65 -65
  48. package/module/gis/form/gis.services.form.json +111 -111
  49. package/module/gis/form/gis.services_attributes.form.json +75 -75
  50. package/module/gis/form/gis.services_filter.form.json +65 -65
  51. package/module/gis/menu.json +43 -43
  52. package/module/gis/select/admin.cls.name.sql +9 -9
  53. package/module/gis/select/layer_list.sql +7 -7
  54. package/module/gis/select/layer_list_text.sql +7 -7
  55. package/module/gis/select/pg.column_name.geometry.sql +12 -12
  56. package/module/gis/select/pg.columns.parent.sql +6 -6
  57. package/module/gis/select/pg.table_name.sql +17 -17
  58. package/module/gis/select/service_id.sql +1 -1
  59. package/module/gis/select/srid.sql +7 -7
  60. package/module/gis/table/gis.cartocss.table.json +74 -74
  61. package/module/gis/table/gis.group_list.table.json +58 -58
  62. package/module/gis/table/gis.maps.table.json +110 -110
  63. package/module/gis/table/gis.metadata.table.json +70 -70
  64. package/module/gis/table/gis.metadata_new.table.json +137 -137
  65. package/module/gis/table/gis.ogc_service.table.json +100 -100
  66. package/module/gis/table/gis.rasters.table.json +113 -113
  67. package/module/gis/table/gis.registers.table.json +143 -143
  68. package/module/gis/table/gis.services.table.json +120 -120
  69. package/module/gis/table/site.gis.registers.table.json +88 -88
  70. package/module/gis/table/site.gis.services.table.json +106 -106
  71. package/module/gis/templates/ISO19136_2017_gml_template.xml +330 -330
  72. package/module/gis/tokens.yml +5 -5
  73. package/module/permissions/form/permissions.users.form.json +151 -151
  74. package/module/permissions/table/gis.permissions.table.json +97 -97
  75. package/module/test/map/addr.json +302 -302
  76. package/module/test/map/addr1.yml +23 -23
  77. package/module/test/select/address.str_id.sql +3 -3
  78. package/package.json +79 -79
  79. package/plugin.js +64 -64
  80. package/server/migrations/array_intersect.sql +13 -13
  81. package/server/migrations/cartocss.sql +27 -27
  82. package/server/migrations/group_list.sql +74 -74
  83. package/server/migrations/maps.sql +30 -30
  84. package/server/migrations/metadata.sql +415 -415
  85. package/server/migrations/ogc.sql +106 -106
  86. package/server/migrations/rasters.sql +265 -265
  87. package/server/migrations/services.sql +248 -248
  88. package/server/migrations/services_users_rel.sql +22 -22
  89. package/server/migrations/widgets.sql +20 -20
  90. package/server/plugins/crons.js +21 -21
  91. package/server/plugins/mapnik/funcs/checkRasterFile.js +107 -107
  92. package/server/plugins/mapnik/funcs/mapnik.js +151 -151
  93. package/server/plugins/mapnik/funcs/rootFolder.mjs +8 -8
  94. package/server/plugins/mapnik/map.proto +437 -437
  95. package/server/plugins/vite.js +74 -74
  96. package/server/routes/cartocss/cartocss.route.js +31 -31
  97. package/server/routes/cartocss/cartocss.route.test.js +78 -78
  98. package/server/routes/cartocss/cartocss.schema.js +76 -76
  99. package/server/routes/cartocss/functions/add.cartocss.js +39 -39
  100. package/server/routes/cartocss/functions/get.cartocss.js +57 -57
  101. package/server/routes/gis/functions/checkXML.js +107 -107
  102. package/server/routes/gis/functions/dashboard.js +24 -24
  103. package/server/routes/gis/gis.route.js +26 -26
  104. package/server/routes/gis/gis.route.test.js +33 -33
  105. package/server/routes/map/fonts/index.js +1933 -1933
  106. package/server/routes/map/functions/clearTiles.js +35 -35
  107. package/server/routes/map/functions/geojson.js +187 -187
  108. package/server/routes/map/functions/gis.convert.js +65 -65
  109. package/server/routes/map/functions/gis.icon.js +327 -327
  110. package/server/routes/map/functions/jsonData.js +206 -206
  111. package/server/routes/map/functions/layerList.js +144 -144
  112. package/server/routes/map/functions/map.js +122 -122
  113. package/server/routes/map/functions/mapCatalog.js +72 -72
  114. package/server/routes/map/functions/mapCatalogAttribute.js +53 -53
  115. package/server/routes/map/functions/mapFeatures.js +133 -133
  116. package/server/routes/map/functions/mapFormat.js +246 -246
  117. package/server/routes/map/functions/mapTiles.js +162 -162
  118. package/server/routes/map/functions/maps.js +15 -15
  119. package/server/routes/map/functions/marker_icon.js +43 -43
  120. package/server/routes/map/functions/parseGeoFile.js +85 -85
  121. package/server/routes/map/functions/pointHeight.js +51 -51
  122. package/server/routes/map/functions/vtile.js +174 -174
  123. package/server/routes/map/functions/vtile1.js +191 -191
  124. package/server/routes/map/map.route.js +283 -283
  125. package/server/routes/map/map.route.test.js +693 -693
  126. package/server/routes/map/map.schema.js +356 -356
  127. package/server/routes/map/pin/circle1.svg +76 -76
  128. package/server/routes/map/pin/circle2.svg +18 -18
  129. package/server/routes/map/pin/none.svg +12 -12
  130. package/server/routes/map/pin/pin.svg +14 -14
  131. package/server/routes/map/pin/pin1.svg +16 -16
  132. package/server/routes/map/pin/pin2.svg +7 -7
  133. package/server/routes/map/pin/pin3.svg +34 -34
  134. package/server/routes/map/pin/pin4.svg +14 -14
  135. package/server/routes/map/pin/pin5.svg +7 -7
  136. package/server/routes/map/pin/pin6.svg +12 -12
  137. package/server/routes/map/pin/pin7.svg +12 -12
  138. package/server/routes/mapnik/functions/cartoBounds.js +32 -32
  139. package/server/routes/mapnik/functions/clearTiles.js +103 -103
  140. package/server/routes/mapnik/functions/convertBoundToTile.js +27 -27
  141. package/server/routes/mapnik/functions/createXml.js +76 -76
  142. package/server/routes/mapnik/functions/createXmlMulti.js +72 -72
  143. package/server/routes/mapnik/functions/fileSearch.js +35 -35
  144. package/server/routes/mapnik/functions/fileStat.js +28 -28
  145. package/server/routes/mapnik/functions/pretile.js +138 -138
  146. package/server/routes/mapnik/functions/rasterInfo.js +66 -66
  147. package/server/routes/mapnik/functions/readDir.js +22 -22
  148. package/server/routes/mapnik/functions/rtile.js +164 -164
  149. package/server/routes/mapnik/functions/uploadRaster.js +152 -152
  150. package/server/routes/mapnik/functions/uploadXML.js +140 -140
  151. package/server/routes/mapnik/mapnik.route.js +102 -102
  152. package/server/routes/mapnik/mapnik.route.test.js +370 -370
  153. package/server/routes/mapnik/mapnik.schema.mjs +195 -195
  154. package/server/routes/mapnik.prefixless/functions/mapnikLogger.js +31 -31
  155. package/server/routes/mapnik.prefixless/functions/mapnikStat.js +21 -21
  156. package/server/routes/mapnik.prefixless/mapnik.prefixless.route.js +20 -20
  157. package/server/routes/mapnik.prefixless/mapnik.prefixless.route.test.js +91 -91
  158. package/server/routes/mapnik.prefixless/mapnik.prefixless.schema.mjs +27 -27
  159. package/server/routes/maps/functions/add.map.js +42 -42
  160. package/server/routes/maps/functions/del.map.js +17 -17
  161. package/server/routes/maps/functions/get.map.js +119 -119
  162. package/server/routes/maps/maps.route.js +58 -58
  163. package/server/routes/maps/maps.route.test.js +231 -231
  164. package/server/routes/maps/maps.schema.js +9 -9
  165. package/server/routes/metadata/functions/editMetadata.js +35 -35
  166. package/server/routes/metadata/functions/metadataXML.js +19 -19
  167. package/server/routes/metadata/metadata.route.js +26 -26
  168. package/server/routes/metadata/metadata.route.test.js +46 -46
  169. package/server/routes/metadata/metadata.schema.js +53 -53
  170. package/server/routes/ogc/functions/map.info.point.js +117 -117
  171. package/server/routes/ogc/ogc.route.js +21 -21
  172. package/server/routes/ogc/ogc.route.test.js +53 -53
  173. package/server/routes/ogc/ogc.schema.js +16 -16
  174. package/server/routes/permissions/functions/catalog.permissions.edit.js +20 -20
  175. package/server/routes/permissions/functions/catalog.permissions.js +12 -12
  176. package/server/routes/permissions/functions/get.permissions.js +59 -59
  177. package/server/routes/permissions/functions/gis.catalog.js +80 -80
  178. package/server/routes/permissions/permissions.route.js +35 -35
  179. package/server/routes/permissions/permissions.route.test.js +35 -35
  180. package/server/routes/permissions/permissions.schema.js +43 -43
  181. package/server/routes/registers/functions/add.registry.js +37 -37
  182. package/server/routes/registers/functions/classifiers.js +100 -100
  183. package/server/routes/registers/functions/columns.js +3 -3
  184. package/server/routes/registers/functions/content.type.js +9 -9
  185. package/server/routes/registers/functions/del.registry.js +14 -14
  186. package/server/routes/registers/functions/get.info.js +93 -93
  187. package/server/routes/registers/functions/getFilterSQLParametrized/formatValue.js +328 -328
  188. package/server/routes/registers/functions/getFilterSQLParametrized/getFilterQuery.js +126 -126
  189. package/server/routes/registers/functions/getFilterSQLParametrized/getRangeQuery.js +353 -353
  190. package/server/routes/registers/functions/getFilterSQLParametrized/index.js +81 -81
  191. package/server/routes/registers/functions/getTableColumnMeta.js +148 -148
  192. package/server/routes/registers/functions/gis.export.js +159 -159
  193. package/server/routes/registers/functions/gis.registry.js +71 -71
  194. package/server/routes/registers/functions/gis.registry.list.js +61 -61
  195. package/server/routes/registers/functions/gis.suggest.js +310 -310
  196. package/server/routes/registers/functions/handleRegistryRequest.js +178 -178
  197. package/server/routes/registers/functions/map.registry.js +87 -87
  198. package/server/routes/registers/registers.route.js +92 -92
  199. package/server/routes/registers/registers.route.test.js +173 -173
  200. package/server/routes/registers/registers.schema.js +276 -276
  201. package/server/routes/root.mjs +3 -3
  202. package/server/routes/services/functions/add.service.js +62 -62
  203. package/server/routes/services/functions/create.route.js +93 -93
  204. package/server/routes/services/functions/del.service.js +12 -12
  205. package/server/routes/services/functions/get.layer.geom.js +27 -27
  206. package/server/routes/services/functions/get.service.users.js +76 -76
  207. package/server/routes/services/functions/get.services.col.js +34 -34
  208. package/server/routes/services/functions/get.services.js +124 -124
  209. package/server/routes/services/functions/legend.auto.js +77 -77
  210. package/server/routes/services/services.route.js +76 -76
  211. package/server/routes/services/services.route.test.js +171 -171
  212. package/server/routes/services/services.schema.js +459 -459
  213. package/server/routes/widgets/functions/add.widget.js +38 -38
  214. package/server/routes/widgets/functions/del.widget.js +17 -17
  215. package/server/routes/widgets/functions/get.widget.js +41 -41
  216. package/server/routes/widgets/widgets.route.js +61 -61
  217. package/server/routes/widgets/widgets.route.test.js +144 -144
  218. package/server/routes/widgets/widgets.schema.js +24 -24
  219. package/server/shared/listFiles.js +14 -14
  220. package/utils.js +13 -13
  221. package/dist/service-JN82JN81.js +0 -3676
@@ -1,693 +1,693 @@
1
- import { describe, test, beforeAll, expect } from 'vitest';
2
-
3
- import { getTemplate, getPGAsync, uploadFile, isFileExists } from '@opengis/fastify-table/utils.js';
4
-
5
- import { build, injectWithHeaders } from '../../../test/helper.js';
6
-
7
- const user = { id: '1', type: 'admin' };
8
-
9
- let pg;
10
- let addr = {};
11
-
12
- // base64 from ziped shapefile for /gis-convert api
13
- const base64 = `UEsDBBQAAAAAAMVDBV2t8XCrgwAAAIMAAAAJAAAAcG9pbnQucHJqR0VPR0NTWyJXR1MgODQiLERBVFVNWyJXR1NfMTk4NCIsU1BIRVJPSURbIldHUyA4NCIsNjM3ODEzNywyOTguMjU3MjIzNTYzXV0sUFJJTUVNWyJHcmVlbndpY2giLDBdLFVOSVRbImRlZ3JlZSIsMC4wMTc0NTMyOTI1MTk5NDMzXV1QSwMEFAAAAAAAxUMFXeUBOGx0AAAAdAAAAAkAAABwb2ludC5kYmYDfggFAQAAAEEAMwAAAAAAAAAAAAAAAAAAAAAAAAAAAGlkAAAAAAAAAAAATgAAAAAyAAAAAAAAAAAAAAAAAAAADSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgMVBLAwQUAAAAAADFQwVdjfPd44AAAACAAAAACQAAAHBvaW50LnNocAAAJwoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEDoAwAAAQAAAPW52or9hT5A/fZ14Jw5SUD1udqK/YU+QP32deCcOUlAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAACgEAAAD1udqK/YU+QP32deCcOUlAUEsDBBQAAAAAAMVDBV0HI9CqbAAAAGwAAAAJAAAAcG9pbnQuc2h4AAAnCgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANugDAAABAAAA9bnaiv2FPkD99nXgnDlJQPW52or9hT5A/fZ14Jw5SUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADIAAAAKUEsBAhQDFAAAAAAAxUMFXa3xcKuDAAAAgwAAAAkAAAAAAAAAAAAAAKSBAAAAAHBvaW50LnByalBLAQIUAxQAAAAAAMVDBV3lAThsdAAAAHQAAAAJAAAAAAAAAAAAAACkgaoAAABwb2ludC5kYmZQSwECFAMUAAAAAADFQwVdjfPd44AAAACAAAAACQAAAAAAAAAAAAAApIFFAQAAcG9pbnQuc2hwUEsBAhQDFAAAAAAAxUMFXQcj0KpsAAAAbAAAAAkAAAAAAAAAAAAAAKSB7AEAAHBvaW50LnNoeFBLBQYAAAAABAAEANwAAAB/AgAAAAA=`;
14
-
15
- describe('map api test', () => {
16
- beforeAll(async () => {
17
- await build();
18
- pg = await getPGAsync();
19
-
20
- // preload an address row for map-feature tests
21
- if (pg.pk?.['data_address.address']) {
22
- addr = await pg
23
- .query('select addr_id, st_x(geom), st_y(geom) from data_address.address where geom is not null limit 1')
24
- .then(r => r.rows?.[0] || {});
25
- expect(!!addr.addr_id).toBeTruthy();
26
- }
27
- });
28
-
29
- test('GET /map-catalog', async () => {
30
- const res = await injectWithHeaders({ method: 'GET', url: '/api/map-catalog' });
31
- expect(res.statusCode).toBe(200);
32
- const rep = res.json();
33
- expect(Array.isArray(rep.rasters)).toBeTruthy();
34
- expect(Array.isArray(rep.services)).toBeTruthy();
35
- });
36
-
37
- test('GET /marker-icon/*', async () => {
38
- // latest changes break local icon generation
39
- const res = await injectWithHeaders({
40
- method: 'GET',
41
- // url: `/api/marker-icon/pin6-m-fa-space-shuttle+teal.png`,
42
- url: '/api/marker-icon/icon-l-fa-location-dot+ff0000.svg',
43
- headers: { uid: user.id, user_type: user.type }
44
- });
45
- if (res.statusCode === 200) {
46
- expect(res.statusCode).toBe(200);
47
- expect(res.body.includes('PNG')).toBeTruthy();
48
- expect(res.rawPayload?.length).toBeTruthy();
49
- } else {
50
- expect(res.statusCode).toBe(404);
51
- expect(res.body.message).toMatch('icon not found');
52
- }
53
- }, 15000);
54
-
55
- test('GET /gis-icon/*', async () => {
56
- const res = await injectWithHeaders({
57
- method: 'GET',
58
- url: `/api/gis-icon/pin6-m-fa-plus-square+7ed957.png`,
59
- query: { nocache: 1 },
60
- headers: { uid: user.id, user_type: user.type }
61
- });
62
- expect(res.statusCode).toBe(200);
63
- expect(res.headers['content-type']).toBe('image/png');
64
- expect(res.body.includes('PNG')).toBeTruthy();
65
- });
66
-
67
- test('GET /icon/*', async () => {
68
- const res = await injectWithHeaders({
69
- method: 'GET',
70
- url: `/api/icon/pin6-m-fa-plus-square+7ed957.png`,
71
- query: { nocache: 1 },
72
- headers: { uid: user.id, user_type: user.type }
73
- });
74
- expect(res.statusCode).toBe(200);
75
- expect(res.headers['content-type']).toBe('image/png');
76
- expect(res.body.includes('PNG')).toBeTruthy();
77
- });
78
-
79
- test('GET /gis-icon/*.svg', async () => {
80
- const res = await injectWithHeaders({
81
- method: 'GET',
82
- url: `/api/gis-icon/pin6-m-fa-plus-square+7ed957.svg`,
83
- query: { nocache: 1 },
84
- headers: { uid: user.id, user_type: user.type }
85
- });
86
- expect(res.statusCode).toBe(200);
87
- expect(res.headers['content-type']).toBe('image/svg+xml');
88
- expect(res.body).toContain('<svg');
89
- expect(res.body).toContain('viewBox="0 0 446 518"');
90
- });
91
-
92
- test('GET /gis-icon/ar-* renders a symbol', async () => {
93
- const res = await injectWithHeaders({
94
- method: 'GET',
95
- url: `/api/gis-icon/pin6-m-ar-E+ff4500.svg`,
96
- query: { nocache: 1 },
97
- headers: { uid: user.id, user_type: user.type }
98
- });
99
- expect(res.statusCode).toBe(200);
100
- expect(res.headers['content-type']).toBe('image/svg+xml');
101
- expect(res.body).toContain('>E</text>');
102
- expect(res.body).toContain('fill="#ff4500"');
103
- expect(res.body).not.toContain('#ff0000');
104
- });
105
-
106
- test.each(['pin2', 'pin3', 'pin4', 'pin5', 'pin6', 'pin7'])(
107
- 'GET /gis-icon/%s recolors the background',
108
- async (pin) => {
109
- const res = await injectWithHeaders({
110
- method: 'GET',
111
- url: `/api/gis-icon/${pin}-m-fa-plus-square+7ed957.svg`,
112
- query: { nocache: 1 },
113
- headers: { uid: user.id, user_type: user.type }
114
- });
115
- expect(res.statusCode).toBe(200);
116
- expect(res.body).not.toContain('#ff0000');
117
- expect(res.body).toContain('fill="#7ed957"');
118
- expect(res.body.lastIndexOf('data-gis-icon-layer="foreground"'))
119
- .toBeGreaterThan(res.body.lastIndexOf('<use'));
120
- },
121
- );
122
-
123
- test.each([
124
- ['pin', '#ff0000'],
125
- ['pin1', '#ff0000'],
126
- ['circle1', '#176e1c'],
127
- ['circle2', '#ff0000'],
128
- ['none', 'fill="red"'],
129
- ])(
130
- 'GET /gis-icon/%s keeps the original background',
131
- async (pin, backgroundColor) => {
132
- const res = await injectWithHeaders({
133
- method: 'GET',
134
- url: `/api/gis-icon/${pin}-m-fa-plus-square+7ed957.svg`,
135
- query: { nocache: 1 },
136
- headers: { uid: user.id, user_type: user.type }
137
- });
138
- expect(res.statusCode).toBe(200);
139
- expect(res.body).toContain(backgroundColor);
140
- expect(res.body).toContain('fill="#7ed957"');
141
- expect(res.body.lastIndexOf('data-gis-icon-layer="foreground"'))
142
- .toBeGreaterThan(res.body.lastIndexOf('<use'));
143
- },
144
- );
145
-
146
- test('GET /gis-icon with typicons font (ty)', async () => {
147
- const res = await injectWithHeaders({
148
- method: 'GET',
149
- url: `/api/gis-icon/pin-m-ty-anchor+ff0000.svg`,
150
- query: { nocache: 1 },
151
- headers: { uid: user.id, user_type: user.type }
152
- });
153
- expect(res.statusCode).toBe(200);
154
- expect(res.headers['content-type']).toBe('image/svg+xml');
155
- expect(res.body).toContain('<svg');
156
- expect(res.body).toContain('fill="#ff0000"');
157
- });
158
-
159
- test('GET /gis-icon with maki font (ma)', async () => {
160
- const res = await injectWithHeaders({
161
- method: 'GET',
162
- url: `/api/gis-icon/pin-m-ma-zoo+00ff00.svg`,
163
- query: { nocache: 1 },
164
- headers: { uid: user.id, user_type: user.type }
165
- });
166
- expect(res.statusCode).toBe(200);
167
- expect(res.headers['content-type']).toBe('image/svg+xml');
168
- expect(res.body).toContain('<svg');
169
- expect(res.body).toContain('fill="#00ff00"');
170
- });
171
-
172
- test('GET /gis-icon with fontawesome font (fa)', async () => {
173
- const res = await injectWithHeaders({
174
- method: 'GET',
175
- url: `/api/gis-icon/pin-m-fa-heart+ff0000.svg`,
176
- query: { nocache: 1 },
177
- headers: { uid: user.id, user_type: user.type }
178
- });
179
- expect(res.statusCode).toBe(200);
180
- expect(res.headers['content-type']).toBe('image/svg+xml');
181
- expect(res.body).toContain('<svg');
182
- expect(res.body).toContain('fill="#ff0000"');
183
- });
184
-
185
- test('GET /gis-icon with map icons font (mi)', async () => {
186
- const res = await injectWithHeaders({
187
- method: 'GET',
188
- url: `/api/gis-icon/pin-m-mi-hospital+0000ff.svg`,
189
- query: { nocache: 1 },
190
- headers: { uid: user.id, user_type: user.type }
191
- });
192
- expect(res.statusCode).toBe(200);
193
- expect(res.headers['content-type']).toBe('image/svg+xml');
194
- expect(res.body).toContain('<svg');
195
- expect(res.body).toContain('fill="#0000ff"');
196
- });
197
-
198
- test('GET /gis-icon with glyphicons font (gl)', async () => {
199
- const res = await injectWithHeaders({
200
- method: 'GET',
201
- url: `/api/gis-icon/pin-m-gl-heart+ffff00.svg`,
202
- query: { nocache: 1 },
203
- headers: { uid: user.id, user_type: user.type }
204
- });
205
- expect(res.statusCode).toBe(200);
206
- expect(res.headers['content-type']).toBe('image/svg+xml');
207
- expect(res.body).toContain('<svg');
208
- expect(res.body).toContain('fill="#ffff00"');
209
- });
210
-
211
- test('GET /gis-icon with mongolia font (mn)', async () => {
212
- const res = await injectWithHeaders({
213
- method: 'GET',
214
- url: `/api/gis-icon/pin-m-mn-book+ffa500.svg`,
215
- query: { nocache: 1 },
216
- headers: { uid: user.id, user_type: user.type }
217
- });
218
- expect(res.statusCode).toBe(200);
219
- expect(res.headers['content-type']).toBe('image/svg+xml');
220
- expect(res.body).toContain('<svg');
221
- expect(res.body).toContain('fill="#ffa500"');
222
- });
223
-
224
- // Test different pin types with various fonts
225
- test.each([
226
- ['ty', 'anchor'],
227
- ['ma', 'zoo'],
228
- ['fa', 'heart'],
229
- ['mi', 'hospital'],
230
- ['gl', 'heart'],
231
- ['mn', 'book']
232
- ])('GET /gis-icon with different pins and %s font', async (fontType, icon) => {
233
- const res = await injectWithHeaders({
234
- method: 'GET',
235
- url: `/api/gis-icon/pin2-m-${fontType}-${icon}+7ed957.svg`,
236
- query: { nocache: 1 },
237
- headers: { uid: user.id, user_type: user.type }
238
- });
239
- expect(res.statusCode).toBe(200);
240
- expect(res.headers['content-type']).toBe('image/svg+xml');
241
- expect(res.body).toContain('<svg');
242
- expect(res.body).toContain('fill="#7ed957"');
243
- });
244
-
245
- // Test different sizes
246
- test.each(['s', 'm', 'l', 'xl'])('GET /gis-icon with different sizes (%s)', async (size) => {
247
- const res = await injectWithHeaders({
248
- method: 'GET',
249
- url: `/api/gis-icon/pin-${size}-fa-star+red.svg`,
250
- query: { nocache: 1 },
251
- headers: { uid: user.id, user_type: user.type }
252
- });
253
- expect(res.statusCode).toBe(200);
254
- expect(res.headers['content-type']).toBe('image/svg+xml');
255
- expect(res.body).toContain('<svg');
256
- });
257
-
258
- // Test PNG format
259
- test('GET /gis-icon with PNG format', async () => {
260
- const res = await injectWithHeaders({
261
- method: 'GET',
262
- url: `/api/gis-icon/pin-m-fa-star+blue.png`,
263
- query: { nocache: 1 },
264
- headers: { uid: user.id, user_type: user.type }
265
- });
266
- expect(res.statusCode).toBe(200);
267
- expect(res.headers['content-type']).toBe('image/png');
268
- expect(res.body.includes('PNG')).toBeTruthy();
269
- });
270
-
271
- // Test hex color formats
272
- test.each([
273
- ['3-digit hex', 'f00'],
274
- ['4-digit hex', 'f00f'],
275
- ['6-digit hex', 'ff0000'],
276
- ['8-digit hex', 'ff0000ff']
277
- ])('GET /gis-icon with %s color', async (format, color) => {
278
- const res = await injectWithHeaders({
279
- method: 'GET',
280
- url: `/api/gis-icon/pin-m-fa-star+${color}.svg`,
281
- query: { nocache: 1 },
282
- headers: { uid: user.id, user_type: user.type }
283
- });
284
- expect(res.statusCode).toBe(200);
285
- expect(res.headers['content-type']).toBe('image/svg+xml');
286
- expect(res.body).toContain('<svg');
287
- });
288
-
289
- // Test named colors
290
- test.each([
291
- 'red', 'green', 'black', 'gray', 'yellow', 'white', 'blue', 'orange', 'purple', 'pink', 'brown'
292
- ])('GET /gis-icon with named color %s', async (color) => {
293
- const res = await injectWithHeaders({
294
- method: 'GET',
295
- url: `/api/gis-icon/pin-m-fa-star+${color}.svg`,
296
- query: { nocache: 1 },
297
- headers: { uid: user.id, user_type: user.type }
298
- });
299
- expect(res.statusCode).toBe(200);
300
- expect(res.headers['content-type']).toBe('image/svg+xml');
301
- expect(res.body).toContain('<svg');
302
- });
303
-
304
- // Test invalid icon name returns 400
305
- test('GET /gis-icon with invalid name returns 400', async () => {
306
- const res = await injectWithHeaders({
307
- method: 'GET',
308
- url: `/api/gis-icon/invalid-name.svg`,
309
- query: { nocache: 1 },
310
- headers: { uid: user.id, user_type: user.type }
311
- });
312
- expect(res.statusCode).toBe(400);
313
- expect(res.json()).toHaveProperty('message');
314
- expect(res.json().message).toContain('invalid icon name');
315
- });
316
-
317
- // Test icon not found returns 404
318
- test('GET /gis-icon with non-existent icon returns 404', async () => {
319
- const res = await injectWithHeaders({
320
- method: 'GET',
321
- url: `/api/gis-icon/pin-m-fa-nonexistenticon+red.svg`,
322
- query: { nocache: 1 },
323
- headers: { uid: user.id, user_type: user.type }
324
- });
325
- expect(res.statusCode).toBe(404);
326
- expect(res.json()).toHaveProperty('message');
327
- expect(res.json().message).toContain('icon not found');
328
- });
329
-
330
- test('GET /maps', async () => {
331
- const res = await injectWithHeaders({
332
- method: 'GET', url: `/api/maps`,
333
- headers: { uid: user.id, user_type: user.type }
334
- });
335
- expect(res.statusCode).toBe(200);
336
- const rep = res.json();
337
- expect(rep).toBeInstanceOf(Array);
338
- if (rep?.length) {
339
- expect(rep?.[0]?.name).toBeTruthy();
340
- expect(rep?.[0]?.slug).toBeTruthy();
341
- }
342
- });
343
-
344
- test(`GET /map/:name`, async () => {
345
- const slug = 'addr';
346
- const body = await getTemplate('map', slug);
347
- expect(body).toBeTruthy();
348
-
349
- const res = await injectWithHeaders({
350
- method: 'GET', url: `/api/map/${slug}`,
351
- headers: { uid: user.id, user_type: user.type }
352
- });
353
- expect(res.statusCode).toBe(200);
354
- // expect(res.body).toHaveProperty('name');
355
- // expect(res.body.name).toBe('Адресний реєстр');
356
- expect(res.body).toHaveProperty('source_path');
357
- expect(res.body.source_path).toBe('data_address.street');
358
- expect(res.body).toHaveProperty('layers');
359
- expect(res.body.layers.length).toBe(3);
360
- expect(res.body).toHaveProperty('maps');
361
- expect(res.body.maps.length).toBeGreaterThan(0);
362
- });
363
-
364
- test(`GET /map-features/:slug/:id`, async () => {
365
- const slug = 'addr';
366
- const res = await injectWithHeaders({
367
- method: 'GET',
368
- url: `/api/map-features/${slug}/${addr.addr_id}`,
369
- });
370
- expect(res.statusCode).toBe(200);
371
- const rep = res.json();
372
- expect(rep.data).toBeTruthy();
373
- expect(rep.meta).toBeTruthy();
374
- expect(rep.data.addr_id).toBe(addr.addr_id);
375
- });
376
-
377
- test(`GET /map-features-point/:slug?x=&y=`, async () => {
378
- const slug = 'addr';
379
- const res = await injectWithHeaders({
380
- method: 'GET',
381
- url: `/api/map-features-point/${slug}?x=${addr.st_x}&y=${addr.st_y}`,
382
- headers: { uid: user.id, user_type: user.type }
383
- });
384
- expect(res.statusCode).toBe(200);
385
- const rep = res.json();
386
- expect(rep.data).toBeTruthy();
387
- expect(rep.meta).toBeTruthy();
388
- expect(rep.data.addr_id).toBe(addr.addr_id);
389
- });
390
-
391
- test(`GET /map-tiles/:slug/:z/:y/:x.pbf`, async () => {
392
- const slug = 'addr';
393
- const res = await injectWithHeaders({
394
- method: 'GET',
395
- url: `/api/map-tiles/${slug}/14/9767/5659.pbf`,
396
- headers: { uid: user.id, user_type: user.type }
397
- });
398
- expect(res.statusCode).toBe(200);
399
- expect(res.headers['content-type']).toBe('application/x-protobuf');
400
- expect(res.body.length).toBeGreaterThan(0);
401
- expect(res.body).toMatch('\u001a�8\n\u0006street');
402
- });
403
-
404
- test(`GET /api/map-catalog/:service/:attr`, async () => {
405
- const { id, columns } = await pg.query('select service_id as id, coalesce(filters::jsonb,attributes::jsonb,card::jsonb,popup::jsonb) as columns from gis.services where source_path is not null and is_active and is_public limit 1').then(r => r.rows?.[0] || {});
406
- expect(id).toBeTypeOf('string');
407
- expect(columns).toBeInstanceOf(Array);
408
- expect(columns.length).toBeGreaterThan(0);
409
- const { name: attr, data } = columns.find(col => col.data) || {};
410
- expect(attr).toBeTypeOf('string');
411
- expect(data).toBeTypeOf('string');
412
- const res = await injectWithHeaders({
413
- method: 'GET',
414
- url: `/api/map-catalog/${id}/${attr}`,
415
- headers: { uid: user.id, user_type: user.type }
416
- });
417
- expect(res.statusCode).toBe(200);
418
- expect(res.body).toHaveProperty('legend');
419
- expect(res.body.legend).toBeInstanceOf(Array);
420
- if (res.body.legend.length) {
421
- expect(res.body.legend[0]).toHaveProperty('id');
422
- expect(res.body.legend[0]).toHaveProperty('count');
423
- expect(res.body.legend[0].count).toMatch(/\d+/);
424
- expect(+res.body.legend[0].count).toBeGreaterThanOrEqual(0);
425
- }
426
- expect(res.body).toHaveProperty('min');
427
- expect(res.body).toHaveProperty('max');
428
- });
429
-
430
- test(`GET /api/map-catalog/:service/:attr?cls=`, async () => {
431
- const { id, columns } = await pg.query('select service_id as id, coalesce(filters::jsonb,attributes::jsonb,card::jsonb,popup::jsonb) as columns from gis.services where source_path is not null and is_active and is_public limit 1').then(r => r.rows?.[0] || {});
432
- expect(id).toBeTypeOf('string');
433
- expect(columns).toBeInstanceOf(Array);
434
- expect(columns.length).toBeGreaterThan(0);
435
- const { name: attr, data } = columns.find(col => col.data) || {};
436
- expect(attr).toBeTypeOf('string');
437
- expect(data).toBeTypeOf('string');
438
- const res = await injectWithHeaders({
439
- method: 'GET',
440
- url: `/api/map-catalog/${id}/${attr}`,
441
- query: { cls: data },
442
- headers: { uid: user.id, user_type: user.type }
443
- });
444
- expect(res.statusCode).toBe(200);
445
- expect(res.body).toHaveProperty('legend');
446
- expect(res.body.legend).toBeInstanceOf(Array);
447
- if (res.body.legend.length) {
448
- expect(res.body.legend[0]).toHaveProperty('id');
449
- expect(res.body.legend[0]).toHaveProperty('count');
450
- expect(res.body.legend[0].count).toMatch(/\d+/);
451
- expect(+res.body.legend[0].count).toBeGreaterThanOrEqual(0);
452
- expect(res.body.legend[0]).toHaveProperty('text');
453
- expect(res.body.legend[0].text).toBeTypeOf('string');
454
- }
455
- expect(res.body).toHaveProperty('min');
456
- expect(res.body).toHaveProperty('max');
457
- });
458
-
459
- test(`GET /api/vtile/:layer/:lang/:z/:y/:x`, async () => {
460
- const layer = await pg.query('select service_id from gis.services where source_path is not null and is_active and is_public limit 1').then(r => r.rows?.[0]?.service_id);
461
- expect(layer).toBeTypeOf('string');
462
- const res = await injectWithHeaders({
463
- method: 'GET',
464
- url: `/api/vtile/${layer}/ua/1/1/1.pbf`,
465
- // headers: { uid: user.id, user_type: user.type }
466
- });
467
- expect(res.statusCode).toBe(200);
468
- expect(res.headers).toHaveProperty('cache-control');
469
- expect(res.headers).toHaveProperty('content-type');
470
- expect(res.headers['content-type']).toBe("application/x-protobuf");
471
- expect(res.headers).toHaveProperty('content-length');
472
- });
473
-
474
- test(`GET /api/gis-clear-vtile/:id`, async () => {
475
- const layer = await pg.query('select service_id from gis.services where source_path is not null and is_active and is_public limit 1').then(r => r.rows?.[0]?.service_id);
476
- expect(layer).toBeTypeOf('string');
477
- const res = await injectWithHeaders({
478
- method: 'GET',
479
- url: `/api/gis-clear-vtile/${layer}`,
480
- headers: { uid: user.id, user_type: user.type }
481
- });
482
- expect(res.statusCode).toBe(200);
483
- expect(res.body).toHaveProperty('message');
484
- expect(res.body.message).toBe('Тайли очищено');
485
- });
486
- test(`GET /api/geojson/:layer`, async () => {
487
- const layer = await pg.query('select service_id from gis.services where source_path is not null and is_active and is_public limit 1').then(r => r.rows?.[0]?.service_id);
488
- expect(layer).toBeTypeOf('string');
489
- const res = await injectWithHeaders({
490
- method: 'GET',
491
- url: `/api/geojson/${layer}`,
492
- // headers: { uid: user.id, user_type: user.type }
493
- });
494
- expect(res.statusCode).toBe(200);
495
- expect(res.body).toHaveProperty('type');
496
- expect(res.body.type).toBe('FeatureCollection');
497
- expect(res.body).toHaveProperty('features');
498
- expect(res.body.features).toBeInstanceOf(Array);
499
- expect(res.body.features.length).toBeGreaterThan(0);
500
- expect(res.body.features[0]).toHaveProperty('type');
501
- expect(res.body.features[0].type).toBe('Feature');
502
- expect(res.body.features[0]).toHaveProperty('geometry');
503
- expect(res.body.features[0].geometry).toHaveProperty('type');
504
- expect(res.body.features[0].geometry.type).toBeOneOf(['Point', 'LineString', 'Polygon']);
505
- expect(res.body.features[0].geometry).toHaveProperty('coordinates');
506
- expect(res.body.features[0].geometry.coordinates).toBeInstanceOf(Array);
507
- expect(res.body.features[0]).toHaveProperty('properties');
508
- expect(Object.keys(res.body.features[0].properties).length).toBeGreaterThan(0);
509
- });
510
- test(`GET /api/json/:layer`, async () => {
511
- const layer = await pg.query('select register_id from gis.registers where 1=1 and is_active and is_public limit 1').then(r => r.rows?.[0]?.register_id);
512
- expect(layer).toBeTypeOf('string');
513
- const res = await injectWithHeaders({
514
- method: 'GET',
515
- url: `/api/json/${layer}`,
516
- // headers: { uid: user.id, user_type: user.type }
517
- });
518
- expect(res.statusCode).toBe(200);
519
- expect(res.body).toHaveProperty('register_id');
520
- expect(res.body).toHaveProperty('total');
521
- expect(res.body).toHaveProperty('limit');
522
- expect(res.body).toHaveProperty('page');
523
- expect(res.body).toHaveProperty('data');
524
- expect(res.body.data).toBeInstanceOf(Array);
525
- expect(res.body.data.length).toBeGreaterThan(0);
526
- expect(res.body.data[0]).toHaveProperty('id');
527
- });
528
- test(`GET /api/gis-layer-list`, async () => {
529
- const res = await injectWithHeaders({
530
- method: 'GET',
531
- url: `/api/gis-layer-list`,
532
- // headers: { uid: user.id, user_type: user.type }
533
- });
534
- expect(res.statusCode).toBe(200);
535
- });
536
-
537
- test(`GET /api/map-format?layer=&id=`, async () => {
538
- const { service_id: layer, source_path: table } = await pg.query('select service_id, source_path from gis.services where source_path is not null and is_active and is_public limit 1').then(r => r.rows?.[0] || {});
539
- expect(layer).toBeTypeOf('string');
540
- expect(pg.pk?.[table]).toBeTypeOf('string');
541
-
542
- const id = await pg.query(`select ${pg.pk?.[table]} as id from ${table} limit 1`).then(r => r.rows?.[0]?.id);
543
- expect(id).toBeTypeOf('string');
544
-
545
- const res = await injectWithHeaders({
546
- method: 'GET',
547
- url: `/api/map-format`,
548
- query: {
549
- layer,
550
- id
551
- },
552
- headers: { uid: user.id, user_type: user.type }
553
- });
554
- expect(res.statusCode).toBe(200);
555
- expect(res.body).toHaveProperty('id');
556
- expect(res.body).toHaveProperty('data');
557
- expect(res.body).toHaveProperty('columns');
558
- expect(res.body.columns).toBeInstanceOf(Array);
559
- expect(res.body.data).toHaveProperty('id');
560
- expect(res.body.data).toHaveProperty('geom');
561
- });
562
- test(`GET /api/map-format?layer=&lng=&lat=`, async () => {
563
- const { cartocss_id: layer, card_table: table } = await pg.query('select cartocss_id, card_table from gis.cartocss where card_table is not null and enabled and is_public limit 1').then(r => r.rows?.[0] || {});
564
- expect(layer).toBeTypeOf('string');
565
- expect(pg.pk?.[table]).toBeTypeOf('string');
566
-
567
- const { st_x: lng, st_y: lat } = await pg.query(`select st_x(st_pointonsurface(st_transform(geom,4326))), st_y(st_pointonsurface(st_transform(geom,4326))) from ${table} where geom is not null limit 1`).then(r => r.rows[0]);
568
- expect(lat).toBeTypeOf('number');
569
- const res = await injectWithHeaders({
570
- method: 'GET',
571
- url: `/api/map-format`,
572
- query: {
573
- layer,
574
- lng,
575
- lat
576
- },
577
- headers: { uid: user.id, user_type: user.type }
578
- });
579
- expect(res.statusCode).toBe(200);
580
- expect(res.body).toHaveProperty('id');
581
- expect(res.body).toHaveProperty('ids');
582
- expect(res.body.ids).toBeInstanceOf(Array);
583
- expect(res.body).toHaveProperty('data');
584
- expect(res.body).toHaveProperty('columns');
585
- expect(res.body.columns).toBeInstanceOf(Array);
586
- expect(res.body.data).toHaveProperty('id');
587
- expect(res.body.data).toHaveProperty('geom');
588
- expect(res.body.data).toHaveProperty('distance'); // self-explanatory
589
- expect(res.body.data).toHaveProperty('key'); // cartocss layer key
590
- });
591
- test(`GET /api/coords/height?lat=&lng=`, async () => {
592
- const res = await injectWithHeaders({
593
- method: 'GET',
594
- url: `/api/coords/height`,
595
- query: { lat: 50, lng: 30 },
596
- headers: { uid: user.id, user_type: user.type }
597
- });
598
- expect(res.statusCode).toBe(200);
599
- expect(res.body).toHaveProperty('height');
600
- expect(res.body.height).toBeTypeOf('number');
601
- expect(res.body.height).toBe(201);
602
- expect(res.body).toHaveProperty('lat');
603
- expect(res.body).toHaveProperty('lng');
604
- });
605
- test(`POST /api/gis-parse-geo`, async () => {
606
- const res = await injectWithHeaders({
607
- method: 'POST',
608
- url: `/api/gis-parse-geo`,
609
- payload: {
610
- content: `{ "type":"Feature", "geometry": { "type": "Point", "coordinates": [30.523,50.4501] }, "properties": {} }`
611
- },
612
- headers: { uid: user.id, user_type: user.type }
613
- });
614
- expect(res.statusCode).toBe(200);
615
- expect(res.body).toHaveProperty('type');
616
- expect(res.body.type).toBe('FeatureCollection');
617
- expect(res.body).toHaveProperty('features');
618
- expect(res.body.features).toBeInstanceOf(Array);
619
- expect(res.body.features.length).toBeGreaterThan(0);
620
- expect(res.body.features[0]).toHaveProperty('type');
621
- expect(res.body.features[0].type).toBe('Feature');
622
- expect(res.body.features[0]).toHaveProperty('geometry');
623
- expect(res.body.features[0].geometry).toHaveProperty('type');
624
- expect(res.body.features[0].geometry.type).toBeOneOf(['Point', 'LineString', 'Polygon']);
625
- expect(res.body.features[0].geometry).toHaveProperty('coordinates');
626
- expect(res.body.features[0].geometry.coordinates).toBeInstanceOf(Array);
627
- expect(res.body.features[0]).toHaveProperty('properties');
628
- });
629
- test(`POST /api/gis-convert (file as base64 + filename)`, async () => {
630
- const res = await injectWithHeaders({
631
- method: 'POST',
632
- url: `/api/gis-convert`,
633
- payload: {
634
- file: base64,
635
- filename: 'shapefile.zip',
636
- },
637
- headers: { uid: user.id, user_type: user.type }
638
- });
639
- expect(res.statusCode).toBe(200);
640
- expect(res.body).toHaveProperty('type');
641
- expect(res.body.type).toBe('FeatureCollection');
642
- expect(res.body).toHaveProperty('features');
643
- expect(res.body.features).toBeInstanceOf(Array);
644
- expect(res.body.features.length).toBeGreaterThan(0);
645
- expect(res.body.features[0]).toHaveProperty('type');
646
- expect(res.body.features[0].type).toBe('Feature');
647
- expect(res.body.features[0]).toHaveProperty('geometry');
648
- expect(res.body.features[0].geometry).toHaveProperty('type');
649
- expect(res.body.features[0].geometry.type).toBe('Point');
650
- expect(res.body.features[0].geometry).toHaveProperty('coordinates');
651
- expect(res.body.features[0].geometry.coordinates).toBeInstanceOf(Array);
652
- expect(res.body.features[0].geometry.coordinates[0]).toBe(30.5234);
653
- expect(res.body.features[0].geometry.coordinates[1]).toBe(50.4501);
654
- expect(res.body.features[0]).toHaveProperty('properties');
655
- expect(res.body.features[0].properties).toHaveProperty('id');
656
- expect(res.body.features[0].properties.id).toBe(1);
657
- });
658
-
659
- test(`POST /api/gis-convert (filepath)`, async () => {
660
- const relpath = '/files/test/shapefile.zip';
661
- const exists = await isFileExists(relpath);
662
- if (!exists) {
663
- await uploadFile(relpath, Buffer.from(base64, 'base64'));
664
- }
665
-
666
- const res = await injectWithHeaders({
667
- method: 'POST',
668
- url: `/api/gis-convert`,
669
- payload: {
670
- filepath: relpath
671
- },
672
- headers: { uid: user.id, user_type: user.type }
673
- });
674
- expect(res.statusCode).toBe(200);
675
- expect(res.body).toHaveProperty('type');
676
- expect(res.body.type).toBe('FeatureCollection');
677
- expect(res.body).toHaveProperty('features');
678
- expect(res.body.features).toBeInstanceOf(Array);
679
- expect(res.body.features.length).toBeGreaterThan(0);
680
- expect(res.body.features[0]).toHaveProperty('type');
681
- expect(res.body.features[0].type).toBe('Feature');
682
- expect(res.body.features[0]).toHaveProperty('geometry');
683
- expect(res.body.features[0].geometry).toHaveProperty('type');
684
- expect(res.body.features[0].geometry.type).toBe('Point');
685
- expect(res.body.features[0].geometry).toHaveProperty('coordinates');
686
- expect(res.body.features[0].geometry.coordinates).toBeInstanceOf(Array);
687
- expect(res.body.features[0].geometry.coordinates[0]).toBe(30.5234);
688
- expect(res.body.features[0].geometry.coordinates[1]).toBe(50.4501);
689
- expect(res.body.features[0]).toHaveProperty('properties');
690
- expect(res.body.features[0].properties).toHaveProperty('id');
691
- expect(res.body.features[0].properties.id).toBe(1);
692
- });
693
- });
1
+ import { describe, test, beforeAll, expect } from 'vitest';
2
+
3
+ import { getTemplate, getPGAsync, uploadFile, isFileExists } from '@opengis/fastify-table/utils.js';
4
+
5
+ import { build, injectWithHeaders } from '../../../test/helper.js';
6
+
7
+ const user = { id: '1', type: 'admin' };
8
+
9
+ let pg;
10
+ let addr = {};
11
+
12
+ // base64 from ziped shapefile for /gis-convert api
13
+ const base64 = `UEsDBBQAAAAAAMVDBV2t8XCrgwAAAIMAAAAJAAAAcG9pbnQucHJqR0VPR0NTWyJXR1MgODQiLERBVFVNWyJXR1NfMTk4NCIsU1BIRVJPSURbIldHUyA4NCIsNjM3ODEzNywyOTguMjU3MjIzNTYzXV0sUFJJTUVNWyJHcmVlbndpY2giLDBdLFVOSVRbImRlZ3JlZSIsMC4wMTc0NTMyOTI1MTk5NDMzXV1QSwMEFAAAAAAAxUMFXeUBOGx0AAAAdAAAAAkAAABwb2ludC5kYmYDfggFAQAAAEEAMwAAAAAAAAAAAAAAAAAAAAAAAAAAAGlkAAAAAAAAAAAATgAAAAAyAAAAAAAAAAAAAAAAAAAADSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgMVBLAwQUAAAAAADFQwVdjfPd44AAAACAAAAACQAAAHBvaW50LnNocAAAJwoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEDoAwAAAQAAAPW52or9hT5A/fZ14Jw5SUD1udqK/YU+QP32deCcOUlAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAACgEAAAD1udqK/YU+QP32deCcOUlAUEsDBBQAAAAAAMVDBV0HI9CqbAAAAGwAAAAJAAAAcG9pbnQuc2h4AAAnCgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANugDAAABAAAA9bnaiv2FPkD99nXgnDlJQPW52or9hT5A/fZ14Jw5SUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADIAAAAKUEsBAhQDFAAAAAAAxUMFXa3xcKuDAAAAgwAAAAkAAAAAAAAAAAAAAKSBAAAAAHBvaW50LnByalBLAQIUAxQAAAAAAMVDBV3lAThsdAAAAHQAAAAJAAAAAAAAAAAAAACkgaoAAABwb2ludC5kYmZQSwECFAMUAAAAAADFQwVdjfPd44AAAACAAAAACQAAAAAAAAAAAAAApIFFAQAAcG9pbnQuc2hwUEsBAhQDFAAAAAAAxUMFXQcj0KpsAAAAbAAAAAkAAAAAAAAAAAAAAKSB7AEAAHBvaW50LnNoeFBLBQYAAAAABAAEANwAAAB/AgAAAAA=`;
14
+
15
+ describe('map api test', () => {
16
+ beforeAll(async () => {
17
+ await build();
18
+ pg = await getPGAsync();
19
+
20
+ // preload an address row for map-feature tests
21
+ if (pg.pk?.['data_address.address']) {
22
+ addr = await pg
23
+ .query('select addr_id, st_x(geom), st_y(geom) from data_address.address where geom is not null limit 1')
24
+ .then(r => r.rows?.[0] || {});
25
+ expect(!!addr.addr_id).toBeTruthy();
26
+ }
27
+ });
28
+
29
+ test('GET /map-catalog', async () => {
30
+ const res = await injectWithHeaders({ method: 'GET', url: '/api/map-catalog' });
31
+ expect(res.statusCode).toBe(200);
32
+ const rep = res.json();
33
+ expect(Array.isArray(rep.rasters)).toBeTruthy();
34
+ expect(Array.isArray(rep.services)).toBeTruthy();
35
+ });
36
+
37
+ test('GET /marker-icon/*', async () => {
38
+ // latest changes break local icon generation
39
+ const res = await injectWithHeaders({
40
+ method: 'GET',
41
+ // url: `/api/marker-icon/pin6-m-fa-space-shuttle+teal.png`,
42
+ url: '/api/marker-icon/icon-l-fa-location-dot+ff0000.svg',
43
+ headers: { uid: user.id, user_type: user.type }
44
+ });
45
+ if (res.statusCode === 200) {
46
+ expect(res.statusCode).toBe(200);
47
+ expect(res.body.includes('PNG')).toBeTruthy();
48
+ expect(res.rawPayload?.length).toBeTruthy();
49
+ } else {
50
+ expect(res.statusCode).toBe(404);
51
+ expect(res.body.message).toMatch('icon not found');
52
+ }
53
+ }, 15000);
54
+
55
+ test('GET /gis-icon/*', async () => {
56
+ const res = await injectWithHeaders({
57
+ method: 'GET',
58
+ url: `/api/gis-icon/pin6-m-fa-plus-square+7ed957.png`,
59
+ query: { nocache: 1 },
60
+ headers: { uid: user.id, user_type: user.type }
61
+ });
62
+ expect(res.statusCode).toBe(200);
63
+ expect(res.headers['content-type']).toBe('image/png');
64
+ expect(res.body.includes('PNG')).toBeTruthy();
65
+ });
66
+
67
+ test('GET /icon/*', async () => {
68
+ const res = await injectWithHeaders({
69
+ method: 'GET',
70
+ url: `/api/icon/pin6-m-fa-plus-square+7ed957.png`,
71
+ query: { nocache: 1 },
72
+ headers: { uid: user.id, user_type: user.type }
73
+ });
74
+ expect(res.statusCode).toBe(200);
75
+ expect(res.headers['content-type']).toBe('image/png');
76
+ expect(res.body.includes('PNG')).toBeTruthy();
77
+ });
78
+
79
+ test('GET /gis-icon/*.svg', async () => {
80
+ const res = await injectWithHeaders({
81
+ method: 'GET',
82
+ url: `/api/gis-icon/pin6-m-fa-plus-square+7ed957.svg`,
83
+ query: { nocache: 1 },
84
+ headers: { uid: user.id, user_type: user.type }
85
+ });
86
+ expect(res.statusCode).toBe(200);
87
+ expect(res.headers['content-type']).toBe('image/svg+xml');
88
+ expect(res.body).toContain('<svg');
89
+ expect(res.body).toContain('viewBox="0 0 446 518"');
90
+ });
91
+
92
+ test('GET /gis-icon/ar-* renders a symbol', async () => {
93
+ const res = await injectWithHeaders({
94
+ method: 'GET',
95
+ url: `/api/gis-icon/pin6-m-ar-E+ff4500.svg`,
96
+ query: { nocache: 1 },
97
+ headers: { uid: user.id, user_type: user.type }
98
+ });
99
+ expect(res.statusCode).toBe(200);
100
+ expect(res.headers['content-type']).toBe('image/svg+xml');
101
+ expect(res.body).toContain('>E</text>');
102
+ expect(res.body).toContain('fill="#ff4500"');
103
+ expect(res.body).not.toContain('#ff0000');
104
+ });
105
+
106
+ test.each(['pin2', 'pin3', 'pin4', 'pin5', 'pin6', 'pin7'])(
107
+ 'GET /gis-icon/%s recolors the background',
108
+ async (pin) => {
109
+ const res = await injectWithHeaders({
110
+ method: 'GET',
111
+ url: `/api/gis-icon/${pin}-m-fa-plus-square+7ed957.svg`,
112
+ query: { nocache: 1 },
113
+ headers: { uid: user.id, user_type: user.type }
114
+ });
115
+ expect(res.statusCode).toBe(200);
116
+ expect(res.body).not.toContain('#ff0000');
117
+ expect(res.body).toContain('fill="#7ed957"');
118
+ expect(res.body.lastIndexOf('data-gis-icon-layer="foreground"'))
119
+ .toBeGreaterThan(res.body.lastIndexOf('<use'));
120
+ },
121
+ );
122
+
123
+ test.each([
124
+ ['pin', '#ff0000'],
125
+ ['pin1', '#ff0000'],
126
+ ['circle1', '#176e1c'],
127
+ ['circle2', '#ff0000'],
128
+ ['none', 'fill="red"'],
129
+ ])(
130
+ 'GET /gis-icon/%s keeps the original background',
131
+ async (pin, backgroundColor) => {
132
+ const res = await injectWithHeaders({
133
+ method: 'GET',
134
+ url: `/api/gis-icon/${pin}-m-fa-plus-square+7ed957.svg`,
135
+ query: { nocache: 1 },
136
+ headers: { uid: user.id, user_type: user.type }
137
+ });
138
+ expect(res.statusCode).toBe(200);
139
+ expect(res.body).toContain(backgroundColor);
140
+ expect(res.body).toContain('fill="#7ed957"');
141
+ expect(res.body.lastIndexOf('data-gis-icon-layer="foreground"'))
142
+ .toBeGreaterThan(res.body.lastIndexOf('<use'));
143
+ },
144
+ );
145
+
146
+ test('GET /gis-icon with typicons font (ty)', async () => {
147
+ const res = await injectWithHeaders({
148
+ method: 'GET',
149
+ url: `/api/gis-icon/pin-m-ty-anchor+ff0000.svg`,
150
+ query: { nocache: 1 },
151
+ headers: { uid: user.id, user_type: user.type }
152
+ });
153
+ expect(res.statusCode).toBe(200);
154
+ expect(res.headers['content-type']).toBe('image/svg+xml');
155
+ expect(res.body).toContain('<svg');
156
+ expect(res.body).toContain('fill="#ff0000"');
157
+ });
158
+
159
+ test('GET /gis-icon with maki font (ma)', async () => {
160
+ const res = await injectWithHeaders({
161
+ method: 'GET',
162
+ url: `/api/gis-icon/pin-m-ma-zoo+00ff00.svg`,
163
+ query: { nocache: 1 },
164
+ headers: { uid: user.id, user_type: user.type }
165
+ });
166
+ expect(res.statusCode).toBe(200);
167
+ expect(res.headers['content-type']).toBe('image/svg+xml');
168
+ expect(res.body).toContain('<svg');
169
+ expect(res.body).toContain('fill="#00ff00"');
170
+ });
171
+
172
+ test('GET /gis-icon with fontawesome font (fa)', async () => {
173
+ const res = await injectWithHeaders({
174
+ method: 'GET',
175
+ url: `/api/gis-icon/pin-m-fa-heart+ff0000.svg`,
176
+ query: { nocache: 1 },
177
+ headers: { uid: user.id, user_type: user.type }
178
+ });
179
+ expect(res.statusCode).toBe(200);
180
+ expect(res.headers['content-type']).toBe('image/svg+xml');
181
+ expect(res.body).toContain('<svg');
182
+ expect(res.body).toContain('fill="#ff0000"');
183
+ });
184
+
185
+ test('GET /gis-icon with map icons font (mi)', async () => {
186
+ const res = await injectWithHeaders({
187
+ method: 'GET',
188
+ url: `/api/gis-icon/pin-m-mi-hospital+0000ff.svg`,
189
+ query: { nocache: 1 },
190
+ headers: { uid: user.id, user_type: user.type }
191
+ });
192
+ expect(res.statusCode).toBe(200);
193
+ expect(res.headers['content-type']).toBe('image/svg+xml');
194
+ expect(res.body).toContain('<svg');
195
+ expect(res.body).toContain('fill="#0000ff"');
196
+ });
197
+
198
+ test('GET /gis-icon with glyphicons font (gl)', async () => {
199
+ const res = await injectWithHeaders({
200
+ method: 'GET',
201
+ url: `/api/gis-icon/pin-m-gl-heart+ffff00.svg`,
202
+ query: { nocache: 1 },
203
+ headers: { uid: user.id, user_type: user.type }
204
+ });
205
+ expect(res.statusCode).toBe(200);
206
+ expect(res.headers['content-type']).toBe('image/svg+xml');
207
+ expect(res.body).toContain('<svg');
208
+ expect(res.body).toContain('fill="#ffff00"');
209
+ });
210
+
211
+ test('GET /gis-icon with mongolia font (mn)', async () => {
212
+ const res = await injectWithHeaders({
213
+ method: 'GET',
214
+ url: `/api/gis-icon/pin-m-mn-book+ffa500.svg`,
215
+ query: { nocache: 1 },
216
+ headers: { uid: user.id, user_type: user.type }
217
+ });
218
+ expect(res.statusCode).toBe(200);
219
+ expect(res.headers['content-type']).toBe('image/svg+xml');
220
+ expect(res.body).toContain('<svg');
221
+ expect(res.body).toContain('fill="#ffa500"');
222
+ });
223
+
224
+ // Test different pin types with various fonts
225
+ test.each([
226
+ ['ty', 'anchor'],
227
+ ['ma', 'zoo'],
228
+ ['fa', 'heart'],
229
+ ['mi', 'hospital'],
230
+ ['gl', 'heart'],
231
+ ['mn', 'book']
232
+ ])('GET /gis-icon with different pins and %s font', async (fontType, icon) => {
233
+ const res = await injectWithHeaders({
234
+ method: 'GET',
235
+ url: `/api/gis-icon/pin2-m-${fontType}-${icon}+7ed957.svg`,
236
+ query: { nocache: 1 },
237
+ headers: { uid: user.id, user_type: user.type }
238
+ });
239
+ expect(res.statusCode).toBe(200);
240
+ expect(res.headers['content-type']).toBe('image/svg+xml');
241
+ expect(res.body).toContain('<svg');
242
+ expect(res.body).toContain('fill="#7ed957"');
243
+ });
244
+
245
+ // Test different sizes
246
+ test.each(['s', 'm', 'l', 'xl'])('GET /gis-icon with different sizes (%s)', async (size) => {
247
+ const res = await injectWithHeaders({
248
+ method: 'GET',
249
+ url: `/api/gis-icon/pin-${size}-fa-star+red.svg`,
250
+ query: { nocache: 1 },
251
+ headers: { uid: user.id, user_type: user.type }
252
+ });
253
+ expect(res.statusCode).toBe(200);
254
+ expect(res.headers['content-type']).toBe('image/svg+xml');
255
+ expect(res.body).toContain('<svg');
256
+ });
257
+
258
+ // Test PNG format
259
+ test('GET /gis-icon with PNG format', async () => {
260
+ const res = await injectWithHeaders({
261
+ method: 'GET',
262
+ url: `/api/gis-icon/pin-m-fa-star+blue.png`,
263
+ query: { nocache: 1 },
264
+ headers: { uid: user.id, user_type: user.type }
265
+ });
266
+ expect(res.statusCode).toBe(200);
267
+ expect(res.headers['content-type']).toBe('image/png');
268
+ expect(res.body.includes('PNG')).toBeTruthy();
269
+ });
270
+
271
+ // Test hex color formats
272
+ test.each([
273
+ ['3-digit hex', 'f00'],
274
+ ['4-digit hex', 'f00f'],
275
+ ['6-digit hex', 'ff0000'],
276
+ ['8-digit hex', 'ff0000ff']
277
+ ])('GET /gis-icon with %s color', async (format, color) => {
278
+ const res = await injectWithHeaders({
279
+ method: 'GET',
280
+ url: `/api/gis-icon/pin-m-fa-star+${color}.svg`,
281
+ query: { nocache: 1 },
282
+ headers: { uid: user.id, user_type: user.type }
283
+ });
284
+ expect(res.statusCode).toBe(200);
285
+ expect(res.headers['content-type']).toBe('image/svg+xml');
286
+ expect(res.body).toContain('<svg');
287
+ });
288
+
289
+ // Test named colors
290
+ test.each([
291
+ 'red', 'green', 'black', 'gray', 'yellow', 'white', 'blue', 'orange', 'purple', 'pink', 'brown'
292
+ ])('GET /gis-icon with named color %s', async (color) => {
293
+ const res = await injectWithHeaders({
294
+ method: 'GET',
295
+ url: `/api/gis-icon/pin-m-fa-star+${color}.svg`,
296
+ query: { nocache: 1 },
297
+ headers: { uid: user.id, user_type: user.type }
298
+ });
299
+ expect(res.statusCode).toBe(200);
300
+ expect(res.headers['content-type']).toBe('image/svg+xml');
301
+ expect(res.body).toContain('<svg');
302
+ });
303
+
304
+ // Test invalid icon name returns 400
305
+ test('GET /gis-icon with invalid name returns 400', async () => {
306
+ const res = await injectWithHeaders({
307
+ method: 'GET',
308
+ url: `/api/gis-icon/invalid-name.svg`,
309
+ query: { nocache: 1 },
310
+ headers: { uid: user.id, user_type: user.type }
311
+ });
312
+ expect(res.statusCode).toBe(400);
313
+ expect(res.json()).toHaveProperty('message');
314
+ expect(res.json().message).toContain('invalid icon name');
315
+ });
316
+
317
+ // Test icon not found returns 404
318
+ test('GET /gis-icon with non-existent icon returns 404', async () => {
319
+ const res = await injectWithHeaders({
320
+ method: 'GET',
321
+ url: `/api/gis-icon/pin-m-fa-nonexistenticon+red.svg`,
322
+ query: { nocache: 1 },
323
+ headers: { uid: user.id, user_type: user.type }
324
+ });
325
+ expect(res.statusCode).toBe(404);
326
+ expect(res.json()).toHaveProperty('message');
327
+ expect(res.json().message).toContain('icon not found');
328
+ });
329
+
330
+ test('GET /maps', async () => {
331
+ const res = await injectWithHeaders({
332
+ method: 'GET', url: `/api/maps`,
333
+ headers: { uid: user.id, user_type: user.type }
334
+ });
335
+ expect(res.statusCode).toBe(200);
336
+ const rep = res.json();
337
+ expect(rep).toBeInstanceOf(Array);
338
+ if (rep?.length) {
339
+ expect(rep?.[0]?.name).toBeTruthy();
340
+ expect(rep?.[0]?.slug).toBeTruthy();
341
+ }
342
+ });
343
+
344
+ test(`GET /map/:name`, async () => {
345
+ const slug = 'addr';
346
+ const body = await getTemplate('map', slug);
347
+ expect(body).toBeTruthy();
348
+
349
+ const res = await injectWithHeaders({
350
+ method: 'GET', url: `/api/map/${slug}`,
351
+ headers: { uid: user.id, user_type: user.type }
352
+ });
353
+ expect(res.statusCode).toBe(200);
354
+ // expect(res.body).toHaveProperty('name');
355
+ // expect(res.body.name).toBe('Адресний реєстр');
356
+ expect(res.body).toHaveProperty('source_path');
357
+ expect(res.body.source_path).toBe('data_address.street');
358
+ expect(res.body).toHaveProperty('layers');
359
+ expect(res.body.layers.length).toBe(3);
360
+ expect(res.body).toHaveProperty('maps');
361
+ expect(res.body.maps.length).toBeGreaterThan(0);
362
+ });
363
+
364
+ test(`GET /map-features/:slug/:id`, async () => {
365
+ const slug = 'addr';
366
+ const res = await injectWithHeaders({
367
+ method: 'GET',
368
+ url: `/api/map-features/${slug}/${addr.addr_id}`,
369
+ });
370
+ expect(res.statusCode).toBe(200);
371
+ const rep = res.json();
372
+ expect(rep.data).toBeTruthy();
373
+ expect(rep.meta).toBeTruthy();
374
+ expect(rep.data.addr_id).toBe(addr.addr_id);
375
+ });
376
+
377
+ test(`GET /map-features-point/:slug?x=&y=`, async () => {
378
+ const slug = 'addr';
379
+ const res = await injectWithHeaders({
380
+ method: 'GET',
381
+ url: `/api/map-features-point/${slug}?x=${addr.st_x}&y=${addr.st_y}`,
382
+ headers: { uid: user.id, user_type: user.type }
383
+ });
384
+ expect(res.statusCode).toBe(200);
385
+ const rep = res.json();
386
+ expect(rep.data).toBeTruthy();
387
+ expect(rep.meta).toBeTruthy();
388
+ expect(rep.data.addr_id).toBe(addr.addr_id);
389
+ });
390
+
391
+ test(`GET /map-tiles/:slug/:z/:y/:x.pbf`, async () => {
392
+ const slug = 'addr';
393
+ const res = await injectWithHeaders({
394
+ method: 'GET',
395
+ url: `/api/map-tiles/${slug}/14/9767/5659.pbf`,
396
+ headers: { uid: user.id, user_type: user.type }
397
+ });
398
+ expect(res.statusCode).toBe(200);
399
+ expect(res.headers['content-type']).toBe('application/x-protobuf');
400
+ expect(res.body.length).toBeGreaterThan(0);
401
+ expect(res.body).toMatch('\u001a�8\n\u0006street');
402
+ });
403
+
404
+ test(`GET /api/map-catalog/:service/:attr`, async () => {
405
+ const { id, columns } = await pg.query('select service_id as id, coalesce(filters::jsonb,attributes::jsonb,card::jsonb,popup::jsonb) as columns from gis.services where source_path is not null and is_active and is_public limit 1').then(r => r.rows?.[0] || {});
406
+ expect(id).toBeTypeOf('string');
407
+ expect(columns).toBeInstanceOf(Array);
408
+ expect(columns.length).toBeGreaterThan(0);
409
+ const { name: attr, data } = columns.find(col => col.data) || {};
410
+ expect(attr).toBeTypeOf('string');
411
+ expect(data).toBeTypeOf('string');
412
+ const res = await injectWithHeaders({
413
+ method: 'GET',
414
+ url: `/api/map-catalog/${id}/${attr}`,
415
+ headers: { uid: user.id, user_type: user.type }
416
+ });
417
+ expect(res.statusCode).toBe(200);
418
+ expect(res.body).toHaveProperty('legend');
419
+ expect(res.body.legend).toBeInstanceOf(Array);
420
+ if (res.body.legend.length) {
421
+ expect(res.body.legend[0]).toHaveProperty('id');
422
+ expect(res.body.legend[0]).toHaveProperty('count');
423
+ expect(res.body.legend[0].count).toMatch(/\d+/);
424
+ expect(+res.body.legend[0].count).toBeGreaterThanOrEqual(0);
425
+ }
426
+ expect(res.body).toHaveProperty('min');
427
+ expect(res.body).toHaveProperty('max');
428
+ });
429
+
430
+ test(`GET /api/map-catalog/:service/:attr?cls=`, async () => {
431
+ const { id, columns } = await pg.query('select service_id as id, coalesce(filters::jsonb,attributes::jsonb,card::jsonb,popup::jsonb) as columns from gis.services where source_path is not null and is_active and is_public limit 1').then(r => r.rows?.[0] || {});
432
+ expect(id).toBeTypeOf('string');
433
+ expect(columns).toBeInstanceOf(Array);
434
+ expect(columns.length).toBeGreaterThan(0);
435
+ const { name: attr, data } = columns.find(col => col.data) || {};
436
+ expect(attr).toBeTypeOf('string');
437
+ expect(data).toBeTypeOf('string');
438
+ const res = await injectWithHeaders({
439
+ method: 'GET',
440
+ url: `/api/map-catalog/${id}/${attr}`,
441
+ query: { cls: data },
442
+ headers: { uid: user.id, user_type: user.type }
443
+ });
444
+ expect(res.statusCode).toBe(200);
445
+ expect(res.body).toHaveProperty('legend');
446
+ expect(res.body.legend).toBeInstanceOf(Array);
447
+ if (res.body.legend.length) {
448
+ expect(res.body.legend[0]).toHaveProperty('id');
449
+ expect(res.body.legend[0]).toHaveProperty('count');
450
+ expect(res.body.legend[0].count).toMatch(/\d+/);
451
+ expect(+res.body.legend[0].count).toBeGreaterThanOrEqual(0);
452
+ expect(res.body.legend[0]).toHaveProperty('text');
453
+ expect(res.body.legend[0].text).toBeTypeOf('string');
454
+ }
455
+ expect(res.body).toHaveProperty('min');
456
+ expect(res.body).toHaveProperty('max');
457
+ });
458
+
459
+ test(`GET /api/vtile/:layer/:lang/:z/:y/:x`, async () => {
460
+ const layer = await pg.query('select service_id from gis.services where source_path is not null and is_active and is_public limit 1').then(r => r.rows?.[0]?.service_id);
461
+ expect(layer).toBeTypeOf('string');
462
+ const res = await injectWithHeaders({
463
+ method: 'GET',
464
+ url: `/api/vtile/${layer}/ua/1/1/1.pbf`,
465
+ // headers: { uid: user.id, user_type: user.type }
466
+ });
467
+ expect(res.statusCode).toBe(200);
468
+ expect(res.headers).toHaveProperty('cache-control');
469
+ expect(res.headers).toHaveProperty('content-type');
470
+ expect(res.headers['content-type']).toBe("application/x-protobuf");
471
+ expect(res.headers).toHaveProperty('content-length');
472
+ });
473
+
474
+ test(`GET /api/gis-clear-vtile/:id`, async () => {
475
+ const layer = await pg.query('select service_id from gis.services where source_path is not null and is_active and is_public limit 1').then(r => r.rows?.[0]?.service_id);
476
+ expect(layer).toBeTypeOf('string');
477
+ const res = await injectWithHeaders({
478
+ method: 'GET',
479
+ url: `/api/gis-clear-vtile/${layer}`,
480
+ headers: { uid: user.id, user_type: user.type }
481
+ });
482
+ expect(res.statusCode).toBe(200);
483
+ expect(res.body).toHaveProperty('message');
484
+ expect(res.body.message).toBe('Тайли очищено');
485
+ });
486
+ test(`GET /api/geojson/:layer`, async () => {
487
+ const layer = await pg.query('select service_id from gis.services where source_path is not null and is_active and is_public limit 1').then(r => r.rows?.[0]?.service_id);
488
+ expect(layer).toBeTypeOf('string');
489
+ const res = await injectWithHeaders({
490
+ method: 'GET',
491
+ url: `/api/geojson/${layer}`,
492
+ // headers: { uid: user.id, user_type: user.type }
493
+ });
494
+ expect(res.statusCode).toBe(200);
495
+ expect(res.body).toHaveProperty('type');
496
+ expect(res.body.type).toBe('FeatureCollection');
497
+ expect(res.body).toHaveProperty('features');
498
+ expect(res.body.features).toBeInstanceOf(Array);
499
+ expect(res.body.features.length).toBeGreaterThan(0);
500
+ expect(res.body.features[0]).toHaveProperty('type');
501
+ expect(res.body.features[0].type).toBe('Feature');
502
+ expect(res.body.features[0]).toHaveProperty('geometry');
503
+ expect(res.body.features[0].geometry).toHaveProperty('type');
504
+ expect(res.body.features[0].geometry.type).toBeOneOf(['Point', 'LineString', 'Polygon']);
505
+ expect(res.body.features[0].geometry).toHaveProperty('coordinates');
506
+ expect(res.body.features[0].geometry.coordinates).toBeInstanceOf(Array);
507
+ expect(res.body.features[0]).toHaveProperty('properties');
508
+ expect(Object.keys(res.body.features[0].properties).length).toBeGreaterThan(0);
509
+ });
510
+ test(`GET /api/json/:layer`, async () => {
511
+ const layer = await pg.query('select register_id from gis.registers where 1=1 and is_active and is_public limit 1').then(r => r.rows?.[0]?.register_id);
512
+ expect(layer).toBeTypeOf('string');
513
+ const res = await injectWithHeaders({
514
+ method: 'GET',
515
+ url: `/api/json/${layer}`,
516
+ // headers: { uid: user.id, user_type: user.type }
517
+ });
518
+ expect(res.statusCode).toBe(200);
519
+ expect(res.body).toHaveProperty('register_id');
520
+ expect(res.body).toHaveProperty('total');
521
+ expect(res.body).toHaveProperty('limit');
522
+ expect(res.body).toHaveProperty('page');
523
+ expect(res.body).toHaveProperty('data');
524
+ expect(res.body.data).toBeInstanceOf(Array);
525
+ expect(res.body.data.length).toBeGreaterThan(0);
526
+ expect(res.body.data[0]).toHaveProperty('id');
527
+ });
528
+ test(`GET /api/gis-layer-list`, async () => {
529
+ const res = await injectWithHeaders({
530
+ method: 'GET',
531
+ url: `/api/gis-layer-list`,
532
+ // headers: { uid: user.id, user_type: user.type }
533
+ });
534
+ expect(res.statusCode).toBe(200);
535
+ });
536
+
537
+ test(`GET /api/map-format?layer=&id=`, async () => {
538
+ const { service_id: layer, source_path: table } = await pg.query('select service_id, source_path from gis.services where source_path is not null and is_active and is_public limit 1').then(r => r.rows?.[0] || {});
539
+ expect(layer).toBeTypeOf('string');
540
+ expect(pg.pk?.[table]).toBeTypeOf('string');
541
+
542
+ const id = await pg.query(`select ${pg.pk?.[table]} as id from ${table} limit 1`).then(r => r.rows?.[0]?.id);
543
+ expect(id).toBeTypeOf('string');
544
+
545
+ const res = await injectWithHeaders({
546
+ method: 'GET',
547
+ url: `/api/map-format`,
548
+ query: {
549
+ layer,
550
+ id
551
+ },
552
+ headers: { uid: user.id, user_type: user.type }
553
+ });
554
+ expect(res.statusCode).toBe(200);
555
+ expect(res.body).toHaveProperty('id');
556
+ expect(res.body).toHaveProperty('data');
557
+ expect(res.body).toHaveProperty('columns');
558
+ expect(res.body.columns).toBeInstanceOf(Array);
559
+ expect(res.body.data).toHaveProperty('id');
560
+ expect(res.body.data).toHaveProperty('geom');
561
+ });
562
+ test(`GET /api/map-format?layer=&lng=&lat=`, async () => {
563
+ const { cartocss_id: layer, card_table: table } = await pg.query('select cartocss_id, card_table from gis.cartocss where card_table is not null and enabled and is_public limit 1').then(r => r.rows?.[0] || {});
564
+ expect(layer).toBeTypeOf('string');
565
+ expect(pg.pk?.[table]).toBeTypeOf('string');
566
+
567
+ const { st_x: lng, st_y: lat } = await pg.query(`select st_x(st_pointonsurface(st_transform(geom,4326))), st_y(st_pointonsurface(st_transform(geom,4326))) from ${table} where geom is not null limit 1`).then(r => r.rows[0]);
568
+ expect(lat).toBeTypeOf('number');
569
+ const res = await injectWithHeaders({
570
+ method: 'GET',
571
+ url: `/api/map-format`,
572
+ query: {
573
+ layer,
574
+ lng,
575
+ lat
576
+ },
577
+ headers: { uid: user.id, user_type: user.type }
578
+ });
579
+ expect(res.statusCode).toBe(200);
580
+ expect(res.body).toHaveProperty('id');
581
+ expect(res.body).toHaveProperty('ids');
582
+ expect(res.body.ids).toBeInstanceOf(Array);
583
+ expect(res.body).toHaveProperty('data');
584
+ expect(res.body).toHaveProperty('columns');
585
+ expect(res.body.columns).toBeInstanceOf(Array);
586
+ expect(res.body.data).toHaveProperty('id');
587
+ expect(res.body.data).toHaveProperty('geom');
588
+ expect(res.body.data).toHaveProperty('distance'); // self-explanatory
589
+ expect(res.body.data).toHaveProperty('key'); // cartocss layer key
590
+ });
591
+ test(`GET /api/coords/height?lat=&lng=`, async () => {
592
+ const res = await injectWithHeaders({
593
+ method: 'GET',
594
+ url: `/api/coords/height`,
595
+ query: { lat: 50, lng: 30 },
596
+ headers: { uid: user.id, user_type: user.type }
597
+ });
598
+ expect(res.statusCode).toBe(200);
599
+ expect(res.body).toHaveProperty('height');
600
+ expect(res.body.height).toBeTypeOf('number');
601
+ expect(res.body.height).toBe(201);
602
+ expect(res.body).toHaveProperty('lat');
603
+ expect(res.body).toHaveProperty('lng');
604
+ });
605
+ test(`POST /api/gis-parse-geo`, async () => {
606
+ const res = await injectWithHeaders({
607
+ method: 'POST',
608
+ url: `/api/gis-parse-geo`,
609
+ payload: {
610
+ content: `{ "type":"Feature", "geometry": { "type": "Point", "coordinates": [30.523,50.4501] }, "properties": {} }`
611
+ },
612
+ headers: { uid: user.id, user_type: user.type }
613
+ });
614
+ expect(res.statusCode).toBe(200);
615
+ expect(res.body).toHaveProperty('type');
616
+ expect(res.body.type).toBe('FeatureCollection');
617
+ expect(res.body).toHaveProperty('features');
618
+ expect(res.body.features).toBeInstanceOf(Array);
619
+ expect(res.body.features.length).toBeGreaterThan(0);
620
+ expect(res.body.features[0]).toHaveProperty('type');
621
+ expect(res.body.features[0].type).toBe('Feature');
622
+ expect(res.body.features[0]).toHaveProperty('geometry');
623
+ expect(res.body.features[0].geometry).toHaveProperty('type');
624
+ expect(res.body.features[0].geometry.type).toBeOneOf(['Point', 'LineString', 'Polygon']);
625
+ expect(res.body.features[0].geometry).toHaveProperty('coordinates');
626
+ expect(res.body.features[0].geometry.coordinates).toBeInstanceOf(Array);
627
+ expect(res.body.features[0]).toHaveProperty('properties');
628
+ });
629
+ test(`POST /api/gis-convert (file as base64 + filename)`, async () => {
630
+ const res = await injectWithHeaders({
631
+ method: 'POST',
632
+ url: `/api/gis-convert`,
633
+ payload: {
634
+ file: base64,
635
+ filename: 'shapefile.zip',
636
+ },
637
+ headers: { uid: user.id, user_type: user.type }
638
+ });
639
+ expect(res.statusCode).toBe(200);
640
+ expect(res.body).toHaveProperty('type');
641
+ expect(res.body.type).toBe('FeatureCollection');
642
+ expect(res.body).toHaveProperty('features');
643
+ expect(res.body.features).toBeInstanceOf(Array);
644
+ expect(res.body.features.length).toBeGreaterThan(0);
645
+ expect(res.body.features[0]).toHaveProperty('type');
646
+ expect(res.body.features[0].type).toBe('Feature');
647
+ expect(res.body.features[0]).toHaveProperty('geometry');
648
+ expect(res.body.features[0].geometry).toHaveProperty('type');
649
+ expect(res.body.features[0].geometry.type).toBe('Point');
650
+ expect(res.body.features[0].geometry).toHaveProperty('coordinates');
651
+ expect(res.body.features[0].geometry.coordinates).toBeInstanceOf(Array);
652
+ expect(res.body.features[0].geometry.coordinates[0]).toBe(30.5234);
653
+ expect(res.body.features[0].geometry.coordinates[1]).toBe(50.4501);
654
+ expect(res.body.features[0]).toHaveProperty('properties');
655
+ expect(res.body.features[0].properties).toHaveProperty('id');
656
+ expect(res.body.features[0].properties.id).toBe(1);
657
+ });
658
+
659
+ test(`POST /api/gis-convert (filepath)`, async () => {
660
+ const relpath = '/files/test/shapefile.zip';
661
+ const exists = await isFileExists(relpath);
662
+ if (!exists) {
663
+ await uploadFile(relpath, Buffer.from(base64, 'base64'));
664
+ }
665
+
666
+ const res = await injectWithHeaders({
667
+ method: 'POST',
668
+ url: `/api/gis-convert`,
669
+ payload: {
670
+ filepath: relpath
671
+ },
672
+ headers: { uid: user.id, user_type: user.type }
673
+ });
674
+ expect(res.statusCode).toBe(200);
675
+ expect(res.body).toHaveProperty('type');
676
+ expect(res.body.type).toBe('FeatureCollection');
677
+ expect(res.body).toHaveProperty('features');
678
+ expect(res.body.features).toBeInstanceOf(Array);
679
+ expect(res.body.features.length).toBeGreaterThan(0);
680
+ expect(res.body.features[0]).toHaveProperty('type');
681
+ expect(res.body.features[0].type).toBe('Feature');
682
+ expect(res.body.features[0]).toHaveProperty('geometry');
683
+ expect(res.body.features[0].geometry).toHaveProperty('type');
684
+ expect(res.body.features[0].geometry.type).toBe('Point');
685
+ expect(res.body.features[0].geometry).toHaveProperty('coordinates');
686
+ expect(res.body.features[0].geometry.coordinates).toBeInstanceOf(Array);
687
+ expect(res.body.features[0].geometry.coordinates[0]).toBe(30.5234);
688
+ expect(res.body.features[0].geometry.coordinates[1]).toBe(50.4501);
689
+ expect(res.body.features[0]).toHaveProperty('properties');
690
+ expect(res.body.features[0].properties).toHaveProperty('id');
691
+ expect(res.body.features[0].properties.id).toBe(1);
692
+ });
693
+ });