fix(plugin-field-sort): fix test case

This commit is contained in:
mytharcher 2024-08-21 14:39:39 +08:00
parent 65b6fb7b03
commit 086364de84
2 changed files with 1 additions and 57 deletions

View File

@ -20,7 +20,7 @@ export async function move(ctx: Context, next) {
return next();
}
if (repository.database) {
if (!repository.database) {
return ctx.throw(new Error(`Repository can not handle action move for ${ctx.action.resourceName}`));
}

View File

@ -9,7 +9,6 @@
import { list } from '../default-actions/list';
import { vi } from 'vitest';
import { createMoveAction } from '../default-actions/move';
describe('action test', () => {
describe('list action', async () => {
@ -100,59 +99,4 @@ describe('action test', () => {
]);
});
});
describe('move action', async () => {
it('should call database move action', async () => {
const dbMove = vi.fn();
const moveAction = createMoveAction(dbMove);
const ctx: any = {
getCurrentRepository() {
return {
database: {},
};
},
action: {
params: {
filterByTk: 1,
targetCollection: 'test',
},
},
};
await moveAction(ctx, () => {});
expect(dbMove).toHaveBeenCalled();
});
it('should move when repository can move', async () => {
const moveAction = createMoveAction(() => {});
const ctx: any = {
getCurrentRepository() {
return {};
},
action: {
params: {
filterByTk: 1,
targetCollection: 'test',
},
},
};
const moveFn = vi.fn();
vi.spyOn(ctx, 'getCurrentRepository').mockImplementation(() => {
return {
move: async () => {
moveFn();
},
};
});
await moveAction(ctx, () => {});
expect(moveFn).toHaveBeenCalled();
});
});
});