From 22339d9ef705680a67b2a28018438716525c32b7 Mon Sep 17 00:00:00 2001 From: anuoua Date: Sun, 29 Jan 2023 01:32:18 +0800 Subject: [PATCH] Fix/snapshot (#1396) * feat: snapshot field check add collectionName * feat: snapshot add test * fix: filterByTk * Update ResourceActionProvider.tsx --------- Co-authored-by: chenos --- .../src/__tests__/fieldsHistory.test.ts | 63 +++++++++++++++++++ .../snapshot-field/src/server/plugin.ts | 1 + 2 files changed, 64 insertions(+) create mode 100644 packages/plugins/snapshot-field/src/__tests__/fieldsHistory.test.ts diff --git a/packages/plugins/snapshot-field/src/__tests__/fieldsHistory.test.ts b/packages/plugins/snapshot-field/src/__tests__/fieldsHistory.test.ts new file mode 100644 index 000000000..0d7311d23 --- /dev/null +++ b/packages/plugins/snapshot-field/src/__tests__/fieldsHistory.test.ts @@ -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); + }); +}); diff --git a/packages/plugins/snapshot-field/src/server/plugin.ts b/packages/plugins/snapshot-field/src/server/plugin.ts index aed76cc14..b54364992 100644 --- a/packages/plugins/snapshot-field/src/server/plugin.ts +++ b/packages/plugins/snapshot-field/src/server/plugin.ts @@ -44,6 +44,7 @@ export class SnapshotFieldPlugin extends Plugin { const existField: Model = await fieldsHistoryRepository.findOne({ filter: { name: fieldDoc.name, + collectionName: fieldDoc.collectionName, }, }); if (existField) {