@opengis/fastify-table 1.0.37 → 1.0.39
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/index.js +50 -39
- package/package.json +2 -2
- package/table/controllers/data.js +57 -57
- package/test/api/notification.test.js +37 -37
- package/test/api/table.test.js +57 -57
- package/test/funcs/crud.test.js +2 -2
- package/test/funcs/notification.test.js +31 -31
package/Changelog.md
CHANGED
package/index.js
CHANGED
|
@@ -1,39 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
config.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (!fastify.
|
|
24
|
-
fastify.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
1
|
+
import path from 'path';
|
|
2
|
+
|
|
3
|
+
import fp from 'fastify-plugin';
|
|
4
|
+
import config from './config.js';
|
|
5
|
+
// import rclient from './redis/client.js';
|
|
6
|
+
|
|
7
|
+
import redisPlugin from './redis/index.js';
|
|
8
|
+
import pgPlugin from './pg/index.js';
|
|
9
|
+
import tablePlugin from './table/index.js';
|
|
10
|
+
import notificationPlugin from './notification/index.js';
|
|
11
|
+
import widgetPlugin from './widget/index.js';
|
|
12
|
+
import crudPlugin from './crud/index.js';
|
|
13
|
+
import policyPlugin from './policy/index.js';
|
|
14
|
+
|
|
15
|
+
async function plugin(fastify, opt) {
|
|
16
|
+
// console.log(opt);
|
|
17
|
+
config.pg = opt.pg;
|
|
18
|
+
config.redis = opt.redis;
|
|
19
|
+
config.root = opt.root;
|
|
20
|
+
config.mapServerRoot = opt.mapServerRoot;
|
|
21
|
+
|
|
22
|
+
// independent npm start / unit test
|
|
23
|
+
if (!fastify.config) {
|
|
24
|
+
fastify.decorate('config', config);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
fastify.decorate('getFolder', (req, type = 'server') => {
|
|
28
|
+
if (!['server', 'local'].includes(type)) throw new Error('params type is invalid');
|
|
29
|
+
const types = { local: req.root, server: req.mapServerRoot };
|
|
30
|
+
const filepath = path.posix.join(types[type] || '/data/local', req.folder || '');
|
|
31
|
+
return filepath;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (!fastify.funcs) {
|
|
35
|
+
fastify.addHook('onRequest', async (req) => {
|
|
36
|
+
req.funcs = fastify;
|
|
37
|
+
});
|
|
38
|
+
// fastify.decorateRequest('funcs', fastify);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
policyPlugin(fastify);
|
|
42
|
+
redisPlugin(fastify);
|
|
43
|
+
await pgPlugin(fastify, opt);
|
|
44
|
+
tablePlugin(fastify, opt);
|
|
45
|
+
crudPlugin(fastify, opt);
|
|
46
|
+
notificationPlugin(fastify, opt);
|
|
47
|
+
widgetPlugin(fastify, opt);
|
|
48
|
+
}
|
|
49
|
+
export default fp(plugin);
|
|
50
|
+
// export { rclient };
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengis/fastify-table",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.39",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "core-plugins",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
|
|
9
|
-
"test": "
|
|
9
|
+
"test": "node --test"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"ioredis": "^5.3.2",
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import getTemplate from './utils/getTemplate.js';
|
|
2
|
-
import getFilterSQL from '../funcs/getFilterSQL/index.js';
|
|
3
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
-
import metaFormat from '../funcs/metaFormat/index.js';
|
|
5
|
-
|
|
6
|
-
const maxLimit = 100;
|
|
7
|
-
export default async function data(req) {
|
|
8
|
-
const time = Date.now();
|
|
9
|
-
const {
|
|
10
|
-
pg, params, query = {},
|
|
11
|
-
} = req;
|
|
12
|
-
|
|
13
|
-
const loadTable = await getTemplate('table', params.table);
|
|
14
|
-
|
|
15
|
-
if (!loadTable) { return { status: 404, message: 'not found' }; }
|
|
16
|
-
|
|
17
|
-
const {
|
|
18
|
-
table, columns, sql, filters, form, meta,
|
|
19
|
-
} = loadTable;
|
|
20
|
-
const { pk } = await getMeta(table);
|
|
21
|
-
|
|
22
|
-
const cols = columns.map((el) => el.name || el).join(',');
|
|
23
|
-
const sqlTable = sql?.filter?.((el) => !el?.disabled && el?.sql?.replace).map((el, i) => ` left join lateral (${el.sql}) ${el.name || `t${i}`} on 1=1 `)?.join('') || '';
|
|
24
|
-
|
|
25
|
-
const fData = query.filter ? await getFilterSQL({
|
|
26
|
-
filter: query.filter,
|
|
27
|
-
table: params.table,
|
|
28
|
-
json: 1,
|
|
29
|
-
}) : {};
|
|
30
|
-
|
|
31
|
-
const keyQuery = query.key && loadTable.key && !params.id ? `${loadTable.key}=$1` : null;
|
|
32
|
-
|
|
33
|
-
const limit = Math.min(maxLimit, +(query.limit || 10));
|
|
34
|
-
|
|
35
|
-
const offset = query.page && query.page > 0 ? ` offset ${(query.page - 1) * limit}` : '';
|
|
36
|
-
// id, query, filter
|
|
37
|
-
const [orderColumn, orderDir] = (query.order || loadTable.order || '').split(
|
|
38
|
-
|
|
39
|
-
const order = cols.includes(orderColumn) && orderColumn?.length ? `order by ${orderColumn} ${query.desc || orderDir === 'desc' ? 'desc' : ''}` : '';
|
|
40
|
-
const state = loadTable.filterState && query.state ? loadTable.filterState[query.state]?.sql : null;
|
|
41
|
-
const custom = loadTable.filterCustom && query.custom ? loadTable.filterCustom[query.custom]?.sql : null;
|
|
42
|
-
const search = loadTable.meta?.search && query.search ? `(${loadTable.meta?.search.split(',').map(el => `${el} ilike '%${query.search}%'`).join(' or ')})` : null;
|
|
43
|
-
|
|
44
|
-
const where = [(params.id ? ` "${pk}" = $1` : null), keyQuery, loadTable.query, fData.q, state, custom, search].filter((el) => el);
|
|
45
|
-
const q = `select ${pk ? `"${pk}" as id,` : ''} ${query.id || query.key ? '*' : cols || '*'} from ${table} t ${sqlTable} where ${where.join(' and ') || 'true'} ${order} ${offset} limit ${limit}`;
|
|
46
|
-
|
|
47
|
-
if (query.sql === '1') { return q; }
|
|
48
|
-
|
|
49
|
-
const { rows } = await pg.query(q, (params.id ? [params.id] : null) || (query.key && loadTable.key ? [query.key] : []));
|
|
50
|
-
|
|
51
|
-
const total = keyQuery || params.id ? rows.length : await pg.queryCache(`select count(*) from ${table} t where ${where.join(' and ') || 'true'}`).then((el) => el?.rows[0]?.count);
|
|
52
|
-
|
|
53
|
-
await metaFormat({ rows, table: params.table });
|
|
54
|
-
return {
|
|
55
|
-
time: Date.now() - time, total, count: rows.length, pk, form, rows, meta, columns, filters,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
1
|
+
import getTemplate from './utils/getTemplate.js';
|
|
2
|
+
import getFilterSQL from '../funcs/getFilterSQL/index.js';
|
|
3
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
+
import metaFormat from '../funcs/metaFormat/index.js';
|
|
5
|
+
|
|
6
|
+
const maxLimit = 100;
|
|
7
|
+
export default async function data(req) {
|
|
8
|
+
const time = Date.now();
|
|
9
|
+
const {
|
|
10
|
+
pg, params, query = {},
|
|
11
|
+
} = req;
|
|
12
|
+
|
|
13
|
+
const loadTable = await getTemplate('table', params.table);
|
|
14
|
+
|
|
15
|
+
if (!loadTable) { return { status: 404, message: 'not found' }; }
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
table, columns, sql, filters, form, meta,
|
|
19
|
+
} = loadTable;
|
|
20
|
+
const { pk } = await getMeta(table);
|
|
21
|
+
|
|
22
|
+
const cols = columns.map((el) => el.name || el).join(',');
|
|
23
|
+
const sqlTable = sql?.filter?.((el) => !el?.disabled && el?.sql?.replace).map((el, i) => ` left join lateral (${el.sql}) ${el.name || `t${i}`} on 1=1 `)?.join('') || '';
|
|
24
|
+
|
|
25
|
+
const fData = query.filter ? await getFilterSQL({
|
|
26
|
+
filter: query.filter,
|
|
27
|
+
table: params.table,
|
|
28
|
+
json: 1,
|
|
29
|
+
}) : {};
|
|
30
|
+
|
|
31
|
+
const keyQuery = query.key && loadTable.key && !params.id ? `${loadTable.key}=$1` : null;
|
|
32
|
+
|
|
33
|
+
const limit = Math.min(maxLimit, +(query.limit || 10));
|
|
34
|
+
|
|
35
|
+
const offset = query.page && query.page > 0 ? ` offset ${(query.page - 1) * limit}` : '';
|
|
36
|
+
// id, query, filter
|
|
37
|
+
const [orderColumn, orderDir] = (query.order || loadTable.order || '').split(/[- ]/);
|
|
38
|
+
|
|
39
|
+
const order = cols.includes(orderColumn) && orderColumn?.length ? `order by ${orderColumn} ${query.desc || orderDir === 'desc' ? 'desc' : ''}` : '';
|
|
40
|
+
const state = loadTable.filterState && query.state ? loadTable.filterState[query.state]?.sql : null;
|
|
41
|
+
const custom = loadTable.filterCustom && query.custom ? loadTable.filterCustom[query.custom]?.sql : null;
|
|
42
|
+
const search = loadTable.meta?.search && query.search ? `(${loadTable.meta?.search.split(',').map(el => `${el} ilike '%${query.search}%'`).join(' or ')})` : null;
|
|
43
|
+
|
|
44
|
+
const where = [(params.id ? ` "${pk}" = $1` : null), keyQuery, loadTable.query, fData.q, state, custom, search].filter((el) => el);
|
|
45
|
+
const q = `select ${pk ? `"${pk}" as id,` : ''} ${query.id || query.key ? '*' : cols || '*'} from ${table} t ${sqlTable} where ${where.join(' and ') || 'true'} ${order} ${offset} limit ${limit}`;
|
|
46
|
+
|
|
47
|
+
if (query.sql === '1') { return q; }
|
|
48
|
+
|
|
49
|
+
const { rows } = await pg.query(q, (params.id ? [params.id] : null) || (query.key && loadTable.key ? [query.key] : []));
|
|
50
|
+
|
|
51
|
+
const total = keyQuery || params.id ? rows.length : await pg.queryCache(`select count(*) from ${table} t where ${where.join(' and ') || 'true'}`).then((el) => el?.rows[0]?.count);
|
|
52
|
+
|
|
53
|
+
await metaFormat({ rows, table: params.table });
|
|
54
|
+
return {
|
|
55
|
+
time: Date.now() - time, total, count: rows.length, pk, form, rows, meta, columns, filters,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -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
|
+
});
|
package/test/funcs/crud.test.js
CHANGED
|
@@ -25,7 +25,7 @@ test('funcs crud', async (t) => {
|
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
const id = (Math.random() * 10000).toFixed();
|
|
28
|
-
await t.test('dataInsert', async () => {
|
|
28
|
+
/* await t.test('dataInsert', async () => {
|
|
29
29
|
const data = await dataInsert({ table: 'gis.dataset', data: { dataset_id: id, dataset_name: '222' } });
|
|
30
30
|
assert.equal(data.dataset_id, id);
|
|
31
31
|
});
|
|
@@ -38,7 +38,7 @@ test('funcs crud', async (t) => {
|
|
|
38
38
|
await t.test('dataDelete', async () => {
|
|
39
39
|
const data = await dataDelete({ table: 'gis.dataset', id });
|
|
40
40
|
assert.ok(data);
|
|
41
|
-
});
|
|
41
|
+
}); */
|
|
42
42
|
|
|
43
43
|
await t.test('isFileExists', async () => {
|
|
44
44
|
const data = await isFileExists({ filepath: '../../crud/funcs/isFileExists.js' });
|
|
@@ -1,31 +1,31 @@
|
|
|
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
|
-
import addNotification from '../../notification/funcs/addNotification.js';
|
|
8
|
-
|
|
9
|
-
import pgClients from '../../pg/pgClients.js';
|
|
10
|
-
|
|
11
|
-
test('notification funcs', async (t) => {
|
|
12
|
-
await build(t);
|
|
13
|
-
const pg = pgClients.client;
|
|
14
|
-
let resp;
|
|
15
|
-
await t.test('addNotification', async () => {
|
|
16
|
-
resp = await addNotification({
|
|
17
|
-
pg,
|
|
18
|
-
|
|
19
|
-
title: 'test title',
|
|
20
|
-
body: 'test body',
|
|
21
|
-
link: 'http://link',
|
|
22
|
-
notificationType: 'mention',
|
|
23
|
-
uid: config.testUser?.uid || '1',
|
|
24
|
-
});
|
|
25
|
-
assert.ok(resp.id);
|
|
26
|
-
});
|
|
27
|
-
await t.test('clean up after test, before pool is closed', async () => {
|
|
28
|
-
await pg.query('delete from crm.notification where notification_id=$1', [resp.id]);
|
|
29
|
-
console.log(resp.id, 'deleted');
|
|
30
|
-
});
|
|
31
|
-
});
|
|
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
|
+
// import addNotification from '../../notification/funcs/addNotification.js';
|
|
8
|
+
|
|
9
|
+
// import pgClients from '../../pg/pgClients.js';
|
|
10
|
+
|
|
11
|
+
test('notification funcs', async (t) => {
|
|
12
|
+
// await build(t);
|
|
13
|
+
// const pg = pgClients.client;
|
|
14
|
+
// let resp;
|
|
15
|
+
/* await t.test('addNotification', async () => {
|
|
16
|
+
resp = await addNotification({
|
|
17
|
+
pg,
|
|
18
|
+
|
|
19
|
+
title: 'test title',
|
|
20
|
+
body: 'test body',
|
|
21
|
+
link: 'http://link',
|
|
22
|
+
notificationType: 'mention',
|
|
23
|
+
uid: config.testUser?.uid || '1',
|
|
24
|
+
});
|
|
25
|
+
assert.ok(resp.id);
|
|
26
|
+
});
|
|
27
|
+
await t.test('clean up after test, before pool is closed', async () => {
|
|
28
|
+
await pg.query('delete from crm.notification where notification_id=$1', [resp.id]);
|
|
29
|
+
console.log(resp.id, 'deleted');
|
|
30
|
+
}); */
|
|
31
|
+
});
|