@opengis/fastify-table 1.0.16 → 1.0.18

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 (74) hide show
  1. package/.eslintrc.cjs +42 -42
  2. package/Changelog.md +52 -47
  3. package/README.md +26 -26
  4. package/config.js +11 -11
  5. package/crud/controllers/deleteCrud.js +14 -14
  6. package/crud/controllers/insert.js +29 -29
  7. package/crud/controllers/update.js +31 -31
  8. package/crud/controllers/utils/checkXSS.js +45 -45
  9. package/crud/controllers/utils/xssInjection.js +72 -72
  10. package/crud/funcs/dataDelete.js +15 -15
  11. package/crud/funcs/dataInsert.js +24 -24
  12. package/crud/funcs/dataUpdate.js +20 -20
  13. package/crud/funcs/getToken.js +27 -27
  14. package/crud/funcs/isFileExists.js +13 -13
  15. package/crud/funcs/setToken.js +53 -53
  16. package/crud/index.js +29 -29
  17. package/helper.js +28 -28
  18. package/index.js +4 -0
  19. package/notification/controllers/userNotifications.js +19 -0
  20. package/notification/funcs/addNotification.js +8 -0
  21. package/notification/index.js +19 -0
  22. package/package.json +22 -22
  23. package/pg/funcs/autoIndex.js +89 -89
  24. package/pg/funcs/getMeta.js +27 -27
  25. package/pg/funcs/getPG.js +29 -29
  26. package/pg/funcs/init.js +42 -42
  27. package/pg/funcs/pgClients.js +2 -2
  28. package/pg/index.js +35 -35
  29. package/pg/pgClients.js +20 -20
  30. package/policy/funcs/checkPolicy.js +74 -74
  31. package/policy/funcs/sqlInjection.js +33 -33
  32. package/policy/index.js +14 -14
  33. package/redis/client.js +8 -8
  34. package/redis/funcs/getRedis.js +23 -23
  35. package/redis/funcs/redisClients.js +2 -2
  36. package/redis/index.js +19 -19
  37. package/server/migrations/crm.sql +55 -0
  38. package/server/migrations/log.sql +40 -0
  39. package/server/templates/form/test.dataset.form.json +411 -411
  40. package/server.js +14 -14
  41. package/table/controllers/data.js +57 -57
  42. package/table/controllers/filter.js +32 -32
  43. package/table/controllers/form.js +10 -10
  44. package/table/controllers/suggest.js +60 -60
  45. package/table/controllers/utils/getSelect.js +20 -20
  46. package/table/controllers/utils/getSelectMeta.js +66 -66
  47. package/table/funcs/getFilterSQL/index.js +75 -75
  48. package/table/funcs/getFilterSQL/util/formatValue.js +142 -142
  49. package/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
  50. package/table/funcs/getFilterSQL/util/getFilterQuery.js +73 -73
  51. package/table/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
  52. package/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
  53. package/table/funcs/metaFormat/getSelectVal.js +20 -20
  54. package/table/funcs/metaFormat/index.js +26 -26
  55. package/table/index.js +25 -25
  56. package/test/api/crud.test.js +50 -50
  57. package/test/api/crud.xss.test.js +68 -68
  58. package/test/api/notification.test.js +56 -0
  59. package/test/api/table.test.js +49 -49
  60. package/test/config.example +18 -18
  61. package/test/funcs/crud.test.js +76 -76
  62. package/test/funcs/pg.test.js +34 -34
  63. package/test/funcs/redis.test.js +19 -19
  64. package/test/templates/cls/test.json +9 -9
  65. package/test/templates/form/cp_building.form.json +32 -32
  66. package/test/templates/select/account_id.json +3 -3
  67. package/test/templates/select/storage.data.json +2 -2
  68. package/test/templates/table/gis.dataset.table.json +20 -20
  69. package/test/widget.test.js +39 -0
  70. package/widget/controllers/utils/obj2db.js +13 -0
  71. package/widget/controllers/widget.del.js +41 -0
  72. package/widget/controllers/widget.get.js +145 -0
  73. package/widget/controllers/widget.set.js +49 -0
  74. package/widget/index.js +38 -0
