mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 13:39:24 +08:00
* feat: create nocobase app with simple & quickstart option * chore: delete template file * create-nocobase-app: add env API_PORT fallback * chore: log * env default fallback * move config dir * change has yarn * chore: prettier * fix: npm running issue * database testing support sqlite * once... * chore: typo * fix: sqlite test * update readme * feat: copy .env.example to .env at create-nocobase-app * create-nocobase-app: change sqlite3 to github master * create-nocobase-app: .env template * create-nocobase-app: update .env * chore: typo * update README * chore: Application constructor * feat: sqlite demo data support * fix test * fix: application error * chore: plugin-client run sql * fix: application createCli * fix: can choose whether to register actions * chore: model compile error * fix: support sqlite * fix: demo data set index sequence on postgresql * chore: code reduce * fix: operators are compatible with sqlite * add impor demo option to init command * update env Co-authored-by: chenos <chenlinxh@gmail.com>
121 lines
2.8 KiB
TypeScript
121 lines
2.8 KiB
TypeScript
import supertest from 'supertest';
|
|
import { Application } from '../application';
|
|
import { Plugin } from '../plugin';
|
|
|
|
class MyPlugin extends Plugin {}
|
|
|
|
describe('application', () => {
|
|
let app: Application;
|
|
let agent;
|
|
|
|
beforeEach(() => {
|
|
app = new Application({
|
|
database: {
|
|
dialect: 'sqlite',
|
|
dialectModule: require('sqlite3'),
|
|
storage: ':memory:',
|
|
},
|
|
resourcer: {
|
|
prefix: '/api',
|
|
},
|
|
dataWrapping: false,
|
|
registerActions: false,
|
|
});
|
|
app.resourcer.registerActionHandlers({
|
|
list: async (ctx, next) => {
|
|
ctx.body = [1, 2];
|
|
await next();
|
|
},
|
|
get: async (ctx, next) => {
|
|
ctx.body = [3, 4];
|
|
await next();
|
|
},
|
|
'foo2s.bar2s:list': async (ctx, next) => {
|
|
ctx.body = [5, 6];
|
|
await next();
|
|
},
|
|
});
|
|
agent = supertest.agent(app.callback());
|
|
});
|
|
|
|
afterEach(async () => {
|
|
return app.db.close();
|
|
});
|
|
|
|
it('resourcer.define', async () => {
|
|
app.resourcer.define({
|
|
name: 'test',
|
|
});
|
|
const response = await agent.get('/api/test');
|
|
expect(response.body).toEqual([1, 2]);
|
|
});
|
|
|
|
it('resourcer.define', async () => {
|
|
app.resourcer.define({
|
|
type: 'hasMany',
|
|
name: 'test.abc',
|
|
});
|
|
const response = await agent.get('/api/test/1/abc');
|
|
expect(response.body).toEqual([1, 2]);
|
|
});
|
|
|
|
it('db.table', async () => {
|
|
app.db.table({
|
|
name: 'tests',
|
|
});
|
|
const response = await agent.get('/api/tests');
|
|
expect(response.body).toEqual([1, 2]);
|
|
});
|
|
|
|
it('db.association', async () => {
|
|
app.db.table({
|
|
name: 'bars',
|
|
});
|
|
app.db.table({
|
|
name: 'foos',
|
|
fields: [
|
|
{
|
|
type: 'hasMany',
|
|
name: 'bars',
|
|
},
|
|
],
|
|
});
|
|
const response = await agent.get('/api/foos/1/bars');
|
|
expect(response.body).toEqual([1, 2]);
|
|
});
|
|
|
|
it('db.middleware', async () => {
|
|
const index = app.middleware.findIndex((m) => m.name === 'table2resource');
|
|
app.middleware.splice(index, 0, async (ctx, next) => {
|
|
app.db.table({
|
|
name: 'tests',
|
|
});
|
|
await next();
|
|
});
|
|
const response = await agent.get('/api/tests');
|
|
expect(response.body).toEqual([1, 2]);
|
|
});
|
|
|
|
it('db.middleware', async () => {
|
|
const index = app.middleware.findIndex((m) => m.name === 'table2resource');
|
|
app.middleware.splice(index, 0, async (ctx, next) => {
|
|
app.db.table({
|
|
name: 'bars',
|
|
});
|
|
app.db.table({
|
|
name: 'foos',
|
|
fields: [
|
|
{
|
|
type: 'hasMany',
|
|
name: 'bars',
|
|
},
|
|
],
|
|
});
|
|
await next();
|
|
});
|
|
console.log(app.middleware);
|
|
const response = await agent.get('/api/foos/1/bars');
|
|
expect(response.body).toEqual([1, 2]);
|
|
});
|
|
});
|