✅ Test refactoring, make test more stable (#374)
- Move copy-pasted code to User API - Clean the database after each test - Refactor documents search test
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
import { describe, beforeEach, it, expect, afterAll, jest } from "@jest/globals";
|
||||
import { init, TestPlatform } from "../setup";
|
||||
import TestHelpers from "../common/common_test_helpers";
|
||||
import UserApi from "../common/user-api";
|
||||
import { DocumentsEngine } from "../../../src/services/documents/services/engine";
|
||||
import { deserialize } from "class-transformer";
|
||||
import { File } from "../../../src/services/files/entities/file";
|
||||
import { ResourceUpdateResponse } from "../../../src/utils/types";
|
||||
import { e2e_createDocument, e2e_createDocumentFile, e2e_createVersion } from "./utils";
|
||||
import { DriveFileMockClass } from "../common/entities/mock_entities";
|
||||
import { TestDbService } from "../utils.prepare.db";
|
||||
import { e2e_createDocumentFile, e2e_createVersion } from "./utils";
|
||||
|
||||
describe("the Drive feature", () => {
|
||||
let platform: TestPlatform;
|
||||
@@ -16,6 +14,7 @@ describe("the Drive feature", () => {
|
||||
DocumentsEngine.prototype,
|
||||
"notifyDocumentVersionUpdated",
|
||||
);
|
||||
let currentUser: UserApi;
|
||||
|
||||
beforeEach(async () => {
|
||||
platform = await init({
|
||||
@@ -40,7 +39,8 @@ describe("the Drive feature", () => {
|
||||
"documents",
|
||||
],
|
||||
});
|
||||
}, 300000000);
|
||||
currentUser = await UserApi.getInstance(platform);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await platform?.tearDown();
|
||||
@@ -49,27 +49,12 @@ describe("the Drive feature", () => {
|
||||
platform = null;
|
||||
});
|
||||
|
||||
const createItem = async (): Promise<DriveFileMockClass> => {
|
||||
await TestDbService.getInstance(platform, true);
|
||||
const scope: "personal" | "shared" = "shared";
|
||||
const item = {
|
||||
name: "new test file",
|
||||
parent_id: "root",
|
||||
company_id: platform.workspace.company_id,
|
||||
scope,
|
||||
};
|
||||
|
||||
const version = {};
|
||||
|
||||
const response = await e2e_createDocument(platform, item, version);
|
||||
return deserialize<DriveFileMockClass>(DriveFileMockClass, response.body);
|
||||
};
|
||||
|
||||
it("Did notify the user after sharing a file.", async () => {
|
||||
// jest.setTimeout(20000);
|
||||
//given:: user uploaded one doc and give permission to another user
|
||||
const oneUser = await TestHelpers.getInstance(platform, true, { companyRole: "admin" });
|
||||
const anotherUser = await TestHelpers.getInstance(platform, true, { companyRole: "admin" });
|
||||
const oneUser = await UserApi.getInstance(platform, true, { companyRole: "admin" });
|
||||
const anotherUser = await UserApi.getInstance(platform, true, { companyRole: "admin" });
|
||||
//upload files
|
||||
const doc = await oneUser.uploadRandomFileAndCreateDocument();
|
||||
await new Promise(r => setTimeout(r, 3000));
|
||||
@@ -88,7 +73,7 @@ describe("the Drive feature", () => {
|
||||
});
|
||||
|
||||
it("Did notify the user after creating a new version for a file.", async () => {
|
||||
const item = await createItem();
|
||||
const item = await currentUser.createDefaultDocument();
|
||||
const fileUploadResponse = await e2e_createDocumentFile(platform);
|
||||
const fileUploadResult = deserialize<ResourceUpdateResponse<File>>(
|
||||
ResourceUpdateResponse,
|
||||
|
||||
Reference in New Issue
Block a user