Fix/snapshot (#1396)

* feat: snapshot field check add collectionName

* feat: snapshot add test

* fix: filterByTk

* Update ResourceActionProvider.tsx

---------

Co-authored-by: chenos <chenlinxh@gmail.com>
This commit is contained in:
anuoua 2023-01-29 01:32:18 +08:00 committed by GitHub
parent 0d30366aba
commit 22339d9ef7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,63 @@
import { mockServer, MockServer } from '@nocobase/test';
import SnapshotFieldPlugin from '../server';
import path from 'path';
describe('actions', () => {
let app: MockServer;
beforeEach(async () => {
app = mockServer({
registerActions: true,
acl: false,
plugins: ['error-handler', 'users', 'ui-schema-storage', 'collection-manager'],
});
app.plugin(SnapshotFieldPlugin, { name: 'snapshot-field' });
await app.loadAndInstall({ clean: true });
});
afterEach(async () => {
await app.cleanDb();
await app.destroy();
});
it.only('fieldsHistory collectionName and name conflict between tables', async () => {
const agent = app.agent();
const field = {
name: 'status',
interface: 'input',
type: 'string',
uiSchema: { type: 'string', 'x-component': 'Input', title: 'status' },
};
await agent.resource('collections').create({
values: {
name: 'table_a',
template: 'general',
fields: [field],
title: 'table_a',
},
});
await agent.resource('collections').create({
values: {
name: 'table_b',
template: 'general',
fields: [field],
title: 'table_b',
},
});
await agent.resource('collections.fields', 'table_b').destroy({
filterByTk: 'status',
});
const { statusCode } = await agent.resource('collections.fields', 'table_b').create({
values: field,
});
expect(statusCode).toBe(200);
});
});

View File

@ -44,6 +44,7 @@ export class SnapshotFieldPlugin extends Plugin {
const existField: Model = await fieldsHistoryRepository.findOne({
filter: {
name: fieldDoc.name,
collectionName: fieldDoc.collectionName,
},
});
if (existField) {