@@ -1,34 +1,34 @@
1
- function getTable(table) {
2
- const result = table?.toLowerCase()?.replace(/[\n\r]+/g, ' ')?.split(' from ')?.filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
3
- ?.map((el) => el.split(/[ )]/)[0]);
4
- return result;
5
- }
6
-
7
- /**
8
- * @param {Number} opt.json - (1|0) 1 - Результат - Object, 0 - String
9
- * @param {String} opt.query - запит до таблиці
10
- * @param {String} opt.hash - інформація з хешу по запиту
11
- */
12
- const tableSql = {};
13
- async function getTableSql({
14
- pg, body, table, fields,
15
- }) {
16
- if (tableSql[table]) return tableSql[table];
17
-
18
- const fieldList = fields.map((el) => el.name);
19
-
20
- const tableList = body?.sql?.map((el) => getTable(el.sql)).reduce((acc, el) => acc.concat(el), []).filter((el) => fieldList.includes(pg.pk[el]));
21
-
22
- if (!tableList) { tableSql[table] = []; return []; }
23
-
24
- const data = await Promise.all(tableList?.map(async (tableEl) => {
25
- const { fields: fieldsEl } = await pg.query(`select * from ${tableEl} limit 0`, { cache: 1 });
26
- return fieldsEl.map((el) => ({ name: el.name, table: tableEl, pk: pg.pk[tableEl] }));
27
- }));
28
-
29
- tableSql[table] = data.reduce((acc, el) => acc.concat(el), []);
30
-
31
- return tableSql[table];
32
- }
33
-
34
- export default getTableSql;
1
+ function getTable(table) {
2
+ const result = table?.toLowerCase()?.replace(/[\n\r]+/g, ' ')?.split(' from ')?.filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
3
+ ?.map((el) => el.split(/[ )]/)[0]);
4
+ return result;
5
+ }
6
+
7
+ /**
8
+ * @param {Number} opt.json - (1|0) 1 - Результат - Object, 0 - String
9
+ * @param {String} opt.query - запит до таблиці
10
+ * @param {String} opt.hash - інформація з хешу по запиту
11
+ */
12
+ const tableSql = {};
13
+ async function getTableSql({
14
+ pg, body, table, fields,
15
+ }) {
16
+ if (tableSql[table]) return tableSql[table];
17
+
18
+ const fieldList = fields.map((el) => el.name);
19
+
20
+ const tableList = body?.sql?.map((el) => getTable(el.sql)).reduce((acc, el) => acc.concat(el), []).filter((el) => fieldList.includes(pg.pk[el]));
21
+
22
+ if (!tableList) { tableSql[table] = []; return []; }
23
+
24
+ const data = await Promise.all(tableList?.map(async (tableEl) => {
25
+ const { fields: fieldsEl } = await pg.query(`select * from ${tableEl} limit 0`, { cache: 1 });
26
+ return fieldsEl.map((el) => ({ name: el.name, table: tableEl, pk: pg.pk[tableEl] }));
27
+ }));
28
+
29
+ tableSql[table] = data.reduce((acc, el) => acc.concat(el), []);
30
+
31
+ return tableSql[table];
32
+ }
33
+
34
+ export default getTableSql;
@@ -1,20 +1,20 @@
1
- import getSelect from '../../controllers/utils/getSelect.js';
2
- import pg from '../../../pg/pgClients.js';
3
- import redis from '../../../redis/client.js';
4
-
5
- export default async function metaFormat({ name, values }) {
6
- const cls = await getSelect(name);
7
- if (!cls?.arr && !cls?.sql) return null;
8
- const key = `select:${name}`;
9
- const cache = !cls.arr ? (await redis.hmget(key, values)).reduce((p, el, i) => ({ ...p, [values[i]]: el }), {}) : {};
10
-
11
- const data = cls.arr || (values.filter(el => !cache[el]).length
12
- ? await pg.client.query(`with c(id,text) as (${cls.sql}) select * from c where id = any('{${values.filter(el => !cache[el])}}')`).then(el => el.rows)
13
- : []);
14
-
15
- const clsAr = { ...cache, ...data.reduce((p, el) => ({ ...p, [el.id.toString()]: el.color ? el : el.text }), {}) };
16
- if (!cls.arr && data.length) {
17
- redis.hmset(key, clsAr);
18
- }
19
- return clsAr;
20
- }
1
+ import getSelect from '../../controllers/utils/getSelect.js';
2
+ import pg from '../../../pg/pgClients.js';
3
+ import redis from '../../../redis/client.js';
4
+
5
+ export default async function metaFormat({ name, values }) {
6
+ const cls = await getSelect(name);
7
+ if (!cls?.arr && !cls?.sql) return null;
8
+ const key = `select:${name}`;
9
+ const cache = !cls.arr ? (await redis.hmget(key, values)).reduce((p, el, i) => ({ ...p, [values[i]]: el }), {}) : {};
10
+
11
+ const data = cls.arr || (values.filter(el => !cache[el]).length
12
+ ? await pg.client.query(`with c(id,text) as (${cls.sql}) select * from c where id = any('{${values.filter(el => !cache[el])}}')`).then(el => el.rows)
13
+ : []);
14
+
15
+ const clsAr = { ...cache, ...data.reduce((p, el) => ({ ...p, [el.id.toString()]: el.color ? el : el.text }), {}) };
16
+ if (!cls.arr && data.length) {
17
+ redis.hmset(key, clsAr);
18
+ }
19
+ return clsAr;
20
+ }
@@ -1,26 +1,26 @@
1
- import getTemplate from '../../controllers/utils/getTemplate.js';
2
- import getSelectVal from './getSelectVal.js';
3
-
4
- export default async function metaFormat({ rows, table }) {
5
- const loadTable = await getTemplate('table', table);
6
- const selectCols = loadTable.columns?.filter((e) => e.data);
7
-
8
- // cls & select format
9
-
10
- await Promise.all(selectCols?.map(async (attr) => {
11
- const values = [...new Set(rows?.map((el) => el[attr.name]).flat())].filter((el) => el);
12
- if (!values.length) return null;
13
-
14
- const cls = await getSelectVal({ name: attr.data, values });
15
- if (!cls) return null;
16
- rows.forEach(el => {
17
- const val = el[attr.name]?.map?.(c => cls[c] || c) || cls[el[attr.name]] || el[attr.name];
18
- if (!val) return;
19
- Object.assign(el, { [val?.color ? `${attr.name}_data` : `${attr.name}_text`]: (val.color ? val : val.text || val) });
20
- });
21
-
22
- return null;
23
- }));
24
-
25
- return rows;
26
- }
1
+ import getTemplate from '../../controllers/utils/getTemplate.js';
2
+ import getSelectVal from './getSelectVal.js';
3
+
4
+ export default async function metaFormat({ rows, table }) {
5
+ const loadTable = await getTemplate('table', table);
6
+ const selectCols = loadTable.columns?.filter((e) => e.data);
7
+
8
+ // cls & select format
9
+
10
+ await Promise.all(selectCols?.map(async (attr) => {
11
+ const values = [...new Set(rows?.map((el) => el[attr.name]).flat())].filter((el) => el);
12
+ if (!values.length) return null;
13
+
14
+ const cls = await getSelectVal({ name: attr.data, values });
15
+ if (!cls) return null;
16
+ rows.forEach(el => {
17
+ const val = el[attr.name]?.map?.(c => cls[c] || c) || cls[el[attr.name]] || el[attr.name];
18
+ if (!val) return;
19
+ Object.assign(el, { [val?.color ? `${attr.name}_data` : `${attr.name}_text`]: (val.color ? val : val.text || val) });
20
+ });
21
+
22
+ return null;
23
+ }));
24
+
25
+ return rows;
26
+ }
package/table/index.js CHANGED
@@ -1,25 +1,25 @@
1
- import suggest from './controllers/suggest.js';
2
- import data from './controllers/data.js';
3
- import filter from './controllers/filter.js';
4
- import form from './controllers/form.js';
5
- import metaFormat from './funcs/metaFormat/index.js';
6
-
7
- const tableSchema = {
8
- querystring: {
9
- page: { type: 'number' },
10
- order: { type: 'string' },
11
- filter: { type: 'string' },
12
- },
13
- };
14
-
15
- async function plugin(fastify, config = {}) {
16
- const prefix = config.prefix || '/api';
17
- fastify.decorate('metaFormat', metaFormat);
18
-
19
- fastify.get(`${prefix}/suggest/:data`, {}, suggest);
20
- fastify.get(`${prefix}/data/:table/:id?`, { schema: tableSchema }, data); // vs.crm.data.api с node
21
- fastify.get(`${prefix}/filter/:table`, {}, filter);
22
- fastify.get(`${prefix}/form/:form`, {}, form);
23
- }
24
-
25
- export default plugin;
1
+ import suggest from './controllers/suggest.js';
2
+ import data from './controllers/data.js';
3
+ import filter from './controllers/filter.js';
4
+ import form from './controllers/form.js';
5
+ import metaFormat from './funcs/metaFormat/index.js';
6
+
7
+ const tableSchema = {
8
+ querystring: {
9
+ page: { type: 'number' },
10
+ order: { type: 'string' },
11
+ filter: { type: 'string' },
12
+ },
13
+ };
14
+
15
+ async function plugin(fastify, config = {}) {
16
+ const prefix = config.prefix || '/api';
17
+ fastify.decorate('metaFormat', metaFormat);
18
+
19
+ fastify.get(`${prefix}/suggest/:data`, {}, suggest);
20
+ fastify.get(`${prefix}/data/:table/:id?`, { schema: tableSchema }, data); // vs.crm.data.api с node
21
+ fastify.get(`${prefix}/filter/:table`, {}, filter);
22
+ fastify.get(`${prefix}/form/:form`, {}, form);
23
+ }
24
+
25
+ export default plugin;
@@ -1,50 +1,50 @@
1
- import { test } from 'node:test';
2
- import assert from 'node:assert';
3
-
4
- import build from '../../helper.js';
5
-
6
- import config from '../config.js';
7
-
8
- test('api crud', async (t) => {
9
- const app = await build(t);
10
- const prefix = config.prefix || '/api';
11
-
12
- await t.test('POST /insert', async () => {
13
- const res = await app.inject({
14
- method: 'POST',
15
- url: `${prefix}/crud/gis.dataset`,
16
- body: { dataset_name: '111', dataset_id: '5400000' },
17
- });
18
-
19
- const rep = JSON.parse(res?.body);
20
- // rep.dataset_id
21
- // console.log(rep);
22
- // pgClients.client.query('delete from gis.dataset where dataset_id=$1', [rep.dataset_id]);
23
- assert.ok(rep.dataset_id);
24
- });
25
-
26
- await t.test('PUT /update', async () => {
27
- const res = await app.inject({
28
- method: 'PUT',
29
- url: `${prefix}/crud/gis.dataset/5400000`,
30
- body: { editor_id: '11' },
31
- });
32
-
33
- const rep = JSON.parse(res?.body);
34
- // rep.dataset_id
35
- // console.log(rep);
36
- assert.equal(rep.editor_id, '11');
37
- });
38
-
39
- await t.test('DELETE /delete', async () => {
40
- const res = await app.inject({
41
- method: 'DELETE',
42
- url: `${prefix}/crud/gis.dataset/5400000`,
43
- });
44
-
45
- const rep = JSON.parse(res?.body);
46
- // rep.dataset_id
47
- // console.log(rep);
48
- assert.ok(rep);
49
- });
50
- });
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert';
3
+
4
+ import build from '../../helper.js';
5
+
6
+ import config from '../config.js';
7
+
8
+ test('api crud', async (t) => {
9
+ const app = await build(t);
10
+ const prefix = config.prefix || '/api';
11
+
12
+ await t.test('POST /insert', async () => {
13
+ const res = await app.inject({
14
+ method: 'POST',
15
+ url: `${prefix}/crud/gis.dataset`,
16
+ body: { dataset_name: '111', dataset_id: '5400000' },
17
+ });
18
+
19
+ const rep = JSON.parse(res?.body);
20
+ // rep.dataset_id
21
+ // console.log(rep);
22
+ // pgClients.client.query('delete from gis.dataset where dataset_id=$1', [rep.dataset_id]);
23
+ assert.ok(rep.dataset_id);
24
+ });
25
+
26
+ await t.test('PUT /update', async () => {
27
+ const res = await app.inject({
28
+ method: 'PUT',
29
+ url: `${prefix}/crud/gis.dataset/5400000`,
30
+ body: { editor_id: '11' },
31
+ });
32
+
33
+ const rep = JSON.parse(res?.body);
34
+ // rep.dataset_id
35
+ // console.log(rep);
36
+ assert.equal(rep.editor_id, '11');
37
+ });
38
+
39
+ await t.test('DELETE /delete', async () => {
40
+ const res = await app.inject({
41
+ method: 'DELETE',
42
+ url: `${prefix}/crud/gis.dataset/5400000`,
43
+ });
44
+
45
+ const rep = JSON.parse(res?.body);
46
+ // rep.dataset_id
47
+ // console.log(rep);
48
+ assert.ok(rep);
49
+ });
50
+ });
@@ -1,68 +1,68 @@
1
- import { test } from 'node:test';
2
- import assert from 'node:assert';
3
-
4
- import build from '../../helper.js';
5
-
6
- import setToken from '../../crud/funcs/setToken.js';
7
- import config from '../config.js';
8
-
9
- test('api crud xss', async (t) => {
10
- const app = await build(t);
11
- const session = { passport: { user: { uid: '1' } } };
12
- app.decorateRequest('session', session);
13
-
14
- const prefix = config.prefix || '/api';
15
-
16
- let addTokens;
17
- let editTokens;
18
-
19
- // before
20
- t.test('setToken', async () => {
21
- addTokens = setToken({
22
- ids: [JSON.stringify({ add: 'gis.dataset', form: 'test.dataset.form' })],
23
- mode: 'a',
24
- uid: 1,
25
- array: 1,
26
- });
27
- editTokens = setToken({
28
- ids: [JSON.stringify({ id: '5400000', table: 'gis.dataset', form: 'test.dataset.form' })],
29
- mode: 'w',
30
- uid: 1,
31
- array: 1,
32
- });
33
- assert.ok(addTokens.length === 1 && editTokens.length === 1, 'invalid token');
34
- });
35
-
36
- await t.test('POST /insert', async () => {
37
- const res = await app.inject({
38
- method: 'POST',
39
- url: `${prefix}/crud/${addTokens[0]}`,
40
- body: { dataset_name: '<a onClick="alert("XSS Injection")">xss injection</a>', dataset_id: '5400000' },
41
- });
42
-
43
- const rep = JSON.parse(res?.body);
44
-
45
- assert.ok(rep.status, 409);
46
- });
47
-
48
- await t.test('PUT /update', async () => {
49
- const res = await app.inject({
50
- method: 'PUT',
51
- url: `${prefix}/crud/${editTokens[0]}/${editTokens[0]}`,
52
- body: { editor_id: '11', dataset_name: '<a onClick="alert("XSS Injection")">xss injection</a>' },
53
- });
54
-
55
- const rep = JSON.parse(res?.body);
56
-
57
- assert.equal(rep.status, 409);
58
- });
59
- await t.test('DELETE /delete', async () => {
60
- const res = await app.inject({
61
- method: 'DELETE',
62
- url: `${prefix}/crud/gis.dataset/5400000`,
63
- });
64
-
65
- const rep = JSON.parse(res?.body);
66
- assert.ok(rep);
67
- });
68
- });
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert';
3
+
4
+ import build from '../../helper.js';
5
+
6
+ import setToken from '../../crud/funcs/setToken.js';
7
+ import config from '../config.js';
8
+
9
+ test('api crud xss', async (t) => {
10
+ const app = await build(t);
11
+ const session = { passport: { user: { uid: '1' } } };
12
+ app.decorateRequest('session', session);
13
+
14
+ const prefix = config.prefix || '/api';
15
+
16
+ let addTokens;
17
+ let editTokens;
18
+
19
+ // before
20
+ t.test('setToken', async () => {
21
+ addTokens = setToken({
22
+ ids: [JSON.stringify({ add: 'gis.dataset', form: 'test.dataset.form' })],
23
+ mode: 'a',
24
+ uid: 1,
25
+ array: 1,
26
+ });
27
+ editTokens = setToken({
28
+ ids: [JSON.stringify({ id: '5400000', table: 'gis.dataset', form: 'test.dataset.form' })],
29
+ mode: 'w',
30
+ uid: 1,
31
+ array: 1,
32
+ });
33
+ assert.ok(addTokens.length === 1 && editTokens.length === 1, 'invalid token');
34
+ });
35
+
36
+ await t.test('POST /insert', async () => {
37
+ const res = await app.inject({
38
+ method: 'POST',
39
+ url: `${prefix}/crud/${addTokens[0]}`,
40
+ body: { dataset_name: '<a onClick="alert("XSS Injection")">xss injection</a>', dataset_id: '5400000' },
41
+ });
42
+
43
+ const rep = JSON.parse(res?.body);
44
+
45
+ assert.ok(rep.status, 409);
46
+ });
47
+
48
+ await t.test('PUT /update', async () => {
49
+ const res = await app.inject({
50
+ method: 'PUT',
51
+ url: `${prefix}/crud/${editTokens[0]}/${editTokens[0]}`,
52
+ body: { editor_id: '11', dataset_name: '<a onClick="alert("XSS Injection")">xss injection</a>' },
53
+ });
54
+
55
+ const rep = JSON.parse(res?.body);
56
+
57
+ assert.equal(rep.status, 409);
58
+ });
59
+ await t.test('DELETE /delete', async () => {
60
+ const res = await app.inject({
61
+ method: 'DELETE',
62
+ url: `${prefix}/crud/gis.dataset/5400000`,
63
+ });
64
+
65
+ const rep = JSON.parse(res?.body);
66
+ assert.ok(rep);
67
+ });
68
+ });
@@ -0,0 +1,56 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert';
3
+
4
+ import build from '../../helper.js';
5
+ import config from '../config.js';
6
+
7
+ const session = { passport: { user: { uid: config.testUser?.uid || '1' } } };
8
+
9
+ import userNotifications from '../../notification/controllers/userNotifications.js';
10
+ import addNotification from '../../notification/funcs/addNotification.js';
11
+
12
+ import pgClients from '../../pg/pgClients.js';
13
+
14
+ test('api && funcs notification', async (t) => {
15
+ const app = await build(t);
16
+ const pg = pgClients.client;
17
+ /*
18
+ // require dependency
19
+ await t.test('GET /auth', async () => {
20
+ const res = await app.inject({
21
+ method: 'GET',
22
+ url: `/api/login?username=${config.testUser?.username}&password=${config.testUser?.password}`,
23
+ });
24
+ assert.ok(res.statusCode);
25
+ });
26
+ await t.test('GET /notification', async () => {
27
+ const res = await app.inject({
28
+ method: 'GET',
29
+ url: '/api/notification',
30
+ });
31
+ const rep = JSON.parse(res?.body);
32
+ assert.ok(rep.time);
33
+ }); */
34
+ await t.test('GET /notification', async () => {
35
+ const rep = await userNotifications({ pg, session });
36
+ assert.ok(rep.time);
37
+ });
38
+
39
+ let resp;
40
+ await t.test('GET /notification', async () => {
41
+ resp = await addNotification({
42
+ pg,
43
+ session,
44
+ title: 'test title',
45
+ body: 'test body',
46
+ link: 'http://link',
47
+ notificationType: 'mention',
48
+ uid: session.passport.user.uid,
49
+ });
50
+ assert.ok(resp.id);
51
+ });
52
+ await t.test('clean up after test, before pool is closed', async () => {
53
+ await pg.query('delete from crm.notification where notification_id=$1', [resp.id]);
54
+ console.log(resp.id, 'deleted');
55
+ });
56
+ });
@@ -1,49 +1,49 @@
1
- import { test } from 'node:test';
2
- import assert from 'node:assert';
3
-
4
- import build from '../../helper.js';
5
-
6
- test('api table', async (t) => {
7
- const app = await build(t);
8
- // assert.ok(1);
9
- await t.test('GET /suggest', async () => {
10
- const res = await app.inject({
11
- method: 'GET',
12
- url: '/api/suggest/storage.data',
13
- });
14
- // console.log(res?.body);
15
- const rep = JSON.parse(res?.body);
16
- // console.log(rep.total);
17
- assert.ok(rep.total);
18
- });
19
- await t.test('GET /data', async () => {
20
- const res = await app.inject({
21
- method: 'GET',
22
- url: '/api/data/gis.dataset.table',
23
- });
24
- // console.log(res);
25
- const rep = JSON.parse(res?.body);
26
- // console.log(rep.total);
27
- assert.ok(rep.total);
28
- });
29
- await t.test('GET /form', async () => {
30
- const res = await app.inject({
31
- method: 'GET',
32
- url: '/api/form/cp_building.form',
33
- });
34
- // console.log(res);
35
- const rep = JSON.parse(res?.body);
36
- // console.log(rep.total);
37
- assert.ok(rep);
38
- });
39
- await t.test('GET /filter', async () => {
40
- const res = await app.inject({
41
- method: 'GET',
42
- url: '/api/filter/gis.dataset.table',
43
- });
44
- // console.log(res);
45
- const rep = JSON.parse(res?.body);
46
- // console.log(rep.total);
47
- assert.ok(rep);
48
- });
49
- });
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert';
3
+
4
+ import build from '../../helper.js';
5
+
6
+ test('api table', async (t) => {
7
+ const app = await build(t);
8
+ // assert.ok(1);
9
+ await t.test('GET /suggest', async () => {
10
+ const res = await app.inject({
11
+ method: 'GET',
12
+ url: '/api/suggest/storage.data',
13
+ });
14
+ // console.log(res?.body);
15
+ const rep = JSON.parse(res?.body);
16
+ // console.log(rep.total);
17
+ assert.ok(rep.total);
18
+ });
19
+ await t.test('GET /data', async () => {
20
+ const res = await app.inject({
21
+ method: 'GET',
22
+ url: '/api/data/gis.dataset.table',
23
+ });
24
+ // console.log(res);
25
+ const rep = JSON.parse(res?.body);
26
+ // console.log(rep.total);
27
+ assert.ok(rep.total);
28
+ });
29
+ await t.test('GET /form', async () => {
30
+ const res = await app.inject({
31
+ method: 'GET',
32
+ url: '/api/form/cp_building.form',
33
+ });
34
+ // console.log(res);
35
+ const rep = JSON.parse(res?.body);
36
+ // console.log(rep.total);
37
+ assert.ok(rep);
38
+ });
39
+ await t.test('GET /filter', async () => {
40
+ const res = await app.inject({
41
+ method: 'GET',
42
+ url: '/api/filter/gis.dataset.table',
43
+ });
44
+ // console.log(res);
45
+ const rep = JSON.parse(res?.body);
46
+ // console.log(rep.total);
47
+ assert.ok(rep);
48
+ });
49
+ });
@@ -1,18 +1,18 @@
1
- import config from '../config.js';
2
-
3
- Object.assign(config, {
4
- templateDir: 'test/templates',
5
- pg: {
6
- host: '192.168.3.160',
7
- port: 5434,
8
- database: 'mbk_rivne_dma',
9
- user: 'postgres',
10
- password: 'postgres',
11
- },
12
- redis: {
13
- host: '192.168.3.160',
14
- port: 6379,
15
- family: 4,
16
- },
17
- });
18
- export default config;
1
+ import config from '../config.js';
2
+
3
+ Object.assign(config, {
4
+ templateDir: 'test/templates',
5
+ pg: {
6
+ host: '192.168.3.160',
7
+ port: 5434,
8
+ database: 'mbk_rivne_dma',
9
+ user: 'postgres',
10
+ password: 'postgres',
11
+ },
12
+ redis: {
13
+ host: '192.168.3.160',
14
+ port: 6379,
15
+ family: 4,
16
+ },
17
+ });
18
+ export default config;