mirror of
https://github.com/labring/laf.git
synced 2026-01-25 16:07:45 +00:00
chore(tests): update all tests name & cleaning
This commit is contained in:
parent
f57a7e71ef
commit
1ff1dfcfa1
@ -1,66 +0,0 @@
|
||||
const assert = require('assert')
|
||||
const client = require('../../dist/commonjs/index')
|
||||
|
||||
const config = {
|
||||
entryUrl: 'http://localhost:8088/entry',
|
||||
getAccessToken: () => '',
|
||||
}
|
||||
|
||||
let category_id = null
|
||||
|
||||
describe('Database sql', function () {
|
||||
it('add one should be ok', async () => {
|
||||
const cloud = client.init(config)
|
||||
|
||||
const result = await cloud.database()
|
||||
.collection('categories')
|
||||
.add({
|
||||
name: 'category-add'
|
||||
})
|
||||
|
||||
console.log({ result })
|
||||
category_id = result.id
|
||||
|
||||
const r = await cloud.database()
|
||||
.collection('categories')
|
||||
.where({id: result.id})
|
||||
.get()
|
||||
|
||||
const data = r.data
|
||||
assert.ok(result.id)
|
||||
assert.equal(data[0].id, result.id)
|
||||
})
|
||||
|
||||
it('add article should be ok', async () => {
|
||||
const cloud = client.init(config)
|
||||
|
||||
const result = await cloud.database()
|
||||
.collection('articles')
|
||||
.add({
|
||||
title: 'article-add',
|
||||
category_id: category_id,
|
||||
content: 'article-content'
|
||||
})
|
||||
|
||||
assert.ok(result.id)
|
||||
})
|
||||
|
||||
it('add many categories should be rejected', async () => {
|
||||
const cloud = client.init(config)
|
||||
|
||||
const res = await cloud.database()
|
||||
.collection('categories')
|
||||
.add([
|
||||
{
|
||||
name: 'category-add'
|
||||
},
|
||||
{
|
||||
name: 'category-add-2'
|
||||
}
|
||||
], { multi: true })
|
||||
|
||||
assert.ok(res.error?.length)
|
||||
assert.strictEqual(res.error[0].type, 'multi')
|
||||
assert.strictEqual(res.error[0].error, 'multi operation denied')
|
||||
})
|
||||
})
|
||||
@ -1,40 +0,0 @@
|
||||
const assert = require('assert')
|
||||
const client = require('../../dist/commonjs/index')
|
||||
|
||||
const config = {
|
||||
entryUrl: 'http://localhost:8088/entry',
|
||||
getAccessToken: () => '',
|
||||
}
|
||||
|
||||
describe('Database sql', function () {
|
||||
it('left join should be ok', async () => {
|
||||
const cloud = client.init(config)
|
||||
|
||||
// 此种写法没有指定 projection,返回的结果中子表的同名字段会覆盖主表
|
||||
const res = await cloud.database().collection('articles')
|
||||
.leftJoin('categories', 'id', 'category_id')
|
||||
.get()
|
||||
|
||||
assert.ok(res.data instanceof Array)
|
||||
assert.ok(res.data.length)
|
||||
assert.ok(res.data[0].id)
|
||||
})
|
||||
|
||||
|
||||
it('left join with projection passed', async () => {
|
||||
const cloud = client.init(config)
|
||||
const db = cloud.database()
|
||||
|
||||
const res = await db.collection('articles')
|
||||
.leftJoin('categories', 'id', 'category_id')
|
||||
.field(['articles.*','categories.name', 'categories.name cate_name'])
|
||||
.get()
|
||||
|
||||
assert.ok(res.data instanceof Array)
|
||||
assert.ok(res.data.length)
|
||||
assert.ok(res.data[0].id)
|
||||
assert.ok(res.data[0].name)
|
||||
assert.ok(res.data[0].cate_name)
|
||||
})
|
||||
})
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
const assert = require('assert')
|
||||
const client = require('../../dist/commonjs/index')
|
||||
|
||||
const config = {
|
||||
entryUrl: 'http://localhost:8088/entry',
|
||||
getAccessToken: () => '',
|
||||
}
|
||||
|
||||
describe('Database sql', function () {
|
||||
it('read all should be ok', async () => {
|
||||
const cloud = client.init(config)
|
||||
|
||||
const res = await cloud.database().collection('categories').get()
|
||||
assert.ok(res.data instanceof Array)
|
||||
assert.ok(res.data.length)
|
||||
assert.ok(res.data[0].id)
|
||||
})
|
||||
|
||||
|
||||
it('read with $like should be ok', async () => {
|
||||
const cloud = client.init(config)
|
||||
const db = cloud.database()
|
||||
const _ = db.command
|
||||
const res = await db.collection('categories')
|
||||
.where({ name: _.like('%category%')}).get()
|
||||
|
||||
assert.ok(res.data instanceof Array)
|
||||
assert.ok(res.data.length)
|
||||
assert.ok(res.data[0].id)
|
||||
})
|
||||
})
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
|
||||
## 运行本例
|
||||
|
||||
### 运行服务端
|
||||
|
||||
1. 启动 MySQL
|
||||
|
||||
```sh
|
||||
docker run --name mysqltest -e MYSQL_ROOT_PASSWORD=kissme -e MYSQL_DATABASE=testdb -d -p 3306:3306 mysql
|
||||
```
|
||||
|
||||
2. 创建表: 将 init.sql 文件在 mysql 中执行
|
||||
|
||||
3. 启动 less-api server
|
||||
|
||||
```sh
|
||||
node ./app.js
|
||||
```
|
||||
@ -1,75 +0,0 @@
|
||||
const express = require('express')
|
||||
const { Entry, MysqlAccessor } = require('less-api')
|
||||
const rules = require('./rules.json')
|
||||
|
||||
const app = new express()
|
||||
app.use(express.json())
|
||||
|
||||
|
||||
// request pre-process, include uid parse and cross-domain set
|
||||
app.all('*', function (_req, res, next) {
|
||||
// set cross domain
|
||||
res.header('Access-Control-Allow-Origin', '*')
|
||||
res.header('Access-Control-Allow-Headers', 'Authorization, Content-Type')
|
||||
res.header('Access-Control-Allow-Methods', '*')
|
||||
res.header('Content-Type', 'application/json;charset=utf-8')
|
||||
next()
|
||||
})
|
||||
|
||||
function parseToken(token) {
|
||||
return {
|
||||
role: 'admin',
|
||||
userId: 123
|
||||
}
|
||||
}
|
||||
|
||||
// init the less-api Entry & Db Accessor
|
||||
const accessor = new MysqlAccessor({
|
||||
database: 'testdb',
|
||||
user: 'root',
|
||||
password: 'kissme',
|
||||
host: 'localhost',
|
||||
port: 3306
|
||||
})
|
||||
|
||||
const entry = new Entry(accessor)
|
||||
entry.init()
|
||||
entry.loadRules(rules)
|
||||
|
||||
app.post('/entry', async (req, res) => {
|
||||
const { role, userId } = parseToken(req.headers['authorization'])
|
||||
|
||||
// parse params
|
||||
const params = entry.parseParams(req.body)
|
||||
console.log(req.body)
|
||||
console.log(params)
|
||||
const injections = {
|
||||
$role: role,
|
||||
$userid: userId
|
||||
}
|
||||
|
||||
// validate query
|
||||
const result = await entry.validate(params, injections)
|
||||
if (result.errors) {
|
||||
return res.send({
|
||||
code: 1,
|
||||
error: result.errors
|
||||
})
|
||||
}
|
||||
|
||||
// execute query
|
||||
try {
|
||||
const data = await entry.execute(params)
|
||||
return res.send({
|
||||
code: 0,
|
||||
data
|
||||
})
|
||||
} catch (error) {
|
||||
return res.send({
|
||||
code: 2,
|
||||
error: error.toString()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
app.listen(8088, () => console.log('listening on 8088'))
|
||||
@ -1,17 +0,0 @@
|
||||
create table IF NOT EXISTS categories (
|
||||
id int not null auto_increment,
|
||||
name varchar(64) not null,
|
||||
created_at int,
|
||||
primary key(id)
|
||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
create table IF NOT EXISTS articles (
|
||||
id int not null auto_increment,
|
||||
title varchar(64) not null,
|
||||
category_id int,
|
||||
content text,
|
||||
created_at int,
|
||||
updated_at int,
|
||||
created_by int,
|
||||
primary key(id)
|
||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
@ -1,23 +0,0 @@
|
||||
{
|
||||
"categories": {
|
||||
".read": true,
|
||||
".update": {
|
||||
"condition": true,
|
||||
"multi": true
|
||||
},
|
||||
".add": true,
|
||||
".remove": true,
|
||||
".count": true
|
||||
},
|
||||
"articles": {
|
||||
".read": {
|
||||
"condition": true,
|
||||
"join": [
|
||||
"categories"
|
||||
]
|
||||
},
|
||||
".update": true,
|
||||
".add": true,
|
||||
".remove": true
|
||||
}
|
||||
}
|
||||
@ -1,76 +0,0 @@
|
||||
/* eslint-disable indent */
|
||||
const assert = require('assert')
|
||||
const client = require('../../dist/commonjs/index')
|
||||
|
||||
const cloud = client.init({
|
||||
entryUrl: 'http://localhost:8088/entry',
|
||||
getAccessToken: () => '',
|
||||
primaryKey: 'id'
|
||||
})
|
||||
|
||||
describe('Database sql', function () {
|
||||
|
||||
let result = null
|
||||
before(async () => {
|
||||
result = await cloud.database()
|
||||
.collection('categories')
|
||||
.add({
|
||||
name: 'category-add'
|
||||
})
|
||||
|
||||
assert.ok(result.id)
|
||||
})
|
||||
|
||||
it('update one should be ok', async () => {
|
||||
const db = cloud.database()
|
||||
|
||||
const updated = await db
|
||||
.collection('categories')
|
||||
.doc(result.id)
|
||||
.update({
|
||||
name: 'updated-title'
|
||||
})
|
||||
|
||||
assert.ok(updated.ok)
|
||||
const { data } = await cloud.database()
|
||||
.collection('categories')
|
||||
.doc(result.id)
|
||||
.get()
|
||||
|
||||
assert.equal(data[0].id, result.id)
|
||||
assert.equal(data[0].name, 'updated-title')
|
||||
})
|
||||
|
||||
it('update many should be ok', async () => {
|
||||
const db = cloud.database()
|
||||
|
||||
const updated = await db.collection('categories')
|
||||
.where({})
|
||||
.update({
|
||||
name: 'content-update-many'
|
||||
}, { multi: true})
|
||||
|
||||
assert.ok(updated.ok)
|
||||
const res = await cloud.database()
|
||||
.collection('categories')
|
||||
.get()
|
||||
|
||||
res?.data?.forEach( d => {
|
||||
assert.strictEqual(d.name, 'content-update-many')
|
||||
})
|
||||
})
|
||||
|
||||
it('set one shouWld be rejected since merge = true forbidden in sql', async () => {
|
||||
const db = cloud.database()
|
||||
|
||||
const res = await db.collection('categories')
|
||||
.doc(result.id)
|
||||
.set({
|
||||
setField: 'content-set-1'
|
||||
})
|
||||
|
||||
assert.ok(res.code > 0)
|
||||
assert.ok(res.error)
|
||||
assert.ok(res.error, 'AssertionError [ERR_ASSERTION]: invalid params: {merge} should be true in sql')
|
||||
})
|
||||
})
|
||||
@ -1,18 +1,10 @@
|
||||
const assert = require('assert')
|
||||
const client = require('../../dist/commonjs/index')
|
||||
const config = require('./config')
|
||||
|
||||
function getAccessToken(){
|
||||
return 'test-token-xxx'
|
||||
}
|
||||
|
||||
const config = {
|
||||
entryUrl: 'http://localhost:8080/entry',
|
||||
getAccessToken,
|
||||
}
|
||||
|
||||
describe('Database', function () {
|
||||
describe('client-sdk(http): db.add()', function () {
|
||||
it('add one should be ok', async () => {
|
||||
const cloud = client.init(config)
|
||||
const cloud = client.init({ dbProxyUrl: config.dbProxyUrl, getAccessToken: config.getAccessToken})
|
||||
|
||||
const result = await cloud.database()
|
||||
.collection('categories')
|
||||
@ -28,6 +20,6 @@ describe('Database', function () {
|
||||
.get()
|
||||
|
||||
assert.ok(result.id)
|
||||
assert.equal(data[0]._id, result.id)
|
||||
assert.equal(data._id, result.id)
|
||||
})
|
||||
})
|
||||
8
packages/client-sdk/tests/http/config.js
Normal file
8
packages/client-sdk/tests/http/config.js
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
|
||||
const config = {
|
||||
dbProxyUrl: 'http://d9f5f2aa-c7a4-47da-ab43-5f01d6724d36.local-dev.host:8080/proxy/app',
|
||||
getAccessToken: () => '',
|
||||
}
|
||||
|
||||
module.exports = config
|
||||
@ -1,19 +1,10 @@
|
||||
const assert = require('assert')
|
||||
const client = require('../../dist/commonjs/index')
|
||||
const config = require('./config')
|
||||
|
||||
function getAccessToken(){
|
||||
return 'test-token-xxx'
|
||||
}
|
||||
|
||||
const config = {
|
||||
baseUrl: 'http://localhost:8080',
|
||||
entryUrl: '/entry',
|
||||
getAccessToken,
|
||||
}
|
||||
|
||||
describe('Database', function () {
|
||||
describe('client-sdk(http): db.get()', function () {
|
||||
it('read empty should be ok', async () => {
|
||||
const cloud = client.init(config)
|
||||
const cloud = client.init({ dbProxyUrl: config.dbProxyUrl, getAccessToken: config.getAccessToken})
|
||||
|
||||
const res = await cloud.database().collection('categories').get()
|
||||
|
||||
|
||||
@ -1,18 +1,9 @@
|
||||
/* eslint-disable indent */
|
||||
const assert = require('assert')
|
||||
const client = require('../../dist/commonjs/index')
|
||||
|
||||
function getAccessToken(){
|
||||
return 'test-token-xxx'
|
||||
}
|
||||
|
||||
const config = {
|
||||
entryUrl: 'http://localhost:8080/entry',
|
||||
getAccessToken
|
||||
}
|
||||
|
||||
describe('Database', function () {
|
||||
const cloud = client.init(config)
|
||||
const config = require('./config')
|
||||
describe('client-sdk(http): db::update()', function () {
|
||||
const cloud = client.init({ dbProxyUrl: config.dbProxyUrl, getAccessToken: config.getAccessToken})
|
||||
|
||||
let result = null
|
||||
before(async () => {
|
||||
@ -41,8 +32,9 @@ describe('Database', function () {
|
||||
.doc(result.id)
|
||||
.get()
|
||||
|
||||
assert.equal(data[0]._id, result.id)
|
||||
assert.equal(data[0].title, 'updated-title')
|
||||
console.log(data)
|
||||
assert.equal(data._id, result.id)
|
||||
assert.equal(data.title, 'updated-title')
|
||||
})
|
||||
|
||||
it('update with $operator should be ok', async () => {
|
||||
@ -63,10 +55,10 @@ describe('Database', function () {
|
||||
.get()
|
||||
|
||||
|
||||
assert.equal(data[0]._id, result.id)
|
||||
assert.equal(data[0].title, 'updated-title')
|
||||
assert.equal(data[0].age, 1)
|
||||
assert.equal(data[0].content, undefined)
|
||||
assert.equal(data._id, result.id)
|
||||
assert.equal(data.title, 'updated-title')
|
||||
assert.equal(data.age, 1)
|
||||
assert.equal(data.content, undefined)
|
||||
})
|
||||
|
||||
it('update many should be ok', async () => {
|
||||
@ -89,7 +81,7 @@ describe('Database', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('set one shouWld be ok', async () => {
|
||||
it('set one should be ok', async () => {
|
||||
const db = cloud.database()
|
||||
const _ = db.command
|
||||
|
||||
@ -104,7 +96,7 @@ describe('Database', function () {
|
||||
.doc(result.id)
|
||||
.get()
|
||||
|
||||
assert.equal(data[0]._id, result.id)
|
||||
assert.equal(data[0].setField, 'content-set-1')
|
||||
assert.equal(data._id, result.id)
|
||||
assert.equal(data.setField, 'content-set-1')
|
||||
})
|
||||
})
|
||||
@ -1,37 +0,0 @@
|
||||
const assert = require('assert')
|
||||
const { Cloud } = require('../../dist/commonjs/index')
|
||||
const { Request } = require('../../dist/commonjs/request')
|
||||
|
||||
|
||||
class CustomRequest extends Request {
|
||||
|
||||
// 允许自定义 Request, 例如客户端加密请求的场景
|
||||
async request(data) {
|
||||
const str = JSON.stringify(data)
|
||||
const encrypt = Buffer.from(str).toString('base64')
|
||||
|
||||
return {
|
||||
data: {
|
||||
code: 1,
|
||||
error: encrypt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
describe('Cloud request', function () {
|
||||
const config = {
|
||||
entryUrl: 'http://localhost:8080/admin/entry',
|
||||
getAccessToken: () => '',
|
||||
requestClass: function (config) { return new CustomRequest(config) }
|
||||
}
|
||||
|
||||
it('database() should be ok', async () => {
|
||||
const cloud = new Cloud(config)
|
||||
const db = cloud.database()
|
||||
|
||||
const r = await db.collection('test').get()
|
||||
assert.ok(r.code)
|
||||
assert.ok(r.error)
|
||||
})
|
||||
})
|
||||
@ -7,9 +7,9 @@ function getAccessToken(){
|
||||
return 'test-token-xxx'
|
||||
}
|
||||
|
||||
describe('Cloud', function () {
|
||||
describe('client-sdk(unit): Cloud', function () {
|
||||
const config = {
|
||||
entryUrl: 'http://localhost:8080/entry',
|
||||
dbProxyUrl: 'http://localhost:8080/entry',
|
||||
getAccessToken
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ describe('Cloud', function () {
|
||||
const cloud = client.init(config)
|
||||
|
||||
assert.ok(cloud instanceof client.Cloud)
|
||||
assert.equal(cloud.config.entryUrl, config.entryUrl)
|
||||
assert.equal(cloud.config.dbProxyUrl, config.dbProxyUrl)
|
||||
assert.equal(cloud.config.getAccessToken, getAccessToken)
|
||||
})
|
||||
|
||||
@ -26,9 +26,5 @@ describe('Cloud', function () {
|
||||
const db = cloud.database()
|
||||
|
||||
assert.ok(db instanceof Db)
|
||||
assert.equal(db.config.entryUrl, config.entryUrl)
|
||||
assert.equal(db.config.getAccessToken, config.getAccessToken)
|
||||
|
||||
assert.equal(Db.getAccessToken, getAccessToken)
|
||||
})
|
||||
})
|
||||
@ -9,7 +9,7 @@ async function restoreTestData (coll) {
|
||||
await coll.deleteMany({})
|
||||
}
|
||||
|
||||
describe('Database add', function () {
|
||||
describe('db-proxy(mongo): db.add()', function () {
|
||||
this.timeout(10000)
|
||||
|
||||
const accessor = new MongoAccessor(dbconfig.dbName, dbconfig.url, dbconfig.connSettings)
|
||||
|
||||
@ -10,7 +10,7 @@ const TEST_DATA = [
|
||||
{ title: 'title-3', content: 'content-3', state: 3, gender: 1 }
|
||||
]
|
||||
|
||||
describe('Database aggregate', function () {
|
||||
describe('db-proxy(mongo): db.aggregate()', function () {
|
||||
this.timeout(10000)
|
||||
|
||||
const accessor = new MongoAccessor(dbconfig.dbName, dbconfig.url, dbconfig.connSettings)
|
||||
|
||||
@ -8,7 +8,7 @@ const TEST_DATA = [
|
||||
{ type: 'b', title: 'title-3', content: 'content-3' }
|
||||
]
|
||||
|
||||
describe('Database count', function () {
|
||||
describe('db-proxy(mongo): db.count()', function () {
|
||||
this.timeout(10000)
|
||||
|
||||
const accessor = new MongoAccessor(dbconfig.dbName, dbconfig.url, dbconfig.connSettings)
|
||||
|
||||
@ -9,7 +9,7 @@ const TEST_DATA = [
|
||||
{ title: 'title-3', content: 'content-3' }
|
||||
]
|
||||
|
||||
describe('Database read', function () {
|
||||
describe('db-proxy(mongo): DBI', function () {
|
||||
this.timeout(10000)
|
||||
|
||||
const accessor = new MongoAccessor(dbconfig.dbName, dbconfig.url, dbconfig.connSettings)
|
||||
|
||||
@ -9,7 +9,7 @@ const TEST_DATA = [
|
||||
{ title: 'title-3', content: 'content-3' }
|
||||
]
|
||||
|
||||
describe('Database read', function () {
|
||||
describe('db-proxy(mongo): db.get()', function () {
|
||||
this.timeout(10000)
|
||||
|
||||
const accessor = new MongoAccessor(dbconfig.dbName, dbconfig.url, dbconfig.connSettings)
|
||||
|
||||
@ -15,7 +15,7 @@ async function restoreTestData (coll) {
|
||||
assert.equal(r.insertedCount, TEST_DATA.length)
|
||||
}
|
||||
|
||||
describe('Database remove', function () {
|
||||
describe('db-proxy(mongo): db.remove()', function () {
|
||||
this.timeout(10000)
|
||||
|
||||
const accessor = new MongoAccessor(dbconfig.dbName, dbconfig.url, dbconfig.connSettings)
|
||||
|
||||
@ -16,7 +16,7 @@ async function restoreTestData (coll) {
|
||||
assert.equal(r.insertedCount, TEST_DATA.length)
|
||||
}
|
||||
|
||||
describe('Database update', function () {
|
||||
describe('db-proxy(mongo): db.update()', function () {
|
||||
this.timeout(10000)
|
||||
|
||||
const accessor = new MongoAccessor(dbconfig.dbName, dbconfig.url, dbconfig.connSettings)
|
||||
|
||||
@ -19,7 +19,6 @@ describe('Database Mysql count', function () {
|
||||
let entry = new Proxy(accessor)
|
||||
|
||||
before(async () => {
|
||||
await entry.init()
|
||||
await accessor.conn.execute(`create table IF NOT EXISTS ${table} (id int(11) NOT NULL AUTO_INCREMENT, name varchar(255) NOT NULL, age int, primary key(id))`)
|
||||
await accessor.conn.execute(`insert into ${table} (id,name, age) values(111, 'less-api-1', 2)`)
|
||||
await accessor.conn.execute(`insert into ${table} (id,name, age) values(112, 'less-api-2', 18)`)
|
||||
@ -3,7 +3,7 @@ const { MongoAccessor } = require('../../dist')
|
||||
|
||||
const MongoClient = require('mongodb').MongoClient
|
||||
|
||||
describe('class Accessor', () => {
|
||||
describe('db-proxy(unit): class Accessor', () => {
|
||||
it('constructor() ok', () => {
|
||||
const acc = new MongoAccessor('test-db', 'mongodb://localhost:27017')
|
||||
assert.equal(acc.db_name, 'test-db')
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const assert = require('assert')
|
||||
const { Policy } = require('../../../../dist/policy')
|
||||
|
||||
describe('Data validator - condition', () => {
|
||||
describe('db-proxy(unit): validator::data - condition', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"add": {
|
||||
|
||||
@ -3,7 +3,7 @@ const { Policy } = require('../../../../dist/policy')
|
||||
|
||||
|
||||
|
||||
describe('Data Validator - default', () => {
|
||||
describe('db-proxy(unit): validator::data - default', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"add": {
|
||||
|
||||
@ -2,7 +2,7 @@ const assert = require('assert')
|
||||
const { Policy } = require('../../../../dist/policy')
|
||||
|
||||
|
||||
describe('Data Validator - in', () => {
|
||||
describe('db-proxy(unit): validator::data - in', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"add": {
|
||||
|
||||
@ -2,7 +2,7 @@ const assert = require('assert')
|
||||
const { Policy } = require('../../../../dist/policy')
|
||||
|
||||
|
||||
describe('Data Validator - length', () => {
|
||||
describe('db-proxy(unit): validator::data - length', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"add": {
|
||||
|
||||
@ -3,7 +3,7 @@ const { Policy } = require('../../../../dist/policy')
|
||||
|
||||
|
||||
|
||||
describe('Data Validator - match', () => {
|
||||
describe('db-proxy(unit): validator::data - match', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"add": {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const assert = require('assert')
|
||||
const { Policy } = require('../../../../dist/policy')
|
||||
|
||||
describe('Data Validator - number', () => {
|
||||
describe('db-proxy(unit): validator::data - number', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"add": {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const assert = require('assert')
|
||||
const { Policy } = require('../../../../dist/policy')
|
||||
|
||||
describe('Data Validator - required', () => {
|
||||
describe('db-proxy(unit): validator::data - required', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"add": {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const assert = require('assert')
|
||||
const { Policy } = require('../../../../dist/policy')
|
||||
|
||||
describe('Date Validator - add', () => {
|
||||
describe('db-proxy(unit): validator::data - add', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"add": {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const assert = require('assert')
|
||||
const { Policy } = require('../../../../dist')
|
||||
|
||||
describe('Date Validator - merge options (replace & update)', () => {
|
||||
describe('db-proxy(unit): validator::data - merge options (replace & update)', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"update": {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const assert = require('assert')
|
||||
const { Policy } = require('../../../../dist')
|
||||
|
||||
describe('Data Validator - default', () => {
|
||||
describe('db-proxy(unit): validator::data - default(update)', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"update": {
|
||||
|
||||
@ -2,7 +2,7 @@ const assert = require('assert')
|
||||
const { Policy } = require('../../../../dist')
|
||||
|
||||
|
||||
describe('Data Validator - required', () => {
|
||||
describe('db-proxy(unit): validator::data - required', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"update": {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const assert = require('assert')
|
||||
const { Policy } = require('../../../../dist/policy')
|
||||
|
||||
describe('Query validator - condition', () => {
|
||||
describe('db-proxy(unit): validator::query - condition', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"update": {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const assert = require('assert')
|
||||
const { Policy } = require('../../../../dist/policy')
|
||||
|
||||
describe('Query Validator - default', () => {
|
||||
describe('db-proxy(unit): validator::query - default', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"update": {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const assert = require('assert')
|
||||
const { Policy } = require('../../../../dist/policy')
|
||||
|
||||
describe('Query Validator - in', () => {
|
||||
describe('db-proxy(unit): validator::query - in', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"update": {
|
||||
|
||||
@ -2,7 +2,7 @@ const assert = require('assert')
|
||||
const { Policy } = require('../../../../dist/policy')
|
||||
|
||||
|
||||
describe('Query Validator - length', () => {
|
||||
describe('db-proxy(unit): validator::query- length', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"update": {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const assert = require('assert')
|
||||
const { Policy } = require('../../../../dist/policy')
|
||||
|
||||
describe('Query Validator - match', () => {
|
||||
describe('db-proxy(unit): validator::query - match', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"update": {
|
||||
|
||||
@ -2,7 +2,7 @@ const assert = require('assert')
|
||||
const { Policy } = require('../../../../dist/policy')
|
||||
|
||||
|
||||
describe('Query Validator - number', () => {
|
||||
describe('db-proxy(unit): validator::query - number', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"update": {
|
||||
|
||||
@ -2,7 +2,7 @@ const assert = require('assert')
|
||||
const { Policy } = require('../../../../dist/policy')
|
||||
|
||||
|
||||
describe('Query Validator - required', () => {
|
||||
describe('db-proxy(unit): validator::query - required', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"update": {
|
||||
|
||||
@ -4,7 +4,7 @@ const { Policy } = require('../../../dist/policy')
|
||||
|
||||
const buildins = require('../../../dist/validators')
|
||||
|
||||
describe('class Policy', () => {
|
||||
describe('db-proxy(unit): class Policy', () => {
|
||||
|
||||
it('loadBuiltins() ok', () => {
|
||||
// 初始化 validator 是否正确
|
||||
@ -69,7 +69,7 @@ describe('class Policy', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('class Policy validate() - condition', () => {
|
||||
describe('db-proxy(unit): class Policy validate() - condition', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"read": true,
|
||||
@ -190,7 +190,7 @@ describe('class Policy validate() - condition', () => {
|
||||
})
|
||||
|
||||
|
||||
describe('class Policy validate() - multiple rules', () => {
|
||||
describe('db-proxy(unit): class Policy validate() - multiple rules', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"read": [
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const assert = require('assert')
|
||||
const { Policy } = require('../../../dist')
|
||||
|
||||
describe('Join Validator - [no join configured]', () => {
|
||||
describe('db-proxy(unit): validator::join - [no join configured]', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"read": true,
|
||||
@ -46,7 +46,7 @@ describe('Join Validator - [no join configured]', () => {
|
||||
})
|
||||
|
||||
|
||||
describe('Join Validator - [join configured]', () => {
|
||||
describe('db-proxy(unit): validator::join - [join configured]', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"read": {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const assert = require('assert')
|
||||
const { Policy } = require('../../../dist')
|
||||
|
||||
describe('Multi Validator - [multi config as true]', () => {
|
||||
describe('db-proxy(unit): validator::multi - [multi config as true]', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"read": {},
|
||||
@ -60,7 +60,7 @@ describe('Multi Validator - [multi config as true]', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Multi Validator - [multi config as false]', () => {
|
||||
describe('db-proxy(unit): validator::multi - [multi config as false]', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"read": {
|
||||
@ -172,8 +172,7 @@ describe('Multi Validator - [multi config as false]', () => {
|
||||
})
|
||||
|
||||
|
||||
|
||||
describe('Multi Validator - [multi config as expression]', () => {
|
||||
describe('db-proxy(unit): validator::multi - [multi config as expression]', () => {
|
||||
const rules = {
|
||||
categories: {
|
||||
"remove": {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const assert = require('assert')
|
||||
const { Proxy, MongoAccessor } = require('../../dist')
|
||||
|
||||
describe('class Proxy', () => {
|
||||
describe('db-proxy(unit): class Proxy', () => {
|
||||
const accessor = new MongoAccessor('test-db', 'mongodb://localhost:27017')
|
||||
|
||||
it('constructor() ok', () => {
|
||||
|
||||
@ -4,7 +4,7 @@ const { SqlBuilder } = require('../../dist/accessor/sql_builder')
|
||||
const { ActionType } = require('../../dist/types')
|
||||
const { strictCompareArray } = require('../utils')
|
||||
|
||||
describe('class SqlBuilder', () => {
|
||||
describe('db-proxy(unit): class SqlBuilder', () => {
|
||||
it('constructor() passed', () => {
|
||||
const params = {
|
||||
collection: 'test_table',
|
||||
|
||||
@ -6,7 +6,7 @@ const { strictCompareArray } = require('../utils')
|
||||
/**
|
||||
* 不同的查询情况(case N),参考 docs/convert-sql.md 文档。
|
||||
*/
|
||||
describe('class SqlQueryBuilder', () => {
|
||||
describe('db-proxy(unit): class SqlQueryBuilder', () => {
|
||||
it('Query CASE 1: query = {} shoud be ok', () => {
|
||||
const query = {}
|
||||
const builder = new SqlQueryBuilder(query)
|
||||
|
||||
@ -3,7 +3,7 @@ const { Actions, getDb } = require('../_utils')
|
||||
const assert = require('assert')
|
||||
const { ObjectId } = require('bson')
|
||||
|
||||
describe('db::aggregate()', () => {
|
||||
describe('db-ql(unit): db::aggregate()', () => {
|
||||
it('aggregate() with raw pipeline should be ok', async () => {
|
||||
const { db, req } = getDb()
|
||||
const res = await db.collection('tasks')
|
||||
|
||||
@ -3,7 +3,7 @@ const { Actions, getDb } = require('../_utils')
|
||||
const assert = require('assert')
|
||||
const { ObjectId } = require('bson')
|
||||
|
||||
describe('db::aggregate()::$lookup', () => {
|
||||
describe('db-ql(unit): db::aggregate()::$lookup', () => {
|
||||
it('lookup() should be ok', async () => {
|
||||
const { db, req } = getDb()
|
||||
const res = await db.collection('tasks')
|
||||
|
||||
@ -3,7 +3,7 @@ const { Actions, getDb } = require('../_utils')
|
||||
const assert = require('assert')
|
||||
const { ObjectId, Binary } = require('bson')
|
||||
|
||||
describe('db::aggregate()::$match', () => {
|
||||
describe('db-ql(unit): db::aggregate()::$match', () => {
|
||||
it('match() should be ok', async () => {
|
||||
const { db, req } = getDb()
|
||||
const res = await db.collection('tasks')
|
||||
|
||||
@ -3,7 +3,7 @@ const { Actions, getDb } = require('../_utils')
|
||||
const assert = require('assert')
|
||||
const { ObjectId, Binary } = require('bson')
|
||||
|
||||
describe('db::doc().create()', () => {
|
||||
describe('db-ql(unit): db::doc().create()', () => {
|
||||
it('create() should be ok', async () => {
|
||||
const { db, req } = getDb()
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ const { Actions, getDb } = require('../_utils')
|
||||
const assert = require('assert')
|
||||
const { ObjectId } = require('bson')
|
||||
|
||||
describe('db::doc().get()', () => {
|
||||
describe('db-ql(unit): db::doc().get()', () => {
|
||||
it('get() with string id should be ok', async () => {
|
||||
const { db, req } = getDb()
|
||||
const res = await db.collection('tasks')
|
||||
|
||||
@ -3,7 +3,7 @@ const { Actions, getDb } = require('../_utils')
|
||||
const assert = require('assert')
|
||||
const { ObjectId, Binary } = require('bson')
|
||||
|
||||
describe('db::doc().update()', () => {
|
||||
describe('db-ql(unit): db::doc().update()', () => {
|
||||
it('update() should be ok', async () => {
|
||||
const { db, req } = getDb()
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const { getDb } = require('../_utils')
|
||||
const assert = require('assert')
|
||||
|
||||
describe('db::field()', () => {
|
||||
describe('db-ql(unit): db::field()', () => {
|
||||
it('field(value: string[]) should be ok', async () => {
|
||||
const { db, req } = getDb()
|
||||
const res = await db.collection('tasks')
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
const { Actions, getDb } = require('../_utils')
|
||||
const assert = require('assert')
|
||||
|
||||
describe('db::get()', () => {
|
||||
describe('db-ql(unit): db::get()', () => {
|
||||
it('get() without query options should be ok', async () => {
|
||||
const { db, req } = getDb()
|
||||
const res = await db.collection('tasks')
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const { getDb } = require('../_utils')
|
||||
const assert = require('assert')
|
||||
|
||||
describe('db::limit() & skip()', () => {
|
||||
describe('db-ql(unit): db::limit() & skip()', () => {
|
||||
it('get() default limit is 100 should be ok', async () => {
|
||||
const { db, req } = getDb()
|
||||
const res = await db.collection('tasks')
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const { getDb } = require('../_utils')
|
||||
const assert = require('assert')
|
||||
|
||||
describe('db::orderBy()', () => {
|
||||
describe('db-ql(unit): db::orderBy()', () => {
|
||||
it('orderBy() should be ok', async () => {
|
||||
const { db, req } = getDb()
|
||||
const res = await db.collection('tasks')
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const { getDb } = require('../_utils')
|
||||
const assert = require('assert')
|
||||
|
||||
describe('db::page()', () => {
|
||||
describe('db-ql(unit): db::page()', () => {
|
||||
it('page() should be ok', async () => {
|
||||
const { db, req } = getDb()
|
||||
const res = await db.collection('tasks')
|
||||
|
||||
@ -5,7 +5,7 @@ const { ObjectId } = require('bson')
|
||||
const { getDb } = require('../_utils')
|
||||
|
||||
|
||||
describe('db::where()', () => {
|
||||
describe('db-ql(unit): db::where()', () => {
|
||||
it('where({}) should be ok', async () => {
|
||||
const { db, req } = getDb()
|
||||
const res = await db.collection('tasks')
|
||||
|
||||
@ -3,7 +3,7 @@ const { Actions, getDb } = require('../_utils')
|
||||
const assert = require('assert')
|
||||
const { ObjectId, Binary } = require('bson')
|
||||
|
||||
describe('db::update()', () => {
|
||||
describe('db-ql(unit): db::update()', () => {
|
||||
it('update() should be ok', async () => {
|
||||
const { db, req } = getDb()
|
||||
|
||||
|
||||
@ -3,9 +3,9 @@ const assert = require('assert')
|
||||
const path = require('path')
|
||||
const { PackageDeclaration } = require('../dist')
|
||||
|
||||
const nmp = path.resolve(__dirname, '../../less-api-framework/node_modules')
|
||||
const nmp = path.resolve(__dirname, '../../app-service/node_modules')
|
||||
|
||||
describe('Package Declaration Load', () => {
|
||||
describe('npm-util(unit): Package Declaration Load', () => {
|
||||
|
||||
/**
|
||||
* load from self package: @
|
||||
|
||||
@ -3,9 +3,9 @@ const assert = require('assert')
|
||||
const path = require('path')
|
||||
const { PackageDeclaration } = require('../dist')
|
||||
|
||||
const nmp = path.resolve(__dirname, '../../less-api-framework/node_modules')
|
||||
const nmp = path.resolve(__dirname, '../../app-service/node_modules')
|
||||
|
||||
describe('Package Declaration Load', () => {
|
||||
describe('npm-util(unit): Package Declaration Load', () => {
|
||||
/**
|
||||
* load from @types/express
|
||||
*/
|
||||
@ -39,12 +39,12 @@ describe('Package Declaration Load', () => {
|
||||
/**
|
||||
* load from self package: less-api-database
|
||||
*/
|
||||
it('load d.ts of less-api-database (typings)', async () => {
|
||||
const pkg = new PackageDeclaration('less-api-database', nmp)
|
||||
it('load d.ts of database-proxy (typings)', async () => {
|
||||
const pkg = new PackageDeclaration('database-proxy', nmp)
|
||||
await pkg.load()
|
||||
console.log(pkg.declarations)
|
||||
|
||||
assert.strictEqual(pkg.name, 'less-api-database')
|
||||
assert.strictEqual(pkg.name, 'database-proxy')
|
||||
assert.ok(pkg.declarations.length > 0)
|
||||
})
|
||||
})
|
||||
@ -3,12 +3,12 @@ const assert = require('assert')
|
||||
const path = require('path')
|
||||
const { ImportParser, PackageDeclaration } = require('../dist')
|
||||
|
||||
const nmp = path.resolve(__dirname, '../../less-api-framework/node_modules')
|
||||
const nmp = path.resolve(__dirname, '../../app-service/node_modules')
|
||||
|
||||
describe('Import Parser', () => {
|
||||
describe('npm-util(unit): Import Parser', () => {
|
||||
|
||||
it('parse less-api-database index.d.ts', async () => {
|
||||
const pkg = new PackageDeclaration('less-api-database', nmp)
|
||||
it('parse database-proxy index.d.ts', async () => {
|
||||
const pkg = new PackageDeclaration('database-proxy', nmp)
|
||||
await pkg.load()
|
||||
const dec0 = pkg.declarations[0]
|
||||
console.log(dec0.packageName, dec0.path)
|
||||
@ -18,7 +18,7 @@ describe('Import Parser', () => {
|
||||
|
||||
console.log(r)
|
||||
assert.ok(r.length > 0)
|
||||
assert.strictEqual(pkg.name, 'less-api-database')
|
||||
assert.strictEqual(pkg.name, 'database-proxy')
|
||||
assert.ok(pkg.declarations.length > 0)
|
||||
})
|
||||
})
|
||||
@ -2,35 +2,36 @@
|
||||
const assert = require('assert')
|
||||
const { PackageInfo} = require('../dist')
|
||||
const path = require('path')
|
||||
const nmp = path.resolve(__dirname, '../../less-api-framework/node_modules')
|
||||
const nmp = path.resolve(__dirname, '../../app-service/node_modules')
|
||||
|
||||
|
||||
describe('Package parse', () => {
|
||||
it('get pkg dir: less-api-database', async () => {
|
||||
const pkg = new PackageInfo('less-api-database', nmp)
|
||||
describe('npm-util(unit): Package parse', () => {
|
||||
it('get pkg dir: database-ql', async () => {
|
||||
const pkg = new PackageInfo('database-ql', nmp)
|
||||
await pkg.parse()
|
||||
assert.strictEqual(pkg.name, 'less-api-database')
|
||||
assert.strictEqual(pkg.name, 'database-ql')
|
||||
console.log(pkg.entryPath)
|
||||
assert(pkg.entryPath?.endsWith('dist/commonjs'))
|
||||
})
|
||||
|
||||
it('get pkg dir: less-api-database/index', async () => {
|
||||
const pkg = new PackageInfo('less-api-database/index', nmp)
|
||||
it('get pkg dir: database-ql/index', async () => {
|
||||
const pkg = new PackageInfo('database-ql/index', nmp)
|
||||
await pkg.parse()
|
||||
assert.strictEqual(pkg.name, 'less-api-database')
|
||||
assert.strictEqual(pkg.name, 'database-ql')
|
||||
assert(pkg.entryPath?.endsWith('dist/commonjs'))
|
||||
})
|
||||
|
||||
it('get pkg dir: less-api-database/dist/commonjs', async () => {
|
||||
const pkg = new PackageInfo('less-api-database/dist/commonjs', nmp)
|
||||
it('get pkg dir: database-ql/dist/commonjs', async () => {
|
||||
const pkg = new PackageInfo('database-ql/dist/commonjs', nmp)
|
||||
await pkg.parse()
|
||||
assert.strictEqual(pkg.name, 'less-api-database')
|
||||
assert.strictEqual(pkg.name, 'database-ql')
|
||||
assert(pkg.entryPath?.endsWith('dist/commonjs'))
|
||||
})
|
||||
|
||||
it('get pkg dir: less-api-database/dist/commonjs/commands/index', async () => {
|
||||
const pkg = new PackageInfo('less-api-database/dist/commonjs/commands/index', nmp)
|
||||
it('get pkg dir: database-ql/dist/commonjs/commands/index', async () => {
|
||||
const pkg = new PackageInfo('database-ql/dist/commonjs/commands/index', nmp)
|
||||
await pkg.parse()
|
||||
assert.strictEqual(pkg.name, 'less-api-database')
|
||||
assert.strictEqual(pkg.name, 'database-ql')
|
||||
assert(pkg.entryPath?.endsWith('dist/commonjs'))
|
||||
})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user