@opengis/fastify-table 1.0.36 → 1.0.37
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/Changelog.md +4 -0
- package/crud/controllers/insert.js +29 -29
- package/crud/controllers/update.js +31 -31
- package/crud/funcs/getOpt.js +10 -10
- package/crud/funcs/setOpt.js +16 -16
- package/crud/index.js +29 -29
- package/helper.js +28 -28
- package/notification/controllers/userNotifications.js +19 -19
- package/notification/funcs/addNotification.js +8 -8
- package/notification/index.js +19 -19
- package/package.json +1 -1
- package/pg/pgClients.js +20 -20
- package/policy/funcs/checkPolicy.js +74 -74
- package/policy/funcs/sqlInjection.js +33 -33
- package/policy/index.js +14 -14
- package/redis/client.js +8 -8
- package/redis/funcs/redisClients.js +2 -2
- package/redis/index.js +19 -19
- package/server/templates/form/test.dataset.form.json +411 -411
- package/server/templates/select/test.storage.data.json +2 -2
- package/server/templates/table/test.dataset.table.json +24 -24
- package/table/controllers/data.js +57 -57
- package/table/controllers/form.js +10 -10
- package/table/controllers/suggest.js +60 -60
- package/table/controllers/utils/getSelect.js +20 -20
- package/table/controllers/utils/getSelectMeta.js +66 -66
- package/table/controllers/utils/getTemplate.js +28 -28
- package/table/funcs/getFilterSQL/index.js +75 -75
- package/table/funcs/getFilterSQL/util/formatValue.js +142 -142
- package/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
- package/table/funcs/getFilterSQL/util/getFilterQuery.js +73 -73
- package/table/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
- package/table/funcs/metaFormat/getSelectVal.js +20 -20
- package/table/funcs/metaFormat/index.js +26 -26
- package/table/index.js +42 -42
- package/test/api/crud.test.js +56 -56
- package/test/api/crud.xss.test.js +71 -71
- package/test/api/notification.test.js +37 -37
- package/test/api/table.test.js +57 -57
- package/test/funcs/notification.test.js +31 -31
- package/widget/controllers/utils/historyFormat.js +76 -76
- package/widget/controllers/utils/obj2db.js +13 -13
- package/widget/controllers/widget.del.js +44 -41
- package/widget/controllers/widget.get.js +86 -77
- package/widget/controllers/widget.set.js +70 -64
- package/widget/index.js +29 -29
|
@@ -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,42 +1,42 @@
|
|
|
1
|
-
import suggest from './controllers/suggest.js';
|
|
2
|
-
import data from './controllers/data.js';
|
|
3
|
-
import search from './controllers/search.js';
|
|
4
|
-
import filter from './controllers/filter.js';
|
|
5
|
-
import form from './controllers/form.js';
|
|
6
|
-
import metaFormat from './funcs/metaFormat/index.js';
|
|
7
|
-
import getFilterSQL from './funcs/getFilterSQL/index.js';
|
|
8
|
-
import getTemplate from './controllers/utils/getTemplate.js';
|
|
9
|
-
|
|
10
|
-
const tableSchema = {
|
|
11
|
-
querystring: {
|
|
12
|
-
page: { type: 'number' },
|
|
13
|
-
order: { type: 'string' },
|
|
14
|
-
filter: { type: 'string' },
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const searchTableSchema = {
|
|
19
|
-
querystring: {
|
|
20
|
-
page: { type: 'number' },
|
|
21
|
-
order: { type: 'string' },
|
|
22
|
-
desc: { type: 'string' },
|
|
23
|
-
filter: { type: 'string' },
|
|
24
|
-
key: { type: 'string' },
|
|
25
|
-
table: { type: 'string' },
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
async function plugin(fastify, config = {}) {
|
|
30
|
-
const prefix = config.prefix || '/api';
|
|
31
|
-
fastify.decorate('metaFormat', metaFormat);
|
|
32
|
-
fastify.decorate('getFilterSQL', getFilterSQL);
|
|
33
|
-
fastify.decorate('getTemplate', getTemplate);
|
|
34
|
-
|
|
35
|
-
fastify.get(`${prefix}/suggest/:data`, {}, suggest);
|
|
36
|
-
fastify.get(`${prefix}/data/:table/:id?`, { schema: tableSchema }, data); // vs.crm.data.api с node
|
|
37
|
-
fastify.get(`${prefix}/search`, { schema: searchTableSchema }, search);
|
|
38
|
-
fastify.get(`${prefix}/filter/:table`, {}, filter);
|
|
39
|
-
fastify.get(`${prefix}/form/:form`, {}, form);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export default plugin;
|
|
1
|
+
import suggest from './controllers/suggest.js';
|
|
2
|
+
import data from './controllers/data.js';
|
|
3
|
+
import search from './controllers/search.js';
|
|
4
|
+
import filter from './controllers/filter.js';
|
|
5
|
+
import form from './controllers/form.js';
|
|
6
|
+
import metaFormat from './funcs/metaFormat/index.js';
|
|
7
|
+
import getFilterSQL from './funcs/getFilterSQL/index.js';
|
|
8
|
+
import getTemplate from './controllers/utils/getTemplate.js';
|
|
9
|
+
|
|
10
|
+
const tableSchema = {
|
|
11
|
+
querystring: {
|
|
12
|
+
page: { type: 'number' },
|
|
13
|
+
order: { type: 'string' },
|
|
14
|
+
filter: { type: 'string' },
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const searchTableSchema = {
|
|
19
|
+
querystring: {
|
|
20
|
+
page: { type: 'number' },
|
|
21
|
+
order: { type: 'string' },
|
|
22
|
+
desc: { type: 'string' },
|
|
23
|
+
filter: { type: 'string' },
|
|
24
|
+
key: { type: 'string' },
|
|
25
|
+
table: { type: 'string' },
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
async function plugin(fastify, config = {}) {
|
|
30
|
+
const prefix = config.prefix || '/api';
|
|
31
|
+
fastify.decorate('metaFormat', metaFormat);
|
|
32
|
+
fastify.decorate('getFilterSQL', getFilterSQL);
|
|
33
|
+
fastify.decorate('getTemplate', getTemplate);
|
|
34
|
+
|
|
35
|
+
fastify.get(`${prefix}/suggest/:data`, {}, suggest);
|
|
36
|
+
fastify.get(`${prefix}/data/:table/:id?`, { schema: tableSchema }, data); // vs.crm.data.api с node
|
|
37
|
+
fastify.get(`${prefix}/search`, { schema: searchTableSchema }, search);
|
|
38
|
+
fastify.get(`${prefix}/filter/:table`, {}, filter);
|
|
39
|
+
fastify.get(`${prefix}/form/:form`, {}, form);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default plugin;
|
package/test/api/crud.test.js
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
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}/table/gis.map`,
|
|
16
|
-
body: {
|
|
17
|
-
alias: 'testMap',
|
|
18
|
-
map_id: '5400000',
|
|
19
|
-
ord: 1,
|
|
20
|
-
enabled: false,
|
|
21
|
-
tags: ['unit', 'test'],
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const rep = JSON.parse(res?.body);
|
|
26
|
-
assert.ok(rep.rows ? rep.rows[0]?.map_id : rep.map_id);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
await t.test('PUT /update', async () => {
|
|
30
|
-
const res = await app.inject({
|
|
31
|
-
method: 'PUT',
|
|
32
|
-
url: `${prefix}/table/gis.map/5400000`,
|
|
33
|
-
body: {
|
|
34
|
-
editor_id: '11',
|
|
35
|
-
alias: 'testMapEdit',
|
|
36
|
-
map_id: '5400000',
|
|
37
|
-
ord: 2,
|
|
38
|
-
enabled: true,
|
|
39
|
-
tags: ['unittest'],
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
const rep = JSON.parse(res?.body);
|
|
44
|
-
assert.equal(rep.rows ? rep.rows[0]?.editor_id : rep.editor_id, '11');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
await t.test('DELETE /delete', async () => {
|
|
48
|
-
const res = await app.inject({
|
|
49
|
-
method: 'DELETE',
|
|
50
|
-
url: `${prefix}/table/gis.map/5400000`,
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const rep = JSON.parse(res?.body);
|
|
54
|
-
assert.ok(rep);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
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}/table/gis.map`,
|
|
16
|
+
body: {
|
|
17
|
+
alias: 'testMap',
|
|
18
|
+
map_id: '5400000',
|
|
19
|
+
ord: 1,
|
|
20
|
+
enabled: false,
|
|
21
|
+
tags: ['unit', 'test'],
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const rep = JSON.parse(res?.body);
|
|
26
|
+
assert.ok(rep.rows ? rep.rows[0]?.map_id : rep.map_id);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
await t.test('PUT /update', async () => {
|
|
30
|
+
const res = await app.inject({
|
|
31
|
+
method: 'PUT',
|
|
32
|
+
url: `${prefix}/table/gis.map/5400000`,
|
|
33
|
+
body: {
|
|
34
|
+
editor_id: '11',
|
|
35
|
+
alias: 'testMapEdit',
|
|
36
|
+
map_id: '5400000',
|
|
37
|
+
ord: 2,
|
|
38
|
+
enabled: true,
|
|
39
|
+
tags: ['unittest'],
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const rep = JSON.parse(res?.body);
|
|
44
|
+
assert.equal(rep.rows ? rep.rows[0]?.editor_id : rep.editor_id, '11');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
await t.test('DELETE /delete', async () => {
|
|
48
|
+
const res = await app.inject({
|
|
49
|
+
method: 'DELETE',
|
|
50
|
+
url: `${prefix}/table/gis.map/5400000`,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const rep = JSON.parse(res?.body);
|
|
54
|
+
assert.ok(rep);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -1,71 +1,71 @@
|
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
assert.ok(rep);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
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
|
+
|
|
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
|
+
|
|
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
|
+
assert.ok(rep);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -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/table.test.js
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
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/test.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/test.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 /search', async () => {
|
|
30
|
-
const res = await app.inject({
|
|
31
|
-
method: 'GET',
|
|
32
|
-
url: '/api/search?table=test.dataset.table&key=0',
|
|
33
|
-
});
|
|
34
|
-
const rep = JSON.parse(res?.body);
|
|
35
|
-
assert.ok(rep.total);
|
|
36
|
-
});
|
|
37
|
-
await t.test('GET /form', async () => {
|
|
38
|
-
const res = await app.inject({
|
|
39
|
-
method: 'GET',
|
|
40
|
-
url: '/api/form/test.dataset.form',
|
|
41
|
-
});
|
|
42
|
-
// console.log(res);
|
|
43
|
-
const rep = JSON.parse(res?.body);
|
|
44
|
-
// console.log(rep.total);
|
|
45
|
-
assert.ok(rep);
|
|
46
|
-
});
|
|
47
|
-
await t.test('GET /filter', async () => {
|
|
48
|
-
const res = await app.inject({
|
|
49
|
-
method: 'GET',
|
|
50
|
-
url: '/api/filter/test.dataset.table',
|
|
51
|
-
});
|
|
52
|
-
// console.log(res);
|
|
53
|
-
const rep = JSON.parse(res?.body);
|
|
54
|
-
// console.log(rep.total);
|
|
55
|
-
assert.ok(rep);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
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/test.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/test.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 /search', async () => {
|
|
30
|
+
const res = await app.inject({
|
|
31
|
+
method: 'GET',
|
|
32
|
+
url: '/api/search?table=test.dataset.table&key=0',
|
|
33
|
+
});
|
|
34
|
+
const rep = JSON.parse(res?.body);
|
|
35
|
+
assert.ok(rep.total);
|
|
36
|
+
});
|
|
37
|
+
await t.test('GET /form', async () => {
|
|
38
|
+
const res = await app.inject({
|
|
39
|
+
method: 'GET',
|
|
40
|
+
url: '/api/form/test.dataset.form',
|
|
41
|
+
});
|
|
42
|
+
// console.log(res);
|
|
43
|
+
const rep = JSON.parse(res?.body);
|
|
44
|
+
// console.log(rep.total);
|
|
45
|
+
assert.ok(rep);
|
|
46
|
+
});
|
|
47
|
+
await t.test('GET /filter', async () => {
|
|
48
|
+
const res = await app.inject({
|
|
49
|
+
method: 'GET',
|
|
50
|
+
url: '/api/filter/test.dataset.table',
|
|
51
|
+
});
|
|
52
|
+
// console.log(res);
|
|
53
|
+
const rep = JSON.parse(res?.body);
|
|
54
|
+
// console.log(rep.total);
|
|
55
|
+
assert.ok(rep);
|
|
56
|
+
});
|
|
57
|
+
});
|