* chore: test * chore: test * chore: test code * feat: on delete restrict * feat: on delete cascade * feat: on delete set null * feat: reference unbind * fix: test * fix: acl test * fix: test on Windows * fix: database recreate * fix: application reload * fix: multi-app-manager test * fix: test * feat: ondelete * fix: hasOne field onDelete Co-authored-by: chenos <chenlinxh@gmail.com>
51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
import Database, { Collection as DBCollection } from '@nocobase/database';
|
|
import Application from '@nocobase/server';
|
|
import { createApp } from '.';
|
|
|
|
describe('collections repository', () => {
|
|
let db: Database;
|
|
let app: Application;
|
|
let Collection: DBCollection;
|
|
let Field: DBCollection;
|
|
|
|
beforeEach(async () => {
|
|
app = await createApp();
|
|
db = app.db;
|
|
|
|
Collection = db.getCollection('collections');
|
|
Field = db.getCollection('fields');
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await app.destroy();
|
|
});
|
|
|
|
it('should remove association field after collection destroy', async () => {
|
|
await Collection.repository.create({
|
|
context: {},
|
|
values: {
|
|
name: 'posts',
|
|
fields: [{ type: 'hasMany', name: 'comments', target: 'comments' }],
|
|
},
|
|
});
|
|
|
|
await Collection.repository.create({
|
|
context: {},
|
|
values: {
|
|
name: 'comments',
|
|
fields: [{ type: 'string', name: 'content' }],
|
|
},
|
|
});
|
|
|
|
await db.getRepository('collections').destroy({
|
|
filter: {
|
|
name: 'comments',
|
|
},
|
|
});
|
|
|
|
const fields = await db.getRepository('fields').find();
|
|
|
|
expect(fields.length).toEqual(0);
|
|
});
|
|
});
|