mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 14:56:00 +00:00
chore(collection-manager): should not throw error when source collection destoryed (#1999)
This commit is contained in:
parent
83a6cae4e5
commit
83dc81c51b
@ -113,11 +113,6 @@ SELECT * FROM numbers;
|
|||||||
2,
|
2,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// cannot get field type in sqlite
|
|
||||||
// if (app.db.options.dialect === 'sqlite') {
|
|
||||||
// expect(data.fields.n.possibleTypes).toBeTruthy();
|
|
||||||
// }
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return possible types for json fields', async () => {
|
it('should return possible types for json fields', async () => {
|
||||||
@ -147,6 +142,83 @@ SELECT * FROM numbers;
|
|||||||
expect(data.fields.json_field.possibleTypes).toBeTruthy();
|
expect(data.fields.json_field.possibleTypes).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not throw error when source collection destroyed', async () => {
|
||||||
|
await app.db.getCollection('collections').repository.create({
|
||||||
|
values: {
|
||||||
|
name: 'users',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: 'name',
|
||||||
|
type: 'string',
|
||||||
|
interface: 'text',
|
||||||
|
uiSchema: 'name-uiSchema',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'age',
|
||||||
|
type: 'integer',
|
||||||
|
interface: 'number',
|
||||||
|
uiSchema: 'age-uiSchema',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
context: {},
|
||||||
|
});
|
||||||
|
|
||||||
|
await app.db.sync();
|
||||||
|
const UserCollection = app.db.getCollection('users');
|
||||||
|
|
||||||
|
const viewName = `t_${uid(6)}`;
|
||||||
|
const dropSQL = `DROP VIEW IF EXISTS ${viewName}`;
|
||||||
|
await app.db.sequelize.query(dropSQL);
|
||||||
|
const viewSQL = `CREATE VIEW ${viewName} AS SELECT * FROM ${UserCollection.quotedTableName()}`;
|
||||||
|
await app.db.sequelize.query(viewSQL);
|
||||||
|
|
||||||
|
// create view collection
|
||||||
|
const viewCollection = await app.db.getCollection('collections').repository.create({
|
||||||
|
values: {
|
||||||
|
name: viewName,
|
||||||
|
view: true,
|
||||||
|
schema: app.db.inDialect('postgres') ? 'public' : undefined,
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: 'name',
|
||||||
|
type: 'string',
|
||||||
|
source: 'users.name',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'age',
|
||||||
|
type: 'integer',
|
||||||
|
source: 'users.age',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
context: {},
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await agent.resource('collections').list({
|
||||||
|
appends: ['fields'],
|
||||||
|
paginate: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
// drop view first
|
||||||
|
await app.db.sequelize.query(dropSQL);
|
||||||
|
|
||||||
|
// remove source collection
|
||||||
|
await app.db.getCollection('collections').repository.destroy({
|
||||||
|
filterByTk: 'users',
|
||||||
|
context: {},
|
||||||
|
});
|
||||||
|
|
||||||
|
const response2 = await agent.resource('collections').list({
|
||||||
|
appends: ['fields'],
|
||||||
|
paginate: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(response2.statusCode).toBe(200);
|
||||||
|
});
|
||||||
|
|
||||||
it('should list collections fields with source interface', async () => {
|
it('should list collections fields with source interface', async () => {
|
||||||
await app.db.getCollection('collections').repository.create({
|
await app.db.getCollection('collections').repository.create({
|
||||||
values: {
|
values: {
|
||||||
|
@ -283,7 +283,7 @@ export class CollectionManagerPlugin extends Plugin {
|
|||||||
if (field.get('source')) {
|
if (field.get('source')) {
|
||||||
const [collectionSource, fieldSource] = field.get('source').split('.');
|
const [collectionSource, fieldSource] = field.get('source').split('.');
|
||||||
// find original field
|
// find original field
|
||||||
const collectionField = this.app.db.getCollection(collectionSource).getField(fieldSource);
|
const collectionField = this.app.db.getCollection(collectionSource)?.getField(fieldSource);
|
||||||
|
|
||||||
if (!collectionField) {
|
if (!collectionField) {
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user