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:
		
							parent
							
								
									0d30366aba
								
							
						
					
					
						commit
						22339d9ef7
					
				@ -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);
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
@ -44,6 +44,7 @@ export class SnapshotFieldPlugin extends Plugin {
 | 
			
		||||
      const existField: Model = await fieldsHistoryRepository.findOne({
 | 
			
		||||
        filter: {
 | 
			
		||||
          name: fieldDoc.name,
 | 
			
		||||
          collectionName: fieldDoc.collectionName,
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
      if (existField) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user