fix: Delete collection exports (#2595)
This commit is contained in:
31
server/commands/fileOperationDeleter.js
Normal file
31
server/commands/fileOperationDeleter.js
Normal file
@@ -0,0 +1,31 @@
|
||||
// @flow
|
||||
import { FileOperation, Event, User } from "../models";
|
||||
import { sequelize } from "../sequelize";
|
||||
|
||||
export default async function fileOperationDeleter(
|
||||
fileOp: FileOperation,
|
||||
user: User,
|
||||
ip: string
|
||||
) {
|
||||
let transaction = await sequelize.transaction();
|
||||
|
||||
try {
|
||||
await fileOp.destroy({ transaction });
|
||||
|
||||
await Event.create(
|
||||
{
|
||||
name: "fileOperations.delete",
|
||||
teamId: user.teamId,
|
||||
actorId: user.id,
|
||||
data: fileOp.dataValues,
|
||||
ip,
|
||||
},
|
||||
{ transaction }
|
||||
);
|
||||
|
||||
await transaction.commit();
|
||||
} catch (error) {
|
||||
await transaction.rollback();
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
31
server/commands/fileOperationDeleter.test.js
Normal file
31
server/commands/fileOperationDeleter.test.js
Normal file
@@ -0,0 +1,31 @@
|
||||
// @flow
|
||||
import { FileOperation } from "../models";
|
||||
import { buildAdmin, buildFileOperation } from "../test/factories";
|
||||
import { flushdb } from "../test/support";
|
||||
import fileOperationDeleter from "./fileOperationDeleter";
|
||||
|
||||
jest.mock("aws-sdk", () => {
|
||||
const mS3 = { deleteObject: jest.fn().mockReturnThis(), promise: jest.fn() };
|
||||
return {
|
||||
S3: jest.fn(() => mS3),
|
||||
Endpoint: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
beforeEach(() => flushdb());
|
||||
|
||||
describe("fileOperationDeleter", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
it("should destroy file operation", async () => {
|
||||
const admin = await buildAdmin();
|
||||
const fileOp = await buildFileOperation({
|
||||
userId: admin.id,
|
||||
teamId: admin.teamId,
|
||||
});
|
||||
|
||||
await fileOperationDeleter(fileOp, admin, ip);
|
||||
|
||||
expect(await FileOperation.count()).toEqual(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user