@opengis/fastify-table 1.0.97 → 1.1.1
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.
- package/.eslintrc.cjs +42 -42
- package/README.md +26 -26
- package/config.js +10 -10
- package/cron/controllers/cronApi.js +22 -22
- package/cron/controllers/utils/cronList.js +1 -1
- package/cron/funcs/addCron.js +131 -131
- package/cron/index.js +10 -10
- package/crud/controllers/utils/checkXSS.js +45 -45
- package/crud/controllers/utils/xssInjection.js +72 -72
- package/crud/funcs/dataUpdate.js +30 -30
- package/crud/funcs/getToken.js +27 -27
- package/crud/funcs/isFileExists.js +13 -13
- package/crud/funcs/setToken.js +53 -53
- package/crud/funcs/utils/logChanges.js +7 -4
- package/notification/controllers/testEmail.js +49 -49
- package/notification/funcs/utils/sendEmail.js +39 -39
- package/notification/index.js +38 -38
- package/package.json +1 -1
- package/pg/funcs/getPG.js +30 -30
- package/redis/funcs/getRedis.js +23 -23
- package/server/migrations/crm.sql +150 -150
- package/server/migrations/log.sql +80 -80
- package/server/templates/select/test.storage.data.json +3 -3
- package/server/templates/select/test.suggest.ato_new.json +2 -2
- package/server/templates/select/test.suggest.ato_new.sql +25 -25
- package/server/templates/select/test.suggest.data.json +4 -4
- package/server/templates/select/test.suggest.parent.sql +2 -2
- package/server.js +14 -14
- package/table/controllers/card.js +44 -44
- package/table/controllers/filter.js +37 -37
- package/table/controllers/form.js +28 -28
- package/table/controllers/search.js +80 -72
- package/table/controllers/utils/getSelect.js +20 -20
- package/table/controllers/utils/getTemplate.js +69 -28
- package/table/controllers/utils/getTemplatePath.js +40 -0
- package/table/controllers/utils/getTemplate_old.js +28 -0
- package/table/controllers/utils/getTemplates.js +18 -18
- package/table/controllers/utils/loadTemplate.js +1 -0
- package/table/controllers/utils/loadTemplatePath.js +1 -0
- package/table/index.js +84 -80
- package/test/api/crud.xss.test.js +72 -72
- package/test/api/notification.test.js +37 -37
- package/test/api/suggest.test.js +65 -65
- package/test/config.example +18 -18
- package/test/funcs/notification.test.js +31 -31
- package/test/funcs/pg.test.js +34 -34
- package/test/funcs/redis.test.js +19 -19
- package/test/templates/cls/test.json +9 -9
- package/test/templates/form/cp_building.form.json +32 -32
- package/test/templates/select/account_id.json +3 -3
- package/test/templates/select/storage.data.json +2 -2
- package/test/templates/table/gis.dataset.table.json +20 -20
- package/util/controllers/logger.file.js +90 -90
- package/util/controllers/next.id.js +4 -4
- package/util/controllers/properties.get.js +19 -19
- package/util/controllers/utils/checkUserAccess.js +19 -19
- package/util/controllers/utils/getRootDir.js +20 -20
- package/util/index.js +23 -23
- package/utils.js +8 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// import { readFile } from 'fs/promises';
|
|
2
|
+
import fs, { existsSync, readdirSync } from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import config from '../../../config.js';
|
|
5
|
+
|
|
6
|
+
import loadTemplatePath from './loadTemplatePath.js';
|
|
7
|
+
|
|
8
|
+
const cwd = process.cwd();
|
|
9
|
+
|
|
10
|
+
export default function getTemplatePath(type) {
|
|
11
|
+
if (!type) return null;
|
|
12
|
+
|
|
13
|
+
// form cache
|
|
14
|
+
|
|
15
|
+
if (loadTemplatePath[type]) return loadTemplatePath[type];
|
|
16
|
+
loadTemplatePath[type] = [];
|
|
17
|
+
|
|
18
|
+
const moduleList = [];
|
|
19
|
+
const moduleDir = path.join(cwd, 'module');
|
|
20
|
+
if (fs.existsSync(moduleDir) && !moduleList.length) {
|
|
21
|
+
readdirSync(moduleDir).forEach(el => moduleList.push(path.join(moduleDir, el, type)));
|
|
22
|
+
}
|
|
23
|
+
moduleList.push(path.join(cwd, config.templateDir || 'server/templates', type));
|
|
24
|
+
|
|
25
|
+
moduleList.forEach(el => {
|
|
26
|
+
const templateDir = el;
|
|
27
|
+
if (!existsSync(templateDir)) return;
|
|
28
|
+
|
|
29
|
+
const list = readdirSync(templateDir, { withFileTypes: true });
|
|
30
|
+
|
|
31
|
+
list.forEach(file => {
|
|
32
|
+
const isDir = file.isDirectory();
|
|
33
|
+
const name = isDir ? file.name : file.name.substring(0, file.name.lastIndexOf('.'));
|
|
34
|
+
const ext = isDir ? null : file.name.substring(file.name.lastIndexOf('.') + 1);
|
|
35
|
+
loadTemplatePath[type].push([name, path.join(templateDir, file.name), ext, isDir]);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return loadTemplatePath[type];
|
|
40
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { readFile } from 'fs/promises';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import config from '../../../config.js';
|
|
5
|
+
|
|
6
|
+
const loadTemplate = {};
|
|
7
|
+
|
|
8
|
+
export default async function getTemplateDir(type, name) {
|
|
9
|
+
if (!type) return null;
|
|
10
|
+
if (!name) return null;
|
|
11
|
+
|
|
12
|
+
const cwd = process.cwd();
|
|
13
|
+
const typeDir = path.join(cwd, (config.templateDir || 'server/templates'), type);
|
|
14
|
+
|
|
15
|
+
if (!loadTemplate[type]) {
|
|
16
|
+
const typeList = fs.existsSync(typeDir) ? fs.readdirSync(typeDir) : [];
|
|
17
|
+
loadTemplate[type] = typeList;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const fullname = loadTemplate[type].find((el) => path.parse(el).name === name);
|
|
21
|
+
const ext = fullname ? path.extname(fullname)?.slice(1) : null;
|
|
22
|
+
if (!ext) return null;
|
|
23
|
+
|
|
24
|
+
const sql = loadTemplate[type].includes(`${name}.sql`) ? await readFile(path.join(typeDir, `${name}.sql`), 'utf-8') : null;
|
|
25
|
+
const data = loadTemplate[type].includes(`${name}.json`) ? JSON.parse(await readFile(path.join(typeDir, `${name}.json`), 'utf-8')) : await readFile(path.join(typeDir, `${name}.${ext}`), 'utf-8');
|
|
26
|
+
if (sql) return { sql };
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import config from '../../../config.js';
|
|
4
|
-
|
|
5
|
-
const loadTemplate = {};
|
|
6
|
-
|
|
7
|
-
export default async function getTemplateDir(type) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import config from '../../../config.js';
|
|
4
|
+
|
|
5
|
+
const loadTemplate = {};
|
|
6
|
+
|
|
7
|
+
export default async function getTemplateDir(type) {
|
|
8
|
+
if (!type) return null;
|
|
9
|
+
|
|
10
|
+
const cwd = process.cwd();
|
|
11
|
+
const typeDir = path.join(cwd, (config.templateDir || 'server/templates'), type);
|
|
12
|
+
|
|
13
|
+
if (!loadTemplate[type]) {
|
|
14
|
+
const typeList = fs.existsSync(typeDir) ? fs.readdirSync(typeDir) : [];
|
|
15
|
+
loadTemplate[type] = typeList;
|
|
16
|
+
}
|
|
17
|
+
return loadTemplate[type];
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default {};
|
package/table/index.js
CHANGED
|
@@ -1,80 +1,84 @@
|
|
|
1
|
-
import suggest from './controllers/suggest.js';
|
|
2
|
-
import data from './controllers/data.js';
|
|
3
|
-
import table from './controllers/table.js';
|
|
4
|
-
import card from './controllers/card.js';
|
|
5
|
-
import search from './controllers/search.js';
|
|
6
|
-
import filter from './controllers/filter.js';
|
|
7
|
-
import form from './controllers/form.js';
|
|
8
|
-
import metaFormat from './funcs/metaFormat/index.js';
|
|
9
|
-
import getFilterSQL from './funcs/getFilterSQL/index.js';
|
|
10
|
-
import getTemplate from './controllers/utils/getTemplate.js';
|
|
11
|
-
import getSelect from './controllers/utils/getSelect.js';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
fastify.decorate('
|
|
69
|
-
fastify.decorate('
|
|
70
|
-
|
|
71
|
-
fastify.
|
|
72
|
-
|
|
73
|
-
fastify.get(`${prefix}/
|
|
74
|
-
fastify.get(`${prefix}/
|
|
75
|
-
fastify.get(`${prefix}/
|
|
76
|
-
fastify.get(`${prefix}/
|
|
77
|
-
fastify.get(`${prefix}/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
1
|
+
import suggest from './controllers/suggest.js';
|
|
2
|
+
import data from './controllers/data.js';
|
|
3
|
+
import table from './controllers/table.js';
|
|
4
|
+
import card from './controllers/card.js';
|
|
5
|
+
import search from './controllers/search.js';
|
|
6
|
+
import filter from './controllers/filter.js';
|
|
7
|
+
import form from './controllers/form.js';
|
|
8
|
+
import metaFormat from './funcs/metaFormat/index.js';
|
|
9
|
+
import getFilterSQL from './funcs/getFilterSQL/index.js';
|
|
10
|
+
import getTemplate from './controllers/utils/getTemplate.js';
|
|
11
|
+
import getSelect from './controllers/utils/getSelect.js';
|
|
12
|
+
|
|
13
|
+
import loadTemplatePath from './controllers/utils/loadTemplatePath.js';
|
|
14
|
+
|
|
15
|
+
const tableSchema = {
|
|
16
|
+
querystring1: {
|
|
17
|
+
page: { type: 'string', pattern: '^(\\d+)$' },
|
|
18
|
+
order: { type: 'string', pattern: '^(\\d+)$' },
|
|
19
|
+
filter: { type: 'string', pattern: '^([\\w\\d_-]+)=([\\w\\d_-]+)$' },
|
|
20
|
+
},
|
|
21
|
+
params: {
|
|
22
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
23
|
+
table: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const searchSchema = {
|
|
28
|
+
querystring: {
|
|
29
|
+
page: { type: 'string', pattern: '^(\\d+)$' },
|
|
30
|
+
limit: { type: 'string', pattern: '^(\\d+)$' },
|
|
31
|
+
order: { type: 'string', pattern: '^([\\w_.]+)$' },
|
|
32
|
+
desc: { type: 'string', pattern: '^(desc)|(asc)$' },
|
|
33
|
+
key: { type: 'string', pattern: '^([\\w\\d_]+)$' },
|
|
34
|
+
table: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
35
|
+
sql: { type: 'string', pattern: '^(\\d)$' },
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const suggestSchema = {
|
|
40
|
+
querystring: {
|
|
41
|
+
lang: { type: 'string', pattern: '^([\\w.]+)$' },
|
|
42
|
+
// parent: { type: 'string', pattern: '^([\\w,./]+)$' },
|
|
43
|
+
sel: { type: 'string', pattern: '^([\\w,./]+)$' },
|
|
44
|
+
name: { type: 'string', pattern: '^([\\w,./]+)$' },
|
|
45
|
+
// key: { type: 'string', pattern: '^([\\w\\d_]+)$' },
|
|
46
|
+
// val: { type: 'string', pattern: '^([\\w.,]+)$' },
|
|
47
|
+
sql: { type: 'string', pattern: '^(\\d)$' },
|
|
48
|
+
},
|
|
49
|
+
params: {
|
|
50
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const formSchema = {
|
|
55
|
+
params: {
|
|
56
|
+
form: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const filterSchema = {
|
|
61
|
+
params: {
|
|
62
|
+
table: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
async function plugin(fastify, config = {}) {
|
|
67
|
+
const prefix = config.prefix || '/api';
|
|
68
|
+
fastify.decorate('metaFormat', metaFormat);
|
|
69
|
+
fastify.decorate('getFilterSQL', getFilterSQL);
|
|
70
|
+
fastify.decorate('getTemplate', getTemplate);
|
|
71
|
+
fastify.decorate('getSelect', getSelect);
|
|
72
|
+
|
|
73
|
+
fastify.get(`${prefix}/suggest/:data`, { schema: suggestSchema }, suggest);
|
|
74
|
+
fastify.get(`${prefix}/data/:table/:id?`, { schema: tableSchema }, data); // vs.crm.data.api с node
|
|
75
|
+
fastify.get(`${prefix}/table/:table/:id`, { schema: tableSchema }, table);
|
|
76
|
+
fastify.get(`${prefix}/card/:table/:id`, { schema: tableSchema }, card);
|
|
77
|
+
fastify.get(`${prefix}/search`, { schema: searchSchema }, search);
|
|
78
|
+
|
|
79
|
+
fastify.get(`${prefix}/templates`, () => loadTemplatePath);
|
|
80
|
+
fastify.get(`${prefix}/filter/:table`, { schema: filterSchema }, filter);
|
|
81
|
+
fastify.get(`${prefix}/form/:form`, { schema: formSchema }, form);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export default plugin;
|
|
@@ -1,72 +1,72 @@
|
|
|
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.addHook('onRequest', async (req) => {
|
|
13
|
-
req.session = session;
|
|
14
|
-
});
|
|
15
|
-
// app.decorateRequest('session', session);
|
|
16
|
-
|
|
17
|
-
const prefix = config.prefix || '/api';
|
|
18
|
-
|
|
19
|
-
let addTokens;
|
|
20
|
-
let editTokens;
|
|
21
|
-
|
|
22
|
-
// before
|
|
23
|
-
t.test('setToken', async () => {
|
|
24
|
-
addTokens = setToken({
|
|
25
|
-
ids: [JSON.stringify({ add: 'gis.dataset', form: 'test.dataset.form' })],
|
|
26
|
-
mode: 'a',
|
|
27
|
-
uid: 1,
|
|
28
|
-
array: 1,
|
|
29
|
-
});
|
|
30
|
-
editTokens = setToken({
|
|
31
|
-
ids: [JSON.stringify({ id: '5400000', table: 'gis.dataset', form: 'test.dataset.form' })],
|
|
32
|
-
mode: 'w',
|
|
33
|
-
uid: 1,
|
|
34
|
-
array: 1,
|
|
35
|
-
});
|
|
36
|
-
assert.ok(addTokens.length === 1 && editTokens.length === 1, 'invalid token');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
await t.test('POST /insert', async () => {
|
|
40
|
-
const res = await app.inject({
|
|
41
|
-
method: 'POST',
|
|
42
|
-
url: `${prefix}/table/${addTokens[0]}`,
|
|
43
|
-
body: { dataset_name: '<a onClick="alert("XSS Injection")">xss injection</a>', dataset_id: '5400000' },
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const rep = JSON.parse(res?.body);
|
|
47
|
-
console.log(rep)
|
|
48
|
-
assert.ok(rep.status, 409);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
await t.test('PUT /update', async () => {
|
|
52
|
-
const res = await app.inject({
|
|
53
|
-
method: 'PUT',
|
|
54
|
-
url: `${prefix}/table/${editTokens[0]}/${editTokens[0]}`,
|
|
55
|
-
body: { editor_id: '11', dataset_name: '<a onClick="alert("XSS Injection")">xss injection</a>' },
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
const rep = JSON.parse(res?.body);
|
|
59
|
-
console.log(rep)
|
|
60
|
-
assert.equal(rep.status, 409);
|
|
61
|
-
});
|
|
62
|
-
await t.test('DELETE /delete', async () => {
|
|
63
|
-
const res = await app.inject({
|
|
64
|
-
method: 'DELETE',
|
|
65
|
-
url: `${prefix}/table/gis.dataset/5400000`,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const rep = JSON.parse(res?.body);
|
|
69
|
-
console.log(rep)
|
|
70
|
-
assert.ok(rep);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
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.addHook('onRequest', async (req) => {
|
|
13
|
+
req.session = session;
|
|
14
|
+
});
|
|
15
|
+
// app.decorateRequest('session', session);
|
|
16
|
+
|
|
17
|
+
const prefix = config.prefix || '/api';
|
|
18
|
+
|
|
19
|
+
let addTokens;
|
|
20
|
+
let editTokens;
|
|
21
|
+
|
|
22
|
+
// before
|
|
23
|
+
t.test('setToken', async () => {
|
|
24
|
+
addTokens = setToken({
|
|
25
|
+
ids: [JSON.stringify({ add: 'gis.dataset', form: 'test.dataset.form' })],
|
|
26
|
+
mode: 'a',
|
|
27
|
+
uid: 1,
|
|
28
|
+
array: 1,
|
|
29
|
+
});
|
|
30
|
+
editTokens = setToken({
|
|
31
|
+
ids: [JSON.stringify({ id: '5400000', table: 'gis.dataset', form: 'test.dataset.form' })],
|
|
32
|
+
mode: 'w',
|
|
33
|
+
uid: 1,
|
|
34
|
+
array: 1,
|
|
35
|
+
});
|
|
36
|
+
assert.ok(addTokens.length === 1 && editTokens.length === 1, 'invalid token');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
await t.test('POST /insert', async () => {
|
|
40
|
+
const res = await app.inject({
|
|
41
|
+
method: 'POST',
|
|
42
|
+
url: `${prefix}/table/${addTokens[0]}`,
|
|
43
|
+
body: { dataset_name: '<a onClick="alert("XSS Injection")">xss injection</a>', dataset_id: '5400000' },
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const rep = JSON.parse(res?.body);
|
|
47
|
+
console.log(rep)
|
|
48
|
+
assert.ok(rep.status, 409);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
await t.test('PUT /update', async () => {
|
|
52
|
+
const res = await app.inject({
|
|
53
|
+
method: 'PUT',
|
|
54
|
+
url: `${prefix}/table/${editTokens[0]}/${editTokens[0]}`,
|
|
55
|
+
body: { editor_id: '11', dataset_name: '<a onClick="alert("XSS Injection")">xss injection</a>' },
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const rep = JSON.parse(res?.body);
|
|
59
|
+
console.log(rep)
|
|
60
|
+
assert.equal(rep.status, 409);
|
|
61
|
+
});
|
|
62
|
+
await t.test('DELETE /delete', async () => {
|
|
63
|
+
const res = await app.inject({
|
|
64
|
+
method: 'DELETE',
|
|
65
|
+
url: `${prefix}/table/gis.dataset/5400000`,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const rep = JSON.parse(res?.body);
|
|
69
|
+
console.log(rep)
|
|
70
|
+
assert.ok(rep);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -1,37 +1,37 @@
|
|
|
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
|
-
|
|
11
|
-
import pgClients from '../../pg/pgClients.js';
|
|
12
|
-
|
|
13
|
-
test('api && funcs notification', async (t) => {
|
|
14
|
-
const app = await build(t);
|
|
15
|
-
const pg = pgClients.client;
|
|
16
|
-
/*
|
|
17
|
-
// require dependency
|
|
18
|
-
await t.test('GET /auth', async () => {
|
|
19
|
-
const res = await app.inject({
|
|
20
|
-
method: 'GET',
|
|
21
|
-
url: `/api/login?username=${config.testUser?.username}&password=${config.testUser?.password}`,
|
|
22
|
-
});
|
|
23
|
-
assert.ok(res.statusCode);
|
|
24
|
-
});
|
|
25
|
-
await t.test('GET /notification', async () => {
|
|
26
|
-
const res = await app.inject({
|
|
27
|
-
method: 'GET',
|
|
28
|
-
url: '/api/notification',
|
|
29
|
-
});
|
|
30
|
-
const rep = JSON.parse(res?.body);
|
|
31
|
-
assert.ok(rep.time);
|
|
32
|
-
}); */
|
|
33
|
-
/* await t.test('GET /notification', async () => {
|
|
34
|
-
const rep = await userNotifications({ pg, session });
|
|
35
|
-
assert.ok(rep.time);
|
|
36
|
-
}); */
|
|
37
|
-
});
|
|
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
|
+
|
|
11
|
+
import pgClients from '../../pg/pgClients.js';
|
|
12
|
+
|
|
13
|
+
test('api && funcs notification', async (t) => {
|
|
14
|
+
const app = await build(t);
|
|
15
|
+
const pg = pgClients.client;
|
|
16
|
+
/*
|
|
17
|
+
// require dependency
|
|
18
|
+
await t.test('GET /auth', async () => {
|
|
19
|
+
const res = await app.inject({
|
|
20
|
+
method: 'GET',
|
|
21
|
+
url: `/api/login?username=${config.testUser?.username}&password=${config.testUser?.password}`,
|
|
22
|
+
});
|
|
23
|
+
assert.ok(res.statusCode);
|
|
24
|
+
});
|
|
25
|
+
await t.test('GET /notification', async () => {
|
|
26
|
+
const res = await app.inject({
|
|
27
|
+
method: 'GET',
|
|
28
|
+
url: '/api/notification',
|
|
29
|
+
});
|
|
30
|
+
const rep = JSON.parse(res?.body);
|
|
31
|
+
assert.ok(rep.time);
|
|
32
|
+
}); */
|
|
33
|
+
/* await t.test('GET /notification', async () => {
|
|
34
|
+
const rep = await userNotifications({ pg, session });
|
|
35
|
+
assert.ok(rep.time);
|
|
36
|
+
}); */
|
|
37
|
+
});
|
package/test/api/suggest.test.js
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
|
|
4
|
-
import build from '../../helper.js';
|
|
5
|
-
|
|
6
|
-
test('api suggest', async (t) => {
|
|
7
|
-
const app = await build(t);
|
|
8
|
-
|
|
9
|
-
await t.test('GET /suggest', async () => {
|
|
10
|
-
const res = await app.inject({
|
|
11
|
-
method: 'GET',
|
|
12
|
-
url: `/api/suggest/test.storage.data`,
|
|
13
|
-
});
|
|
14
|
-
const rep = JSON.parse(res?.body);
|
|
15
|
-
// console.log(rep);
|
|
16
|
-
assert.equal(res?.statusCode, 200);
|
|
17
|
-
assert.ok(rep?.count);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
await t.test('GET /suggest key query', async () => {
|
|
21
|
-
const key = 'Новокиївка';
|
|
22
|
-
const res = await app.inject({
|
|
23
|
-
method: 'GET',
|
|
24
|
-
url: `/api/suggest/test.suggest.ato_new?key=${key}`,
|
|
25
|
-
});
|
|
26
|
-
const rep = JSON.parse(res?.body);
|
|
27
|
-
// console.log(rep);
|
|
28
|
-
assert.equal(res?.statusCode, 200);
|
|
29
|
-
assert.ok(rep?.count);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
await t.test('GET /suggest key searchColumn', async () => {
|
|
33
|
-
const key = 'data_address.addr_city';
|
|
34
|
-
const res = await app.inject({
|
|
35
|
-
method: 'GET',
|
|
36
|
-
url: `/api/suggest/test.storage.data?key=${key}`,
|
|
37
|
-
});
|
|
38
|
-
const rep = JSON.parse(res?.body);
|
|
39
|
-
// console.log(rep);
|
|
40
|
-
assert.equal(res?.statusCode, 200);
|
|
41
|
-
assert.ok(rep?.count);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
await t.test('GET /suggest інша db', async () => {
|
|
45
|
-
const res = await app.inject({
|
|
46
|
-
method: 'GET',
|
|
47
|
-
url: `/api/suggest/test.suggest.data`,
|
|
48
|
-
});
|
|
49
|
-
const rep = JSON.parse(res?.body);
|
|
50
|
-
// console.log(rep);
|
|
51
|
-
assert.equal(res?.statusCode, 200);
|
|
52
|
-
assert.ok(rep?.count);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
await t.test('GET /suggest parent', async () => {
|
|
56
|
-
const parent = '3206158274160231699';
|
|
57
|
-
const res = await app.inject({
|
|
58
|
-
method: 'GET',
|
|
59
|
-
url: `/api/suggest/test.suggest.parent?parent=${parent}`,
|
|
60
|
-
});
|
|
61
|
-
const rep = JSON.parse(res?.body);
|
|
62
|
-
// console.log(rep);
|
|
63
|
-
assert.equal(res?.statusCode, 200);
|
|
64
|
-
assert.ok(rep?.count);
|
|
65
|
-
});
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
|
|
4
|
+
import build from '../../helper.js';
|
|
5
|
+
|
|
6
|
+
test('api suggest', async (t) => {
|
|
7
|
+
const app = await build(t);
|
|
8
|
+
|
|
9
|
+
await t.test('GET /suggest', async () => {
|
|
10
|
+
const res = await app.inject({
|
|
11
|
+
method: 'GET',
|
|
12
|
+
url: `/api/suggest/test.storage.data`,
|
|
13
|
+
});
|
|
14
|
+
const rep = JSON.parse(res?.body);
|
|
15
|
+
// console.log(rep);
|
|
16
|
+
assert.equal(res?.statusCode, 200);
|
|
17
|
+
assert.ok(rep?.count);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
await t.test('GET /suggest key query', async () => {
|
|
21
|
+
const key = 'Новокиївка';
|
|
22
|
+
const res = await app.inject({
|
|
23
|
+
method: 'GET',
|
|
24
|
+
url: `/api/suggest/test.suggest.ato_new?key=${key}`,
|
|
25
|
+
});
|
|
26
|
+
const rep = JSON.parse(res?.body);
|
|
27
|
+
// console.log(rep);
|
|
28
|
+
assert.equal(res?.statusCode, 200);
|
|
29
|
+
assert.ok(rep?.count);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
await t.test('GET /suggest key searchColumn', async () => {
|
|
33
|
+
const key = 'data_address.addr_city';
|
|
34
|
+
const res = await app.inject({
|
|
35
|
+
method: 'GET',
|
|
36
|
+
url: `/api/suggest/test.storage.data?key=${key}`,
|
|
37
|
+
});
|
|
38
|
+
const rep = JSON.parse(res?.body);
|
|
39
|
+
// console.log(rep);
|
|
40
|
+
assert.equal(res?.statusCode, 200);
|
|
41
|
+
assert.ok(rep?.count);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
await t.test('GET /suggest інша db', async () => {
|
|
45
|
+
const res = await app.inject({
|
|
46
|
+
method: 'GET',
|
|
47
|
+
url: `/api/suggest/test.suggest.data`,
|
|
48
|
+
});
|
|
49
|
+
const rep = JSON.parse(res?.body);
|
|
50
|
+
// console.log(rep);
|
|
51
|
+
assert.equal(res?.statusCode, 200);
|
|
52
|
+
assert.ok(rep?.count);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
await t.test('GET /suggest parent', async () => {
|
|
56
|
+
const parent = '3206158274160231699';
|
|
57
|
+
const res = await app.inject({
|
|
58
|
+
method: 'GET',
|
|
59
|
+
url: `/api/suggest/test.suggest.parent?parent=${parent}`,
|
|
60
|
+
});
|
|
61
|
+
const rep = JSON.parse(res?.body);
|
|
62
|
+
// console.log(rep);
|
|
63
|
+
assert.equal(res?.statusCode, 200);
|
|
64
|
+
assert.ok(rep?.count);
|
|
65
|
+
});
|
|
66
66
|
})
|