🤝 Shared with me (#71)
* 🚧 #46 Shared with me - added converter of DriveFile to dto with user information - updated version of jest to the latest for better compatibility with typescript and mocking class instances - added run configuration for unit tests Co-authored-by: Romaric Mourgues <rmourgues@linagora.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Tests in e2e/" type="JavaScriptTestRunnerJest" nameIsGenerated="true">
|
||||
<configuration default="false" name="Run all e2e [ElsticSearch]" type="JavaScriptTestRunnerJest">
|
||||
<node-interpreter value="project" />
|
||||
<jest-package value="$PROJECT_DIR$/tdrive/backend/node/node_modules/jest" />
|
||||
<working-dir value="$PROJECT_DIR$/tdrive/backend/node" />
|
||||
@@ -0,0 +1,18 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Run all e2e [MongoDB]" type="JavaScriptTestRunnerJest">
|
||||
<node-interpreter value="project" />
|
||||
<jest-package value="$PROJECT_DIR$/tdrive/backend/node/node_modules/jest" />
|
||||
<working-dir value="$PROJECT_DIR$/tdrive/backend/node" />
|
||||
<jest-options value="--forceExit --coverage --detectOpenHandles --maxWorkers=1 --testTimeout=30000" />
|
||||
<envs>
|
||||
<env name="DB_DRIVER" value="mongodb" />
|
||||
<env name="DB_MONGO_URI" value="mongodb://localhost:27017" />
|
||||
<env name="PUBSUB_TYPE" value="local" />
|
||||
<env name="SEARCH_DRIVER" value="mongodb" />
|
||||
<env name="STORAGE_LOCAL_PATH" value="$USER_HOME$/dev/linagora/TDrive/tdrive/docker-data" />
|
||||
</envs>
|
||||
<scope-kind value="DIRECTORY" />
|
||||
<test-directory value="$PROJECT_DIR$/tdrive/backend/node/test/e2e" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -0,0 +1,18 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Run all unit" type="JavaScriptTestRunnerJest">
|
||||
<node-interpreter value="project" />
|
||||
<jest-package value="$PROJECT_DIR$/tdrive/backend/node/node_modules/jest" />
|
||||
<working-dir value="$PROJECT_DIR$/tdrive/backend/node" />
|
||||
<jest-options value="--testTimeout=30000" />
|
||||
<envs>
|
||||
<env name="DB_DRIVER" value="mongodb" />
|
||||
<env name="DB_MONGO_URI" value="mongodb://localhost:27017" />
|
||||
<env name="PUBSUB_TYPE" value="local" />
|
||||
<env name="SEARCH_DRIVER" value="mongodb" />
|
||||
<env name="STORAGE_LOCAL_PATH" value="$USER_HOME$/dev/linagora/TDrive/tdrive/docker-data" />
|
||||
</envs>
|
||||
<scope-kind value="DIRECTORY" />
|
||||
<test-directory value="$PROJECT_DIR$/tdrive/backend/node/test/unit" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -3,6 +3,7 @@
|
||||
<node-interpreter value="project" />
|
||||
<jest-package value="$PROJECT_DIR$/tdrive/backend/node/node_modules/jest" />
|
||||
<working-dir value="$PROJECT_DIR$/tdrive/backend/node" />
|
||||
<jest-options value="--testTimeout=30000" />
|
||||
<envs>
|
||||
<env name="DB_DRIVER" value="mongodb" />
|
||||
<env name="DB_MONGO_URI" value="mongodb://localhost:27017" />
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<node-interpreter value="project" />
|
||||
<jest-package value="$PROJECT_DIR$/tdrive/backend/node/node_modules/jest" />
|
||||
<working-dir value="$PROJECT_DIR$/tdrive/backend/node" />
|
||||
<jest-options value="--testTimeout=30000" />
|
||||
<envs>
|
||||
<env name="DB_DRIVER" value="mongodb" />
|
||||
<env name="DB_MONGO_URI" value="mongodb://localhost:27017" />
|
||||
|
||||
Generated
+1588
-2439
File diff suppressed because it is too large
Load Diff
@@ -75,7 +75,7 @@
|
||||
"@types/fastify-static": "^2.2.1",
|
||||
"@types/fluent-ffmpeg": "^2.1.20",
|
||||
"@types/html-to-text": "^8.1.1",
|
||||
"@types/jest": "^26.0.14",
|
||||
"@types/jest": "^29.1.0",
|
||||
"@types/lodash": "^4.14.165",
|
||||
"@types/minio": "^7.0.7",
|
||||
"@types/mongodb": "^4.0.7",
|
||||
@@ -94,7 +94,7 @@
|
||||
"@types/ws": "^7.2.7",
|
||||
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
||||
"@typescript-eslint/parser": "^4.2.0",
|
||||
"babel-jest": "^26.5.2",
|
||||
"babel-jest": "^29.1.0",
|
||||
"babel-plugin-parameter-decorator": "^1.0.16",
|
||||
"chai": "^4.2.0",
|
||||
"cpy-cli": "^4.2.0",
|
||||
@@ -103,17 +103,19 @@
|
||||
"eslint-plugin-prettier": "^3.1.4",
|
||||
"eslint-plugin-unused-imports": "^2.0.0",
|
||||
"form-auto-content": "^2.2.0",
|
||||
"jest": "^26.6.3",
|
||||
"jest": "^29.1.0",
|
||||
"jest-mock-extended": "^3.0.4",
|
||||
"nodemon": "2.0.4",
|
||||
"pino-pretty": "^10.0.0",
|
||||
"prettier": "^2.1.2",
|
||||
"rimraf": "^3.0.2",
|
||||
"supertest": "4.0.2",
|
||||
"ts-jest": "^26.4.0",
|
||||
"ts-jest": "^29.1.0",
|
||||
"ts-node": "^9.0.0",
|
||||
"ts-node-dev": "^1.1.8",
|
||||
"tsc-watch": "^4.2.9",
|
||||
"typescript": "^4.0.3"
|
||||
"typescript": "^4.0.3",
|
||||
"tsconfig-paths": "^3.14.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@elastic/elasticsearch": "7",
|
||||
|
||||
@@ -89,4 +89,5 @@ type AuthEntity = {
|
||||
type: "user" | "channel" | "company" | "folder";
|
||||
id: string | "parent";
|
||||
level: publicAccessLevel | DriveFileAccessLevel;
|
||||
grantor: string;
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ import _ from "lodash";
|
||||
import { logger } from "../../../core/platform/framework";
|
||||
import Repository from "../../../core/platform/services/database/services/orm/repository/repository";
|
||||
import globalResolver from "../../global-resolver";
|
||||
import { DriveFile } from "../entities/drive-file";
|
||||
import { AccessInformation, DriveFile } from "../entities/drive-file";
|
||||
import { CompanyExecutionContext, DriveFileAccessLevel } from "../types";
|
||||
|
||||
/**
|
||||
@@ -325,3 +325,22 @@ export const makeStandaloneAccessLevel = async (
|
||||
|
||||
return accessInfo;
|
||||
};
|
||||
|
||||
export const getSharedByUser = (
|
||||
accessInfo: AccessInformation,
|
||||
context: CompanyExecutionContext,
|
||||
): string => {
|
||||
// Try to find entity that matches user the most
|
||||
// at first user, and then company
|
||||
// we don't consider right now the access level by folder or channel or workspace
|
||||
for (const idx in accessInfo?.entities) {
|
||||
const entity = accessInfo.entities[idx];
|
||||
if (entity.type === "user" && entity.id === context.user?.id) {
|
||||
return entity.grantor;
|
||||
}
|
||||
if (entity.type === "company" && entity.id === context.company.id) {
|
||||
return entity.grantor;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
@@ -370,7 +370,14 @@ export class DocumentsService {
|
||||
oldParent = item.parent_id;
|
||||
}
|
||||
|
||||
if (key === "name") {
|
||||
if (key === "access_info") {
|
||||
item.access_info = content.access_info;
|
||||
item.access_info.entities.forEach(info => {
|
||||
if (!info.grantor) {
|
||||
info.grantor = context.user.id;
|
||||
}
|
||||
});
|
||||
} else if (key === "name") {
|
||||
item.name = await getItemName(
|
||||
content.parent_id || item.parent_id,
|
||||
item.id,
|
||||
@@ -885,6 +892,7 @@ export class DocumentsService {
|
||||
type: "channel",
|
||||
id: channelId,
|
||||
level: level === "write" ? "write" : "read",
|
||||
grantor: context.user.id,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -47,6 +47,8 @@ export type SearchDocumentsOptions = {
|
||||
last_modified_gt?: number;
|
||||
last_modified_lt?: number;
|
||||
sort?: SortType;
|
||||
view?: string;
|
||||
fields?: string[];
|
||||
};
|
||||
|
||||
export type SearchDocumentsBody = {
|
||||
@@ -59,6 +61,8 @@ export type SearchDocumentsBody = {
|
||||
last_modified_gt?: number;
|
||||
last_modified_lt?: number;
|
||||
sort?: SortType;
|
||||
view?: string;
|
||||
fields?: string[];
|
||||
};
|
||||
|
||||
export type DocumentsMessageQueueRequest = {
|
||||
|
||||
@@ -61,16 +61,19 @@ export const getDefaultDriveItem = (
|
||||
id: "parent",
|
||||
type: "folder",
|
||||
level: "manage",
|
||||
grantor: null,
|
||||
},
|
||||
{
|
||||
id: item.company_id,
|
||||
type: "company",
|
||||
level: "none",
|
||||
grantor: null,
|
||||
},
|
||||
{
|
||||
id: context.user?.id,
|
||||
type: "user",
|
||||
level: "manage",
|
||||
grantor: null,
|
||||
},
|
||||
],
|
||||
public: {
|
||||
@@ -476,7 +479,7 @@ export const getItemName = async (
|
||||
* @param {string} source - the to be moved item id.
|
||||
* @param {string} target - the to be moved to item id.
|
||||
* @param {string} repository - the Drive item repository.
|
||||
* @param {CompanyExecutionContex} context - the execution context.
|
||||
* @param {CompanyExecutionContext} context - the execution context.
|
||||
* @returns {Promise<boolean>} - whether the move is possible or not.
|
||||
*/
|
||||
export const canMoveItem = async (
|
||||
@@ -531,7 +534,11 @@ export const canMoveItem = async (
|
||||
return true;
|
||||
};
|
||||
|
||||
export function isFileType(fileMime: string, fileName: string, requiredExtensions: string[]): any {
|
||||
export function isFileType(
|
||||
fileMime: string,
|
||||
fileName: string,
|
||||
requiredExtensions: string[],
|
||||
): boolean {
|
||||
const extension = fileName.split(".").pop();
|
||||
const secondaryExtensions = Object.keys(mimes).filter(k => mimes[k] === fileMime);
|
||||
const fileExtensions = [extension, ...secondaryExtensions];
|
||||
|
||||
@@ -18,8 +18,12 @@ import {
|
||||
SearchDocumentsBody,
|
||||
SearchDocumentsOptions,
|
||||
} from "../../types";
|
||||
import { DriveFileDTO } from "../dto/drive-file-dto";
|
||||
import { DriveFileDTOBuilder } from "../dto/drive-file-dto-builder";
|
||||
|
||||
export class DocumentsController {
|
||||
private driveFileDTOBuilder = new DriveFileDTOBuilder();
|
||||
|
||||
/**
|
||||
* Creates a DriveFile item
|
||||
*
|
||||
@@ -340,7 +344,7 @@ export class DocumentsController {
|
||||
Body: SearchDocumentsBody;
|
||||
Querystring: { public_token?: string };
|
||||
}>,
|
||||
): Promise<ListResult<DriveFile>> => {
|
||||
): Promise<ListResult<DriveFileDTO>> => {
|
||||
try {
|
||||
const context = getDriveExecutionContext(request);
|
||||
|
||||
@@ -353,7 +357,9 @@ export class DocumentsController {
|
||||
this.throw500Search();
|
||||
}
|
||||
|
||||
return await globalResolver.services.documents.documents.search(options, context);
|
||||
const fileList = await globalResolver.services.documents.documents.search(options, context);
|
||||
|
||||
return this.driveFileDTOBuilder.build(fileList, context, options.fields, options.view);
|
||||
} catch (error) {
|
||||
logger.error("error while searching for document", error);
|
||||
this.throw500Search();
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
import { DriveFile } from "../../entities/drive-file";
|
||||
import { DriveFileDTO } from "./drive-file-dto";
|
||||
import {
|
||||
ListResult,
|
||||
Paginable,
|
||||
Pagination,
|
||||
} from "../../../../core/platform/framework/api/crud-service";
|
||||
import _ from "lodash";
|
||||
import { CompanyExecutionContext } from "../../types";
|
||||
import globalResolver from "../../../../services/global-resolver";
|
||||
import User from "../../../../services/user/entities/user";
|
||||
import { getSharedByUser } from "../../services/access-check";
|
||||
|
||||
export class DriveFileDTOBuilder {
|
||||
private views: Map<string, string[]> = new Map([
|
||||
["default", Object.getOwnPropertyNames(new DriveFile())],
|
||||
[
|
||||
"shared_with_me",
|
||||
[
|
||||
"id",
|
||||
"name",
|
||||
"parent_id",
|
||||
"shared_by",
|
||||
"created_by",
|
||||
"is_directory",
|
||||
"extension",
|
||||
"added",
|
||||
"last_modified",
|
||||
"size",
|
||||
"last_version_cache",
|
||||
],
|
||||
],
|
||||
]);
|
||||
usersService = globalResolver.services?.users;
|
||||
|
||||
public async build(
|
||||
files: ListResult<DriveFile>,
|
||||
context: CompanyExecutionContext,
|
||||
fields?: string[],
|
||||
view?: string,
|
||||
): Promise<ListResult<DriveFileDTO>> {
|
||||
if (view) {
|
||||
fields = this.views.get(view);
|
||||
}
|
||||
if (!fields) {
|
||||
fields = this.views.get("default");
|
||||
}
|
||||
|
||||
//if we need to fetch users, find all the user identifiers ask theirs data at once
|
||||
const fileUsers = new Map<string, FileUsers>();
|
||||
// gather all user identifiers who share files with the current user
|
||||
if (fields.some(f => f == "shared_by")) {
|
||||
files.getEntities().forEach(f => {
|
||||
fileUsers.set(f.id, { grantor: getSharedByUser(f.access_info, context) });
|
||||
});
|
||||
}
|
||||
// gather all users who created the files
|
||||
if (fields.some(f => f == "created_by")) {
|
||||
files.getEntities().forEach(f => {
|
||||
if (!fileUsers.has(f.id)) fileUsers.set(f.id, { creator: f.creator });
|
||||
else fileUsers.get(f.id).creator = f.creator;
|
||||
});
|
||||
}
|
||||
if (fileUsers.size > 0) {
|
||||
await this.initUserCash(fileUsers);
|
||||
}
|
||||
|
||||
const nextPage: Paginable = new Pagination(files.page_token, files.nextPage?.limitStr);
|
||||
return new ListResult(
|
||||
"drive_files_dto",
|
||||
files.getEntities().map(f => this._buildDto(f, fields, fileUsers)),
|
||||
nextPage,
|
||||
);
|
||||
}
|
||||
|
||||
private async initUserCash(fileUsers: Map<string, FileUsers>): Promise<void> {
|
||||
const ids = [] as string[];
|
||||
fileUsers.forEach(f => {
|
||||
if (f.creator) ids.push(f.creator);
|
||||
if (f.grantor) ids.push(f.grantor);
|
||||
});
|
||||
|
||||
const users = await this.fetchUsers(ids);
|
||||
const userById = new Map(users.map(u => [u.id, u]));
|
||||
fileUsers.forEach(f => {
|
||||
f.creatorObj = userById.get(f.creator);
|
||||
f.grantorObj = userById.get(f.grantor);
|
||||
});
|
||||
}
|
||||
|
||||
private async fetchUsers(ids: string[]) {
|
||||
return (
|
||||
await this.usersService.list(
|
||||
{
|
||||
limitStr: ids.length.toString(),
|
||||
} as Pagination,
|
||||
{ userIds: _.uniq(ids) },
|
||||
)
|
||||
).getEntities();
|
||||
}
|
||||
|
||||
private _buildDto(file: DriveFile, fields: string[], userCache: Map<string, FileUsers>) {
|
||||
const dto = _.pick(file, fields) as DriveFileDTO;
|
||||
const users = userCache.get(file.id);
|
||||
if (users) {
|
||||
dto.created_by = users?.creatorObj;
|
||||
dto.shared_by = users?.grantorObj;
|
||||
}
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
|
||||
type FileUsers = {
|
||||
creator?: string;
|
||||
grantor?: string;
|
||||
creatorObj?: User;
|
||||
grantorObj?: User;
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import { DriveFile } from "../../entities/drive-file";
|
||||
import User from "../../../user/entities/user";
|
||||
|
||||
export class DriveFileDTO extends DriveFile {
|
||||
created_by: User;
|
||||
shared_by: User;
|
||||
}
|
||||
@@ -28,6 +28,9 @@ export class DriveFileMockClass {
|
||||
last_modified: string;
|
||||
access_info: MockAccessInformation;
|
||||
creator: string;
|
||||
is_directory: boolean;
|
||||
created_by: Record<string, any>;
|
||||
shared_by: Record<string, any>;
|
||||
}
|
||||
|
||||
export class DriveItemDetailsMockClass {
|
||||
|
||||
@@ -51,15 +51,12 @@ describe("the Drive Tdrive tabs feature", () => {
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await platform.tearDown();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await platform.app.close();
|
||||
await platform?.tearDown();
|
||||
platform = null;
|
||||
});
|
||||
|
||||
it("did create a tab configuration on Drive side", async done => {
|
||||
it("did create a tab configuration on Drive side", async () => {
|
||||
await TestDbService.getInstance(platform, true);
|
||||
|
||||
const item = {
|
||||
@@ -125,11 +122,9 @@ describe("the Drive Tdrive tabs feature", () => {
|
||||
a => a?.type === "channel" && a.id === "abcdefghij" && a.level === "write",
|
||||
),
|
||||
).toBeDefined();
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("did refuse to create a tab configuration for an item I can't manage", async done => {
|
||||
it("did refuse to create a tab configuration for an item I can't manage", async () => {
|
||||
const dbService = await TestDbService.getInstance(platform, true);
|
||||
const ws0pk = {
|
||||
id: platform.workspace.workspace_id,
|
||||
@@ -177,7 +172,5 @@ describe("the Drive Tdrive tabs feature", () => {
|
||||
});
|
||||
|
||||
expect(createdTab.statusCode).toBe(403);
|
||||
|
||||
done?.();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,7 +14,11 @@ import {
|
||||
e2e_updateDocument,
|
||||
} from "./utils";
|
||||
import TestHelpers from "../common/common_test_helpers";
|
||||
import {DriveFileMockClass, DriveItemDetailsMockClass, SearchResultMockClass} from "../common/entities/mock_entities";
|
||||
import {
|
||||
DriveFileMockClass,
|
||||
DriveItemDetailsMockClass,
|
||||
SearchResultMockClass,
|
||||
} from "../common/entities/mock_entities";
|
||||
|
||||
describe("the Drive feature", () => {
|
||||
let platform: TestPlatform;
|
||||
@@ -48,12 +52,9 @@ describe("the Drive feature", () => {
|
||||
dbService = await TestDbService.getInstance(platform, true);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await platform.tearDown();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await platform.app.close();
|
||||
await platform?.tearDown();
|
||||
platform = null;
|
||||
});
|
||||
|
||||
const createItem = async (): Promise<DriveFileMockClass> => {
|
||||
@@ -71,17 +72,15 @@ describe("the Drive feature", () => {
|
||||
return deserialize<DriveFileMockClass>(DriveFileMockClass, response.body);
|
||||
};
|
||||
|
||||
it("did create the drive item", async done => {
|
||||
it("did create the drive item", async () => {
|
||||
const result = await createItem();
|
||||
|
||||
expect(result).toBeDefined();
|
||||
expect(result.name).toEqual("new test file");
|
||||
expect(result.added).toBeDefined();
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("did fetch the drive item", async done => {
|
||||
it("did fetch the drive item", async () => {
|
||||
await TestDbService.getInstance(platform, true);
|
||||
|
||||
const response = await e2e_getDocument(platform, "");
|
||||
@@ -89,11 +88,9 @@ describe("the Drive feature", () => {
|
||||
|
||||
expect(result.item.id).toEqual("root");
|
||||
expect(result.item.name).toEqual("Home");
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("did fetch the trash", async done => {
|
||||
it("did fetch the trash", async () => {
|
||||
await TestDbService.getInstance(platform, true);
|
||||
|
||||
const response = await e2e_getDocument(platform, "trash");
|
||||
@@ -101,22 +98,18 @@ describe("the Drive feature", () => {
|
||||
|
||||
expect(result.item.id).toEqual("trash");
|
||||
expect(result.item.name).toEqual("Trash");
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("did delete an item", async done => {
|
||||
it("did delete an item", async () => {
|
||||
const createItemResult = await createItem();
|
||||
|
||||
expect(createItemResult.id).toBeDefined();
|
||||
|
||||
const deleteResponse = await e2e_deleteDocument(platform, createItemResult.id);
|
||||
expect(deleteResponse.statusCode).toEqual(200);
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("did update an item", async done => {
|
||||
it("did update an item", async () => {
|
||||
const createItemResult = await createItem();
|
||||
|
||||
expect(createItemResult.id).toBeDefined();
|
||||
@@ -133,11 +126,9 @@ describe("the Drive feature", () => {
|
||||
|
||||
expect(createItemResult.id).toEqual(updateItemResult.id);
|
||||
expect(updateItemResult.name).toEqual("somethingelse");
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("did move an item to trash", async done => {
|
||||
it("did move an item to trash", async () => {
|
||||
const createItemResult = await createItem();
|
||||
|
||||
expect(createItemResult.id).toBeDefined();
|
||||
@@ -153,11 +144,9 @@ describe("the Drive feature", () => {
|
||||
|
||||
expect(listTrashResult.item.name).toEqual("Trash");
|
||||
expect(listTrashResult.children.some(({ id }) => id === createItemResult.id)).toBeTruthy();
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("did search for an item", async done => {
|
||||
it("did search for an item", async () => {
|
||||
jest.setTimeout(10000);
|
||||
const createItemResult = await createItem();
|
||||
|
||||
@@ -179,11 +168,50 @@ describe("the Drive feature", () => {
|
||||
);
|
||||
|
||||
expect(searchResult.entities.length).toBeGreaterThanOrEqual(1);
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("did search for an item that doesn't exist", async done => {
|
||||
it("did search for an item and check that all the fields for 'shared_with_me' view", async () => {
|
||||
jest.setTimeout(10000);
|
||||
//given:: user uploaded one doc and give permission to another user
|
||||
const oneUser = await TestHelpers.getInstance(platform, true);
|
||||
const anotherUser = await TestHelpers.getInstance(platform, true);
|
||||
//upload files
|
||||
const doc = await oneUser.uploadRandomFileAndCreateDocument();
|
||||
await new Promise(r => setTimeout(r, 3000));
|
||||
//give permissions to the file
|
||||
doc.access_info.entities.push({
|
||||
type: "user",
|
||||
id: anotherUser.user.id,
|
||||
level: "read",
|
||||
grantor: null,
|
||||
});
|
||||
await oneUser.updateDocument(doc.id, doc);
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 3000));
|
||||
|
||||
//when:: user search for a doc
|
||||
const searchResponse = await anotherUser.searchDocument({ view: "shared_with_me" });
|
||||
|
||||
//then::
|
||||
expect(searchResponse.entities?.length).toEqual(1);
|
||||
const actual = searchResponse.entities[0];
|
||||
|
||||
//file name
|
||||
expect(actual.name).toEqual(doc.name);
|
||||
//file type
|
||||
expect(actual.extension).toEqual(doc.extension);
|
||||
expect(actual.id).toEqual(doc.id);
|
||||
expect(actual.is_directory).toEqual(doc.is_directory);
|
||||
expect(actual.last_modified).toEqual(doc.last_modified);
|
||||
expect(actual.added).toEqual(doc.added);
|
||||
expect(actual.parent_id).toEqual(doc.parent_id);
|
||||
expect(actual.created_by?.id).toEqual(oneUser.user.id);
|
||||
expect(actual.created_by?.first_name).toEqual(oneUser.user.first_name);
|
||||
expect(actual.shared_by?.id).toEqual(oneUser.user.id);
|
||||
expect(actual.shared_by?.first_name).toEqual(oneUser.user.first_name);
|
||||
});
|
||||
|
||||
it("did search for an item that doesn't exist", async () => {
|
||||
await createItem();
|
||||
|
||||
const unexistingSeachPayload = {
|
||||
@@ -196,11 +224,9 @@ describe("the Drive feature", () => {
|
||||
);
|
||||
|
||||
expect(failSearchResult.entities).toHaveLength(0);
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("did create a version for a drive item", async done => {
|
||||
it("did create a version for a drive item", async () => {
|
||||
const item = await createItem();
|
||||
const fileUploadResponse = await e2e_createDocumentFile(platform);
|
||||
const fileUploadResult = deserialize<ResourceUpdateResponse<File>>(
|
||||
@@ -221,41 +247,38 @@ describe("the Drive feature", () => {
|
||||
);
|
||||
|
||||
expect(fetchItemResult.versions).toHaveLength(4);
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("did search by mime type", async done => {
|
||||
it("did search by mime type", async () => {
|
||||
jest.setTimeout(10000);
|
||||
// given:: all the sample files uploaded and documents for them created
|
||||
await Promise.all((await currentUser.uploadFiles()).map(f => currentUser.createDocumentFromFile(f)))
|
||||
await Promise.all(
|
||||
(await currentUser.uploadFiles()).map(f => currentUser.createDocumentFromFile(f)),
|
||||
);
|
||||
|
||||
const filters = {
|
||||
mime_type: "application/pdf",
|
||||
};
|
||||
|
||||
jest.setTimeout(10000);
|
||||
await new Promise(r => setTimeout(r, 5000));
|
||||
|
||||
|
||||
let documents = await currentUser.searchDocument(filters);
|
||||
expect(documents.entities).toHaveLength(1);
|
||||
|
||||
const actualFile = documents.entities[0];
|
||||
expect(actualFile.name).toEqual("sample.pdf");
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("did search by last modified", async done => {
|
||||
it("did search by last modified", async () => {
|
||||
jest.setTimeout(10000);
|
||||
const user = await TestHelpers.getInstance(platform, true);
|
||||
// given:: all the sample files uploaded and documents for them created
|
||||
const start = new Date().getTime();
|
||||
await user.uploadAllFilesOneByOne()
|
||||
await user.uploadAllFilesOneByOne();
|
||||
const end = new Date().getTime();
|
||||
await user.uploadAllFilesOneByOne()
|
||||
await user.uploadAllFilesOneByOne();
|
||||
//wait for putting docs to elastic and its indexing
|
||||
await new Promise(r => setTimeout(r, 3000));
|
||||
await new Promise(r => setTimeout(r, 5000));
|
||||
|
||||
//then:: all the files are searchable without filters
|
||||
let documents = await user.searchDocument({});
|
||||
@@ -264,21 +287,19 @@ describe("the Drive feature", () => {
|
||||
//then:: only file uploaded in the [start, end] interval are shown in the search results
|
||||
const filters = {
|
||||
last_modified_gt: start.toString(),
|
||||
last_modified_lt: end.toString()
|
||||
last_modified_lt: end.toString(),
|
||||
};
|
||||
documents = await user.searchDocument(filters);
|
||||
expect(documents.entities).toHaveLength(TestHelpers.ALL_FILES.length);
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("did search a file shared by another user", async done => {
|
||||
it("did search a file shared by another user", async () => {
|
||||
jest.setTimeout(30000);
|
||||
//given:
|
||||
const oneUser = await TestHelpers.getInstance(platform, true);
|
||||
const anotherUser = await TestHelpers.getInstance(platform, true);
|
||||
//upload files
|
||||
let files = await oneUser.uploadAllFilesOneByOne()
|
||||
let files = await oneUser.uploadAllFilesOneByOne();
|
||||
|
||||
await new Promise(r => setTimeout(r, 5000));
|
||||
|
||||
@@ -292,56 +313,61 @@ describe("the Drive feature", () => {
|
||||
files[0].access_info.entities.push({
|
||||
type: "user",
|
||||
id: anotherUser.user.id,
|
||||
level: "read"
|
||||
})
|
||||
level: "read",
|
||||
grantor: null,
|
||||
});
|
||||
await oneUser.updateDocument(files[0].id, files[0]);
|
||||
await new Promise(r => setTimeout(r, 3000));
|
||||
|
||||
//then file become searchable
|
||||
expect((await anotherUser.searchDocument({})).entities).toHaveLength(1);
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("did search a file by file owner", async done => {
|
||||
it("did search a file by file owner", async () => {
|
||||
jest.setTimeout(30000);
|
||||
//given:
|
||||
const oneUser = await TestHelpers.getInstance(platform, true);
|
||||
const anotherUser = await TestHelpers.getInstance(platform, true);
|
||||
//upload files
|
||||
let files = await oneUser.uploadAllFilesOneByOne()
|
||||
await anotherUser.uploadAllFilesOneByOne()
|
||||
let files = await oneUser.uploadAllFilesOneByOne();
|
||||
await anotherUser.uploadAllFilesOneByOne();
|
||||
//give permissions for all files to 'another user'
|
||||
await Promise.all(files.map(f => {
|
||||
await Promise.all(
|
||||
files.map(f => {
|
||||
f.access_info.entities.push({
|
||||
type: "user",
|
||||
id: anotherUser.user.id,
|
||||
level: "read"
|
||||
})
|
||||
level: "read",
|
||||
grantor: null,
|
||||
});
|
||||
return oneUser.updateDocument(f.id, f);
|
||||
}));
|
||||
}),
|
||||
);
|
||||
|
||||
await new Promise(r => setTimeout(r, 5000));
|
||||
|
||||
//then:: all files are searchable for 'another user'
|
||||
expect((await anotherUser.searchDocument({})).entities).toHaveLength(TestHelpers.ALL_FILES.length * 2);
|
||||
expect((await anotherUser.searchDocument({})).entities).toHaveLength(
|
||||
TestHelpers.ALL_FILES.length * 2,
|
||||
);
|
||||
|
||||
//and searchable for user that have
|
||||
expect((await oneUser.searchDocument({
|
||||
expect(
|
||||
(
|
||||
await oneUser.searchDocument({
|
||||
creator: oneUser.user.id,
|
||||
})).entities).toHaveLength(TestHelpers.ALL_FILES.length);
|
||||
|
||||
done?.();
|
||||
|
||||
})
|
||||
).entities,
|
||||
).toHaveLength(TestHelpers.ALL_FILES.length);
|
||||
});
|
||||
|
||||
it("did search by 'added' date", async done => {
|
||||
it("did search by 'added' date", async () => {
|
||||
jest.setTimeout(10000);
|
||||
const user = await TestHelpers.getInstance(platform, true);
|
||||
// given:: all the sample files uploaded and documents for them created
|
||||
await user.uploadRandomFileAndCreateDocument();
|
||||
const start = new Date().getTime();
|
||||
await user.uploadAllFilesAndCreateDocuments()
|
||||
await user.uploadAllFilesAndCreateDocuments();
|
||||
const end = new Date().getTime();
|
||||
await user.uploadRandomFileAndCreateDocument();
|
||||
//wait for putting docs to elastic and its indexing
|
||||
@@ -354,19 +380,17 @@ describe("the Drive feature", () => {
|
||||
//then:: only file uploaded in the [start, end] interval are shown in the search results
|
||||
const filters = {
|
||||
added_gt: start.toString(),
|
||||
added_lt: end.toString()
|
||||
added_lt: end.toString(),
|
||||
};
|
||||
documents = await user.searchDocument(filters);
|
||||
expect(documents.entities).toHaveLength(TestHelpers.ALL_FILES.length);
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("did search order by name", async done => {
|
||||
it("did search order by name", async () => {
|
||||
jest.setTimeout(10000);
|
||||
const user = await TestHelpers.getInstance(platform, true);
|
||||
// given:: all the sample files uploaded and documents for them created
|
||||
await user.uploadAllFilesAndCreateDocuments()
|
||||
await user.uploadAllFilesAndCreateDocuments();
|
||||
//wait for putting docs to elastic and its indexing
|
||||
await new Promise(r => setTimeout(r, 5000));
|
||||
|
||||
@@ -374,20 +398,19 @@ describe("the Drive feature", () => {
|
||||
const options = {
|
||||
sort: {
|
||||
name_keyword: "asc",
|
||||
}
|
||||
},
|
||||
};
|
||||
const documents = await user.searchDocument(options);
|
||||
|
||||
//then all the files are sorted properly by name
|
||||
expect(documents.entities.map(e => e.name)).toEqual(TestHelpers.ALL_FILES.sort());
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("did search order by name desc", async done => {
|
||||
it("did search order by name desc", async () => {
|
||||
jest.setTimeout(10000);
|
||||
const user = await TestHelpers.getInstance(platform, true);
|
||||
// given:: all the sample files uploaded and documents for them created
|
||||
await user.uploadAllFilesOneByOne()
|
||||
await user.uploadAllFilesOneByOne();
|
||||
//wait for putting docs to elastic and its indexing
|
||||
await new Promise(r => setTimeout(r, 5000));
|
||||
|
||||
@@ -395,16 +418,15 @@ describe("the Drive feature", () => {
|
||||
const options = {
|
||||
sort: {
|
||||
name_keyword: "desc",
|
||||
}
|
||||
},
|
||||
};
|
||||
const documents = await user.searchDocument(options);
|
||||
|
||||
//then all the files are sorted properly by name
|
||||
expect(documents.entities.map(e => e.name)).toEqual(TestHelpers.ALL_FILES.sort().reverse());
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("did search order by added date", async done => {
|
||||
it("did search order by added date", async () => {
|
||||
jest.setTimeout(10000);
|
||||
const user = await TestHelpers.getInstance(platform, true);
|
||||
// given:: all the sample files uploaded and documents for them created
|
||||
@@ -416,17 +438,15 @@ describe("the Drive feature", () => {
|
||||
const options = {
|
||||
sort: {
|
||||
added: "asc",
|
||||
}
|
||||
},
|
||||
};
|
||||
const documents = await user.searchDocument(options);
|
||||
|
||||
//then:: files should be sorted properly
|
||||
expect(documents.entities.map(e => e.name)).toEqual(TestHelpers.ALL_FILES);
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("did search order by added date desc", async done => {
|
||||
it("did search order by added date desc", async () => {
|
||||
jest.setTimeout(10000);
|
||||
const user = await TestHelpers.getInstance(platform, true);
|
||||
// given:: all the sample files uploaded and documents for them created
|
||||
@@ -438,16 +458,11 @@ describe("the Drive feature", () => {
|
||||
const options = {
|
||||
sort: {
|
||||
added: "desc",
|
||||
}
|
||||
},
|
||||
};
|
||||
const documents = await user.searchDocument(options);
|
||||
|
||||
//then:: files should be sorted properly
|
||||
expect(documents.entities.map(e => e.name)).toEqual(TestHelpers.ALL_FILES.reverse());
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
@@ -23,6 +23,7 @@ describe("the My Drive feature", () => {
|
||||
size: number;
|
||||
added: string;
|
||||
parent_id: string;
|
||||
is_directory: boolean;
|
||||
}
|
||||
|
||||
class DriveItemDetailsMockClass {
|
||||
@@ -61,12 +62,9 @@ describe("the My Drive feature", () => {
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await platform.tearDown();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await platform.app.close();
|
||||
await platform?.tearDown();
|
||||
platform = null;
|
||||
});
|
||||
|
||||
const createItem = async (): Promise<DriveFileMockClass> => {
|
||||
@@ -84,17 +82,15 @@ describe("the My Drive feature", () => {
|
||||
return deserialize<DriveFileMockClass>(DriveFileMockClass, response.body);
|
||||
};
|
||||
|
||||
it("did create the drive item in my user folder", async done => {
|
||||
it("did create the drive item in my user folder", async () => {
|
||||
const result = await createItem();
|
||||
|
||||
expect(result).toBeDefined();
|
||||
expect(result.name).toEqual("new test file");
|
||||
expect(result.added).toBeDefined();
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("did move an item to root and back", async done => {
|
||||
it("did move an item to root and back", async () => {
|
||||
const createItemResult = await createItem();
|
||||
|
||||
expect(createItemResult.id).toBeDefined();
|
||||
@@ -117,11 +113,9 @@ describe("the My Drive feature", () => {
|
||||
|
||||
expect(createItemResult.id).toEqual(updateItemResult.id);
|
||||
expect(updateItemResult.parent_id).toEqual("user_" + platform.currentUser.id);
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("can't move an item to another user folder", async done => {
|
||||
it("can't move an item to another user folder", async () => {
|
||||
const createItemResult = await createItem();
|
||||
|
||||
expect(createItemResult.id).toBeDefined();
|
||||
@@ -131,7 +125,5 @@ describe("the My Drive feature", () => {
|
||||
});
|
||||
|
||||
expect(updateItemResponse.statusCode).not.toBe(200);
|
||||
|
||||
done?.();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@ describe("the public links feature", () => {
|
||||
id: string;
|
||||
name: string;
|
||||
size: number;
|
||||
added: string;
|
||||
added: number;
|
||||
parent_id: string;
|
||||
company_id: string;
|
||||
access_info: AccessInformation;
|
||||
@@ -56,8 +56,8 @@ describe("the public links feature", () => {
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await platform.tearDown();
|
||||
await platform.app.close();
|
||||
await platform?.tearDown();
|
||||
platform = null;
|
||||
});
|
||||
|
||||
const createItem = async (): Promise<DriveFileMockClass> => {
|
||||
@@ -77,7 +77,7 @@ describe("the public links feature", () => {
|
||||
|
||||
let publicFile: DriveFileMockClass;
|
||||
|
||||
it("did create the drive item", async done => {
|
||||
it("did create the drive item", async () => {
|
||||
const result = await createItem();
|
||||
publicFile = result;
|
||||
|
||||
@@ -85,11 +85,9 @@ describe("the public links feature", () => {
|
||||
expect(result.name).toEqual("public file");
|
||||
expect(result.added).toBeDefined();
|
||||
expect(result.access_info).toBeDefined();
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("unable to access non public file", async done => {
|
||||
it("unable to access non public file", async () => {
|
||||
const res = await platform.app.inject({
|
||||
method: "GET",
|
||||
url: `${url}/companies/${publicFile.company_id}/item/${publicFile.id}?public_token=${publicFile.access_info.public?.token}`,
|
||||
@@ -97,11 +95,9 @@ describe("the public links feature", () => {
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(401);
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("should access public file", async done => {
|
||||
it("should access public file", async () => {
|
||||
const res = await e2e_updateDocument(platform, publicFile.id, {
|
||||
...publicFile,
|
||||
access_info: {
|
||||
@@ -124,11 +120,9 @@ describe("the public links feature", () => {
|
||||
const resPublic = deserialize<DriveItemDetails>(FullDriveInfoMockClass, resPublicRaw.body);
|
||||
expect(resPublicRaw.statusCode).toBe(200);
|
||||
expect(resPublic.item?.id).toBe(publicFile.id);
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("unable to access expired public file link", async done => {
|
||||
it("unable to access expired public file link", async () => {
|
||||
await e2e_updateDocument(platform, publicFile.id, {
|
||||
...publicFile,
|
||||
access_info: {
|
||||
@@ -180,11 +174,9 @@ describe("the public links feature", () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
done?.();
|
||||
});
|
||||
|
||||
it("access public file link with password", async done => {
|
||||
it("access public file link with password", async () => {
|
||||
await e2e_updateDocument(platform, publicFile.id, {
|
||||
...publicFile,
|
||||
access_info: {
|
||||
@@ -199,9 +191,7 @@ describe("the public links feature", () => {
|
||||
|
||||
let resPublicRaw = await platform.app.inject({
|
||||
method: "GET",
|
||||
url: `${url}/companies/${publicFile.company_id}/item/${publicFile.id}?public_token=${
|
||||
publicFile.access_info.public?.token
|
||||
}%2B${"abcdef"}`,
|
||||
url: `${url}/companies/${publicFile.company_id}/item/${publicFile.id}?public_token=${publicFile.access_info.public?.token}%2Babcdef`,
|
||||
headers: {},
|
||||
});
|
||||
let resPublic = deserialize<DriveItemDetails>(FullDriveInfoMockClass, resPublicRaw.body);
|
||||
@@ -226,7 +216,5 @@ describe("the public links feature", () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
done?.();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,10 +21,10 @@ describe("The Files feature", () => {
|
||||
helpers = await TestHelpers.getInstance(platform)
|
||||
});
|
||||
|
||||
afterAll(async done => {
|
||||
afterAll(async () => {
|
||||
await platform?.tearDown();
|
||||
platform = null;
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
describe("On user send files", () => {
|
||||
@@ -67,8 +67,7 @@ describe("The Files feature", () => {
|
||||
|
||||
}, 120000);
|
||||
|
||||
|
||||
it.skip("should save file and generate previews", async done => {
|
||||
it.skip("should save file and generate previews", async () => {
|
||||
for (const i in TestHelpers.ALL_FILES) {
|
||||
const file = TestHelpers.ALL_FILES[i];
|
||||
|
||||
@@ -88,7 +87,7 @@ describe("The Files feature", () => {
|
||||
}
|
||||
}
|
||||
|
||||
done();
|
||||
|
||||
}, 1200000);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,6 +26,7 @@ type TokenPayload = {
|
||||
|
||||
export type User = {
|
||||
id: string;
|
||||
first_name?: string;
|
||||
isWorkspaceModerator?: boolean;
|
||||
};
|
||||
|
||||
|
||||
@@ -16,15 +16,14 @@ describe("The Tag feature", () => {
|
||||
let testDbService: TestDbService;
|
||||
const tagIds: string[] = [];
|
||||
|
||||
beforeAll(async ends => {
|
||||
beforeAll(async () => {
|
||||
platform = await init({
|
||||
services: ["webserver", "database", "storage", "message-queue", "tags"],
|
||||
});
|
||||
testDbService = await TestDbService.getInstance(platform, true);
|
||||
ends();
|
||||
});
|
||||
|
||||
afterAll(async done => {
|
||||
afterAll(async () => {
|
||||
for (let i = 0; i < tagIds.length; i++) {
|
||||
for (let j = 0; j < tagIds.length; j++) {
|
||||
if (tagIds[j] === tagIds[i] && j !== i) {
|
||||
@@ -34,11 +33,10 @@ describe("The Tag feature", () => {
|
||||
}
|
||||
await platform?.tearDown();
|
||||
platform = null;
|
||||
done();
|
||||
});
|
||||
|
||||
describe("Create tag", () => {
|
||||
it("should 201 if creator is a company admin", async done => {
|
||||
it("should 201 if creator is a company admin", async () => {
|
||||
const user = await testDbService.createUser([testDbService.defaultWorkspace()], {
|
||||
companyRole: "admin",
|
||||
});
|
||||
@@ -80,10 +78,9 @@ describe("The Tag feature", () => {
|
||||
|
||||
tagIds.push(tagResult.resource.tag_id);
|
||||
}
|
||||
done();
|
||||
});
|
||||
|
||||
it("should 401 if creator is not a company admin", async done => {
|
||||
it("should 401 if creator is not a company admin", async () => {
|
||||
const user = await testDbService.createUser([testDbService.defaultWorkspace()], {
|
||||
companyRole: "member",
|
||||
});
|
||||
@@ -106,12 +103,11 @@ describe("The Tag feature", () => {
|
||||
createTag.body,
|
||||
);
|
||||
expect(tagResult.resource).toBe(undefined);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Get tag", () => {
|
||||
it("should 200 get a tag", async done => {
|
||||
it("should 200 get a tag", async () => {
|
||||
const user = await testDbService.createUser([testDbService.defaultWorkspace()], {
|
||||
companyRole: "member",
|
||||
});
|
||||
@@ -131,10 +127,10 @@ describe("The Tag feature", () => {
|
||||
expect(getResult.resource.colour).toBe("#000000");
|
||||
expect(getResult.resource.company_id).toBe(platform.workspace.company_id);
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 200 tag does not exist", async done => {
|
||||
it("should 200 tag does not exist", async () => {
|
||||
const user = await testDbService.createUser([testDbService.defaultWorkspace()], {
|
||||
companyRole: "member",
|
||||
});
|
||||
@@ -151,12 +147,12 @@ describe("The Tag feature", () => {
|
||||
const getResult: ResourceGetResponse<Tag> = deserialize(ResourceGetResponse, getTag.body);
|
||||
expect(getResult.resource).toBe(null);
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe("Update tag", () => {
|
||||
it("Should 204 if user is admin", async done => {
|
||||
it("Should 204 if user is admin", async () => {
|
||||
const user = await testDbService.createUser([testDbService.defaultWorkspace()], {
|
||||
companyRole: "admin",
|
||||
});
|
||||
@@ -193,10 +189,10 @@ describe("The Tag feature", () => {
|
||||
});
|
||||
expect(getUpdatedTag.statusCode).toBe(200);
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 401 if creator is not a company admin", async done => {
|
||||
it("should 401 if creator is not a company admin", async () => {
|
||||
const user = await testDbService.createUser([testDbService.defaultWorkspace()], {
|
||||
companyRole: "member",
|
||||
});
|
||||
@@ -221,12 +217,12 @@ describe("The Tag feature", () => {
|
||||
console.log("tagResult2", tagResult, jwtToken);
|
||||
expect(tagResult.resource).toBe(undefined);
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe("List tags", () => {
|
||||
it("should 200 list a tag", async done => {
|
||||
it("should 200 list a tag", async () => {
|
||||
const user = await testDbService.createUser([testDbService.defaultWorkspace()], {
|
||||
companyRole: "member",
|
||||
});
|
||||
@@ -249,12 +245,12 @@ describe("The Tag feature", () => {
|
||||
expect(tag.tag_id).toBeDefined();
|
||||
}
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe("Delete tag", () => {
|
||||
it("should 200 if admin delete a tag", async done => {
|
||||
it("should 200 if admin delete a tag", async () => {
|
||||
const user = await testDbService.createUser([testDbService.defaultWorkspace()], {
|
||||
companyRole: "admin",
|
||||
});
|
||||
@@ -268,10 +264,10 @@ describe("The Tag feature", () => {
|
||||
});
|
||||
expect(deleteTag.statusCode).toBe(200);
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 200 if tag does not exist", async done => {
|
||||
it("should 200 if tag does not exist", async () => {
|
||||
const user = await testDbService.createUser([testDbService.defaultWorkspace()], {
|
||||
companyRole: "admin",
|
||||
});
|
||||
@@ -284,10 +280,10 @@ describe("The Tag feature", () => {
|
||||
},
|
||||
});
|
||||
expect(deleteTag.statusCode).toBe(200);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 401 if not admin", async done => {
|
||||
it("should 401 if not admin", async () => {
|
||||
const user = await testDbService.createUser([testDbService.defaultWorkspace()], {
|
||||
companyRole: "member",
|
||||
});
|
||||
@@ -300,7 +296,7 @@ describe("The Tag feature", () => {
|
||||
},
|
||||
});
|
||||
expect(deleteTag.statusCode).toBe(401);
|
||||
done();
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@ describe("The /users API", () => {
|
||||
const url = "/internal/services/users/v1";
|
||||
let platform: TestPlatform;
|
||||
|
||||
beforeEach(async ends => {
|
||||
beforeEach(async () => {
|
||||
platform = await init({
|
||||
services: [
|
||||
"database",
|
||||
@@ -26,17 +26,15 @@ describe("The /users API", () => {
|
||||
"platform-services",
|
||||
],
|
||||
});
|
||||
ends();
|
||||
});
|
||||
|
||||
afterEach(async ends => {
|
||||
afterEach(async () => {
|
||||
platform && (await platform.tearDown());
|
||||
platform = null;
|
||||
ends();
|
||||
});
|
||||
|
||||
describe("The GET /users/?search=... route", () => {
|
||||
it("Should find the searched users", async done => {
|
||||
it("Should find the searched users", async () => {
|
||||
const testDbService = new TestDbService(platform);
|
||||
await testDbService.createCompany(platform.workspace.company_id);
|
||||
const workspacePk = {
|
||||
@@ -122,7 +120,6 @@ describe("The /users API", () => {
|
||||
resources = await search("rbs@tdrive.app", uuidv1());
|
||||
expect(resources.length).toBe(0);
|
||||
|
||||
done();
|
||||
}, 1200000);
|
||||
});
|
||||
|
||||
|
||||
@@ -12,17 +12,15 @@ describe("The /users API", () => {
|
||||
|
||||
const nonExistentId = uuidv1();
|
||||
|
||||
beforeEach(async ends => {
|
||||
beforeEach(async () => {
|
||||
platform = await init();
|
||||
ends();
|
||||
});
|
||||
afterEach(async ends => {
|
||||
afterEach(async () => {
|
||||
await platform.tearDown();
|
||||
platform = null;
|
||||
ends();
|
||||
});
|
||||
|
||||
beforeAll(async ends => {
|
||||
beforeAll(async () => {
|
||||
const platform = await init({
|
||||
services: [
|
||||
"database",
|
||||
@@ -55,25 +53,22 @@ describe("The /users API", () => {
|
||||
});
|
||||
await testDbService.createUser([workspacePk]);
|
||||
|
||||
ends();
|
||||
});
|
||||
|
||||
afterAll(async ends => {
|
||||
ends();
|
||||
afterAll(async () => {
|
||||
});
|
||||
|
||||
describe("The GET /users/:id route", () => {
|
||||
it("should 401 when not authenticated", async done => {
|
||||
it("should 401 when not authenticated", async () => {
|
||||
const response = await platform.app.inject({
|
||||
method: "GET",
|
||||
url: `${url}/users/1`,
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(401);
|
||||
done();
|
||||
});
|
||||
|
||||
it("should 404 when user does not exists", async done => {
|
||||
it("should 404 when user does not exists", async () => {
|
||||
const jwtToken = await platform.auth.getJWTToken({ sub: testDbService.users[0].id });
|
||||
const response = await platform.app.inject({
|
||||
method: "GET",
|
||||
@@ -89,10 +84,9 @@ describe("The /users API", () => {
|
||||
message: `User ${nonExistentId} not found`,
|
||||
statusCode: 404,
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
it("should 200 and big response for myself", async done => {
|
||||
it("should 200 and big response for myself", async () => {
|
||||
const myId = testDbService.users[0].id;
|
||||
const jwtToken = await platform.auth.getJWTToken({ sub: myId });
|
||||
const response = await platform.app.inject({
|
||||
@@ -143,10 +137,9 @@ describe("The /users API", () => {
|
||||
]),
|
||||
);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it("should 200 and short response for another user", async done => {
|
||||
it("should 200 and short response for another user", async () => {
|
||||
const myId = testDbService.users[0].id;
|
||||
const anotherUserId = testDbService.users[1].id;
|
||||
|
||||
@@ -183,23 +176,20 @@ describe("The /users API", () => {
|
||||
timezone: expect.anything(),
|
||||
companies: expect.anything(),
|
||||
});
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe("The GET /users route", () => {
|
||||
it("should 401 when user is not authenticated", async done => {
|
||||
it("should 401 when user is not authenticated", async () => {
|
||||
const response = await platform.app.inject({
|
||||
method: "GET",
|
||||
url: `${url}/users`,
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(401);
|
||||
done();
|
||||
});
|
||||
|
||||
it("should 200 with array of users", async done => {
|
||||
it("should 200 with array of users", async () => {
|
||||
const myId = testDbService.users[0].id;
|
||||
const anotherUserId = testDbService.users[1].id;
|
||||
|
||||
@@ -220,23 +210,20 @@ describe("The /users API", () => {
|
||||
const json = response.json();
|
||||
expect(json).toMatchObject({ resources: expect.any(Array) });
|
||||
const resources = json.resources;
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe("The GET /users/:user_id/companies route", () => {
|
||||
it("should 401 when not authenticated", async done => {
|
||||
it("should 401 when not authenticated", async () => {
|
||||
const response = await platform.app.inject({
|
||||
method: "GET",
|
||||
url: `${url}/users/1/companies`,
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(401);
|
||||
done();
|
||||
});
|
||||
|
||||
it("should 404 when user does not exists", async done => {
|
||||
it("should 404 when user does not exists", async () => {
|
||||
const jwtToken = await platform.auth.getJWTToken({ sub: testDbService.users[0].id });
|
||||
const response = await platform.app.inject({
|
||||
method: "GET",
|
||||
@@ -252,10 +239,9 @@ describe("The /users API", () => {
|
||||
message: `User ${nonExistentId} not found`,
|
||||
statusCode: 404,
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
it("should 200 and on correct request", async done => {
|
||||
it("should 200 and on correct request", async () => {
|
||||
const myId = testDbService.users[0].id;
|
||||
const anotherUserId = testDbService.users[1].id;
|
||||
|
||||
@@ -299,21 +285,19 @@ describe("The /users API", () => {
|
||||
});
|
||||
}
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe("The GET /companies/:company_id route", () => {
|
||||
it("should 404 when company does not exists", async done => {
|
||||
it("should 404 when company does not exists", async () => {
|
||||
const response = await platform.app.inject({
|
||||
method: "GET",
|
||||
url: `${url}/companies/11111111-1111-1111-1111-111111111111`,
|
||||
});
|
||||
expect(response.statusCode).toBe(404);
|
||||
done();
|
||||
});
|
||||
|
||||
it("should 200 when company exists", async done => {
|
||||
it("should 200 when company exists", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
|
||||
const response = await platform.app.inject({
|
||||
@@ -347,7 +331,6 @@ describe("The /users API", () => {
|
||||
total_messages: expect.any(Number),
|
||||
});
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -355,7 +338,7 @@ describe("The /users API", () => {
|
||||
const deviceToken = "testDeviceToken";
|
||||
|
||||
describe("Register device (POST)", () => {
|
||||
it("should 400 when type is not FCM", async done => {
|
||||
it("should 400 when type is not FCM", async () => {
|
||||
const myId = testDbService.users[0].id;
|
||||
|
||||
const jwtToken = await platform.auth.getJWTToken({ sub: myId });
|
||||
@@ -381,10 +364,9 @@ describe("The /users API", () => {
|
||||
error: "Bad Request",
|
||||
message: "Type should be FCM only",
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
it("should 200 when ok", async done => {
|
||||
it("should 200 when ok", async () => {
|
||||
const firstId = testDbService.users[0].id;
|
||||
|
||||
const jwtToken = await platform.auth.getJWTToken({ sub: firstId });
|
||||
@@ -413,7 +395,7 @@ describe("The /users API", () => {
|
||||
});
|
||||
|
||||
const user = await testDbService.getUserFromDb({ id: firstId });
|
||||
expect(user.devices).toMatchObject([deviceToken]);
|
||||
expect(user.devices).toEqual([deviceToken]);
|
||||
const device = await testDbService.getDeviceFromDb(deviceToken);
|
||||
expect(device).toMatchObject({
|
||||
id: deviceToken,
|
||||
@@ -421,11 +403,9 @@ describe("The /users API", () => {
|
||||
type: "FCM",
|
||||
version: "1",
|
||||
});
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it("should 200 when register token to another person", async done => {
|
||||
it("should 200 when register token to another person", async () => {
|
||||
const firstId = testDbService.users[0].id;
|
||||
const secondId = testDbService.users[1].id;
|
||||
|
||||
@@ -456,7 +436,7 @@ describe("The /users API", () => {
|
||||
|
||||
// second user should have now this token
|
||||
let user = await testDbService.getUserFromDb({ id: secondId });
|
||||
expect(user.devices).toMatchObject([deviceToken]);
|
||||
expect(user.devices).toEqual([deviceToken]);
|
||||
const device = await testDbService.getDeviceFromDb(deviceToken);
|
||||
expect(device).toMatchObject({
|
||||
id: deviceToken,
|
||||
@@ -470,11 +450,10 @@ describe("The /users API", () => {
|
||||
user = await testDbService.getUserFromDb({ id: firstId });
|
||||
expect(user.devices).toMatchObject([]);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
describe("List registered devices (GET)", () => {
|
||||
it("should 200 when request devices", async done => {
|
||||
it("should 200 when request devices", async () => {
|
||||
const myId = testDbService.users[1].id;
|
||||
|
||||
const jwtToken = await platform.auth.getJWTToken({ sub: myId });
|
||||
@@ -497,12 +476,11 @@ describe("The /users API", () => {
|
||||
},
|
||||
],
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe("De-register device (DELETE)", () => {
|
||||
it("should 200 when device not found for the user", async done => {
|
||||
it("should 200 when device not found for the user", async () => {
|
||||
const myId = testDbService.users[1].id;
|
||||
|
||||
const jwtToken = await platform.auth.getJWTToken({ sub: myId });
|
||||
@@ -516,7 +494,7 @@ describe("The /users API", () => {
|
||||
expect(response.statusCode).toBe(204);
|
||||
|
||||
const user = await testDbService.getUserFromDb({ id: myId });
|
||||
expect(user.devices).toMatchObject([deviceToken]);
|
||||
expect(user.devices).toEqual([deviceToken]);
|
||||
const device = await testDbService.getDeviceFromDb(deviceToken);
|
||||
expect(device).toMatchObject({
|
||||
id: deviceToken,
|
||||
@@ -524,11 +502,9 @@ describe("The /users API", () => {
|
||||
type: "FCM",
|
||||
version: "1",
|
||||
});
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it("should 200 when device found and device should be removed", async done => {
|
||||
it("should 200 when device found and device should be removed", async () => {
|
||||
const myId = testDbService.users[1].id;
|
||||
|
||||
const jwtToken = await platform.auth.getJWTToken({ sub: myId });
|
||||
@@ -546,7 +522,6 @@ describe("The /users API", () => {
|
||||
const device = await testDbService.getDeviceFromDb(deviceToken);
|
||||
expect(device).toBeFalsy();
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -37,7 +37,7 @@ describe("The /workspace users API", () => {
|
||||
});
|
||||
};
|
||||
|
||||
beforeAll(async ends => {
|
||||
beforeAll(async () => {
|
||||
platform = await init({
|
||||
services: [
|
||||
"database",
|
||||
@@ -76,16 +76,14 @@ describe("The /workspace users API", () => {
|
||||
await testDbService.createUser([ws2pk], { workspaceRole: "member" });
|
||||
await testDbService.createUser([], { companyRole: "member" });
|
||||
await testDbService.createUser([ws3pk], { companyRole: "guest", workspaceRole: "member" });
|
||||
ends();
|
||||
});
|
||||
|
||||
afterAll(async ends => {
|
||||
afterAll(async () => {
|
||||
await platform.tearDown();
|
||||
ends();
|
||||
});
|
||||
|
||||
describe("The GET /workspaces/users route", () => {
|
||||
it("should 401 when not authenticated", async done => {
|
||||
it("should 401 when not authenticated", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
|
||||
const response = await platform.app.inject({
|
||||
@@ -93,10 +91,10 @@ describe("The /workspace users API", () => {
|
||||
url: `${url}/companies/${companyId}/workspaces/${nonExistentId}/users`,
|
||||
});
|
||||
expect(response.statusCode).toBe(401);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 404 when workspace not found", async done => {
|
||||
it("should 404 when workspace not found", async () => {
|
||||
const userId = testDbService.users[0].id;
|
||||
|
||||
const jwtToken = await platform.auth.getJWTToken({ sub: userId });
|
||||
@@ -107,10 +105,10 @@ describe("The /workspace users API", () => {
|
||||
headers: { authorization: `Bearer ${jwtToken}` },
|
||||
});
|
||||
expect(response.statusCode).toBe(404);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 200 when ok", async done => {
|
||||
it("should 200 when ok", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
const workspaceId = testDbService.workspaces[2].workspace.id;
|
||||
const userId = testDbService.workspaces[2].users[0].id;
|
||||
@@ -131,12 +129,12 @@ describe("The /workspace users API", () => {
|
||||
checkUserObject(resource);
|
||||
}
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe("The GET /workspaces/users/:user_id route", () => {
|
||||
it("should 401 when not authenticated", async done => {
|
||||
it("should 401 when not authenticated", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
const userId = testDbService.users[0].id;
|
||||
|
||||
@@ -145,10 +143,10 @@ describe("The /workspace users API", () => {
|
||||
url: `${url}/companies/${companyId}/workspaces/${nonExistentId}/users/${userId}`,
|
||||
});
|
||||
expect(response.statusCode).toBe(401);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 404 when workspace not found", async done => {
|
||||
it("should 404 when workspace not found", async () => {
|
||||
const userId = testDbService.users[0].id;
|
||||
|
||||
const jwtToken = await platform.auth.getJWTToken({ sub: userId });
|
||||
@@ -159,10 +157,10 @@ describe("The /workspace users API", () => {
|
||||
headers: { authorization: `Bearer ${jwtToken}` },
|
||||
});
|
||||
expect(response.statusCode).toBe(404);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 200 when ok", async done => {
|
||||
it("should 200 when ok", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
const workspaceId = testDbService.workspaces[0].workspace.id;
|
||||
const userId = testDbService.workspaces[0].users[0].id;
|
||||
@@ -177,12 +175,12 @@ describe("The /workspace users API", () => {
|
||||
|
||||
const resource = response.json()["resource"];
|
||||
checkUserObject(resource);
|
||||
done();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe("The POST /workspaces/users route (add)", () => {
|
||||
it("should 401 when not authenticated", async done => {
|
||||
it("should 401 when not authenticated", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
|
||||
const response = await platform.app.inject({
|
||||
@@ -190,10 +188,10 @@ describe("The /workspace users API", () => {
|
||||
url: `${url}/companies/${companyId}/workspaces/${nonExistentId}/users`,
|
||||
});
|
||||
expect(response.statusCode).toBe(401);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 403 user is not workspace moderator", async done => {
|
||||
it("should 403 user is not workspace moderator", async () => {
|
||||
const userId = testDbService.users[0].id;
|
||||
const anotherUserId = testDbService.users[1].id;
|
||||
const workspaceId = testDbService.workspaces[0].workspace.id;
|
||||
@@ -212,10 +210,10 @@ describe("The /workspace users API", () => {
|
||||
},
|
||||
});
|
||||
expect(response.statusCode).toBe(403);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 400 when requested user not in company", async done => {
|
||||
it("should 400 when requested user not in company", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
const workspaceId = testDbService.workspaces[2].workspace.id;
|
||||
const userId = testDbService.workspaces[2].users[1].id;
|
||||
@@ -233,10 +231,10 @@ describe("The /workspace users API", () => {
|
||||
},
|
||||
});
|
||||
expect(response.statusCode).toBe(400);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 201 when requested already in workspace (ignore)", async done => {
|
||||
it("should 201 when requested already in workspace (ignore)", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
const workspaceId = testDbService.workspaces[2].workspace.id;
|
||||
const userId = testDbService.workspaces[2].users[1].id;
|
||||
@@ -254,10 +252,10 @@ describe("The /workspace users API", () => {
|
||||
},
|
||||
});
|
||||
expect(response.statusCode).toBe(201);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 200 when ok", async done => {
|
||||
it("should 200 when ok", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
const workspaceId = testDbService.workspaces[2].workspace.id;
|
||||
const userId = testDbService.workspaces[2].users[1].id;
|
||||
@@ -290,12 +288,12 @@ describe("The /workspace users API", () => {
|
||||
|
||||
workspaceUsersCount = await testDbService.getWorkspaceUsersCountFromDb(workspaceId);
|
||||
expect(workspaceUsersCount).toBe(5);
|
||||
done();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe("The POST /workspaces/users/:user_id route (update)", () => {
|
||||
it("should 401 when not authenticated", async done => {
|
||||
it("should 401 when not authenticated", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
const userId = testDbService.users[0].id;
|
||||
|
||||
@@ -304,10 +302,10 @@ describe("The /workspace users API", () => {
|
||||
url: `${url}/companies/${companyId}/workspaces/${nonExistentId}/users/${userId}`,
|
||||
});
|
||||
expect(response.statusCode).toBe(401);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 403 user is not workspace moderator", async done => {
|
||||
it("should 403 user is not workspace moderator", async () => {
|
||||
const userId = testDbService.users[0].id;
|
||||
const anotherUserId = testDbService.users[1].id;
|
||||
const workspaceId = testDbService.workspaces[0].workspace.id;
|
||||
@@ -326,10 +324,10 @@ describe("The /workspace users API", () => {
|
||||
},
|
||||
});
|
||||
expect(response.statusCode).toBe(403);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 404 when user not found in workspace", async done => {
|
||||
it("should 404 when user not found in workspace", async () => {
|
||||
const workspaceId = testDbService.workspaces[2].workspace.id;
|
||||
const userId = testDbService.workspaces[2].users[1].id;
|
||||
const anotherWorkspaceUserId = testDbService.workspaces[3].users[0].id;
|
||||
@@ -347,10 +345,10 @@ describe("The /workspace users API", () => {
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(404);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 200 when ok", async done => {
|
||||
it("should 200 when ok", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
const workspaceId = testDbService.workspaces[2].workspace.id;
|
||||
const userId = testDbService.workspaces[2].users[1].id;
|
||||
@@ -377,12 +375,12 @@ describe("The /workspace users API", () => {
|
||||
const usersCount = await testDbService.getWorkspaceUsersCountFromDb(workspaceId);
|
||||
expect(usersCount).toBe(5);
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe("The DELETE /workspaces/users/:user_id route", () => {
|
||||
it("should 401 when not authenticated", async done => {
|
||||
it("should 401 when not authenticated", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
const anotherUserId = testDbService.users[1].id;
|
||||
|
||||
@@ -391,10 +389,10 @@ describe("The /workspace users API", () => {
|
||||
url: `${url}/companies/${companyId}/workspaces/${nonExistentId}/users/${anotherUserId}`,
|
||||
});
|
||||
expect(response.statusCode).toBe(401);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 403 user is not workspace moderator", async done => {
|
||||
it("should 403 user is not workspace moderator", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
const workspaceId = testDbService.workspaces[2].workspace.id;
|
||||
const userId = testDbService.workspaces[2].users[3].id;
|
||||
@@ -411,10 +409,10 @@ describe("The /workspace users API", () => {
|
||||
console.log(response.body);
|
||||
|
||||
expect(response.statusCode).toBe(403);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 404 when user not found in workspace", async done => {
|
||||
it("should 404 when user not found in workspace", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
const workspaceId = testDbService.workspaces[2].workspace.id;
|
||||
const userId = testDbService.workspaces[2].users[1].id;
|
||||
@@ -428,10 +426,10 @@ describe("The /workspace users API", () => {
|
||||
|
||||
expect(response.statusCode).toBe(404);
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 200 when ok", async done => {
|
||||
it("should 200 when ok", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
const workspaceId = testDbService.workspaces[2].workspace.id;
|
||||
const userId = testDbService.workspaces[2].users[1].id;
|
||||
@@ -459,7 +457,7 @@ describe("The /workspace users API", () => {
|
||||
const usersCount = await testDbService.getWorkspaceUsersCountFromDb(workspaceId);
|
||||
expect(usersCount).toBe(4);
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,7 +12,7 @@ describe("The /workspaces API", () => {
|
||||
const nonExistentId = uuidv1();
|
||||
let companyId = "";
|
||||
|
||||
beforeAll(async ends => {
|
||||
beforeAll(async () => {
|
||||
platform = await init({
|
||||
services: [
|
||||
"database",
|
||||
@@ -46,25 +46,22 @@ describe("The /workspaces API", () => {
|
||||
await testDbService.createUser([ws2pk], { companyRole: "admin" });
|
||||
await testDbService.createUser([ws2pk], { companyRole: undefined, workspaceRole: "moderator" });
|
||||
await testDbService.createUser([], { companyRole: "guest" });
|
||||
ends();
|
||||
});
|
||||
|
||||
afterAll(async ends => {
|
||||
afterAll(async () => {
|
||||
await platform.tearDown();
|
||||
ends();
|
||||
});
|
||||
|
||||
describe("The GET /workspaces/ route", () => {
|
||||
it("should 401 when not authenticated", async done => {
|
||||
it("should 401 when not authenticated", async () => {
|
||||
const response = await platform.app.inject({
|
||||
method: "GET",
|
||||
url: `${url}/companies/${nonExistentId}/workspaces`,
|
||||
});
|
||||
expect(response.statusCode).toBe(401);
|
||||
done();
|
||||
});
|
||||
|
||||
it("should 404 when company not found", async done => {
|
||||
it("should 404 when company not found", async () => {
|
||||
const userId = testDbService.workspaces[0].users[0].id;
|
||||
|
||||
const jwtToken = await platform.auth.getJWTToken({ sub: userId });
|
||||
@@ -75,10 +72,9 @@ describe("The /workspaces API", () => {
|
||||
headers: { authorization: `Bearer ${jwtToken}` },
|
||||
});
|
||||
expect(response.statusCode).toBe(404);
|
||||
done();
|
||||
});
|
||||
|
||||
it("should 200 when company belongs to user", async done => {
|
||||
it("should 200 when company belongs to user", async () => {
|
||||
const userId = testDbService.workspaces[0].users[0].id;
|
||||
|
||||
const jwtToken = await platform.auth.getJWTToken({ sub: userId });
|
||||
@@ -113,12 +109,12 @@ describe("The /workspaces API", () => {
|
||||
}
|
||||
}
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe("The GET /workspaces/:workspace_id route", () => {
|
||||
it("should 401 when not authenticated", async done => {
|
||||
it("should 401 when not authenticated", async () => {
|
||||
const workspaceId = testDbService.workspaces[0].workspace.id;
|
||||
|
||||
const response = await platform.app.inject({
|
||||
@@ -126,10 +122,10 @@ describe("The /workspaces API", () => {
|
||||
url: `${url}/companies/${nonExistentId}/workspaces/${workspaceId}`,
|
||||
});
|
||||
expect(response.statusCode).toBe(401);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 404 when workspace not found", async done => {
|
||||
it("should 404 when workspace not found", async () => {
|
||||
const userId = testDbService.workspaces[0].users[0].id;
|
||||
const jwtToken = await platform.auth.getJWTToken({ sub: userId });
|
||||
|
||||
@@ -139,10 +135,10 @@ describe("The /workspaces API", () => {
|
||||
headers: { authorization: `Bearer ${jwtToken}` },
|
||||
});
|
||||
expect(response.statusCode).toBe(404);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 403 when user not belong to workspace and not company_admin", async done => {
|
||||
it("should 403 when user not belong to workspace and not company_admin", async () => {
|
||||
const workspaceId = testDbService.workspaces[2].workspace.id;
|
||||
const userIdFromAnotherWorkspace = testDbService.workspaces[0].users[0].id;
|
||||
|
||||
@@ -161,10 +157,10 @@ describe("The /workspaces API", () => {
|
||||
statusCode: 403,
|
||||
});
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 200 when user is company_admin", async done => {
|
||||
it("should 200 when user is company_admin", async () => {
|
||||
const workspaceId = testDbService.workspaces[0].workspace.id;
|
||||
const userIdFromAnotherWorkspace = testDbService.workspaces[2].users[0].id;
|
||||
|
||||
@@ -195,10 +191,10 @@ describe("The /workspaces API", () => {
|
||||
});
|
||||
}
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 200 when user is belong to workspace", async done => {
|
||||
it("should 200 when user is belong to workspace", async () => {
|
||||
const workspaceId = testDbService.workspaces[0].workspace.id;
|
||||
const userIdFromThisWorkspace = testDbService.workspaces[0].users[0].id;
|
||||
|
||||
@@ -230,14 +226,14 @@ describe("The /workspaces API", () => {
|
||||
});
|
||||
}
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
// create
|
||||
|
||||
describe("The POST /workspaces route (creating workspace)", () => {
|
||||
it("should 401 when not authenticated", async done => {
|
||||
it("should 401 when not authenticated", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
|
||||
const response = await platform.app.inject({
|
||||
@@ -245,10 +241,10 @@ describe("The /workspaces API", () => {
|
||||
url: `${url}/companies/${companyId}/workspaces/${nonExistentId}`,
|
||||
});
|
||||
expect(response.statusCode).toBe(401);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 403 when user is not (company member or company admin) ", async done => {
|
||||
it("should 403 when user is not (company member or company admin) ", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
const userId = testDbService.users[3].id;
|
||||
const jwtToken = await platform.auth.getJWTToken({ sub: userId });
|
||||
@@ -267,10 +263,10 @@ describe("The /workspaces API", () => {
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(403);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 201 when workspace created well", async done => {
|
||||
it("should 201 when workspace created well", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
const userId = testDbService.users[0].id;
|
||||
const jwtToken = await platform.auth.getJWTToken({ sub: userId });
|
||||
@@ -302,14 +298,14 @@ describe("The /workspaces API", () => {
|
||||
role: expect.stringMatching(/moderator/),
|
||||
});
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
// update
|
||||
|
||||
describe("The POST /workspaces/:workspace_id route (updating workspace)", () => {
|
||||
it("should 401 when not authenticated", async done => {
|
||||
it("should 401 when not authenticated", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
|
||||
const response = await platform.app.inject({
|
||||
@@ -318,10 +314,10 @@ describe("The /workspaces API", () => {
|
||||
payload: { resource: {} },
|
||||
});
|
||||
expect(response.statusCode).toBe(401);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 403 when not workspace not found", async done => {
|
||||
it("should 403 when not workspace not found", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
const userId = testDbService.workspaces[0].users[0].id;
|
||||
|
||||
@@ -336,10 +332,10 @@ describe("The /workspaces API", () => {
|
||||
|
||||
expect(response.statusCode).toBe(403);
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 403 when not belong to workspace", async done => {
|
||||
it("should 403 when not belong to workspace", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
const workspaceId = testDbService.workspaces[1].workspace.id;
|
||||
const userId = testDbService.workspaces[0].users[0].id;
|
||||
@@ -355,10 +351,10 @@ describe("The /workspaces API", () => {
|
||||
|
||||
expect(response.statusCode).toBe(403);
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 403 when not workspace moderator", async done => {
|
||||
it("should 403 when not workspace moderator", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
const workspaceId = testDbService.workspaces[1].workspace.id;
|
||||
const userId = testDbService.workspaces[0].users[0].id;
|
||||
@@ -374,10 +370,10 @@ describe("The /workspaces API", () => {
|
||||
|
||||
expect(response.statusCode).toBe(403);
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 200 when admin of company (full update)", async done => {
|
||||
it("should 200 when admin of company (full update)", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
const workspaceId = testDbService.workspaces[2].workspace.id;
|
||||
const userId = testDbService.workspaces[2].users[0].id; // company owner
|
||||
@@ -412,10 +408,10 @@ describe("The /workspaces API", () => {
|
||||
role: "moderator", //Company admin is a moderator
|
||||
});
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 200 when moderator of workspace (partial update)", async done => {
|
||||
it("should 200 when moderator of workspace (partial update)", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
const workspaceId = testDbService.workspaces[2].workspace.id;
|
||||
const userId = testDbService.workspaces[2].users[1].id; // workspace admin
|
||||
@@ -449,14 +445,14 @@ describe("The /workspaces API", () => {
|
||||
role: "moderator",
|
||||
});
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
// delete
|
||||
|
||||
describe("The DELETE /workspaces route", () => {
|
||||
it("should 401 when not authenticated", async done => {
|
||||
it("should 401 when not authenticated", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
|
||||
const response = await platform.app.inject({
|
||||
@@ -464,10 +460,10 @@ describe("The /workspaces API", () => {
|
||||
url: `${url}/companies/${companyId}/workspaces/${nonExistentId}`,
|
||||
});
|
||||
expect(response.statusCode).toBe(401);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 403 when user is not (company member or company admin) ", async done => {
|
||||
it("should 403 when user is not (company member or company admin) ", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
const userId = testDbService.users[3].id;
|
||||
const jwtToken = await platform.auth.getJWTToken({ sub: userId });
|
||||
@@ -480,10 +476,10 @@ describe("The /workspaces API", () => {
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(403);
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should 204 when workspace deleted", async done => {
|
||||
it("should 204 when workspace deleted", async () => {
|
||||
const companyId = testDbService.company.id;
|
||||
const workspaceId = testDbService.workspaces[2].workspace.id;
|
||||
const userId = testDbService.workspaces[2].users[0].id;
|
||||
@@ -507,7 +503,7 @@ describe("The /workspaces API", () => {
|
||||
|
||||
expect(checkResponseJson.resources.find((a: any) => a.id === workspaceId)).toBe(undefined);
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+6
-6
@@ -5,7 +5,7 @@ import { websocketEventBus } from "../../../../../../../src/core/platform/servic
|
||||
import { ResourcePath } from "../../../../../../../src/core/platform/services/realtime/types";
|
||||
|
||||
describe("The RealtimeCreated decorator", () => {
|
||||
it("should call the original method send back original result but do not emit event if result type is wrong", async done => {
|
||||
it("should call the original method send back original result but do not emit event if result type is wrong", async () => {
|
||||
const emitSpy = jest.spyOn(websocketEventBus, "emit");
|
||||
|
||||
class TestMe {
|
||||
@@ -27,10 +27,10 @@ describe("The RealtimeCreated decorator", () => {
|
||||
expect(emitSpy).toHaveBeenCalledTimes(0);
|
||||
|
||||
emitSpy.mockRestore();
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should call the original method send back original result and emit event", async done => {
|
||||
it("should call the original method send back original result and emit event", async () => {
|
||||
const emitSpy = jest.spyOn(websocketEventBus, "emit");
|
||||
|
||||
class TestMe {
|
||||
@@ -68,10 +68,10 @@ describe("The RealtimeCreated decorator", () => {
|
||||
});
|
||||
|
||||
emitSpy.mockRestore();
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should emit event with path computed from function", async done => {
|
||||
it("should emit event with path computed from function", async () => {
|
||||
const emitSpy = jest.spyOn(websocketEventBus, "emit");
|
||||
|
||||
class TestMe {
|
||||
@@ -111,6 +111,6 @@ describe("The RealtimeCreated decorator", () => {
|
||||
});
|
||||
|
||||
emitSpy.mockRestore();
|
||||
done();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
+6
-6
@@ -5,7 +5,7 @@ import { websocketEventBus } from "../../../../../../../src/core/platform/servic
|
||||
import { ResourcePath } from "../../../../../../../src/core/platform/services/realtime/types";
|
||||
|
||||
describe("The RealtimeDeleted decorator", () => {
|
||||
it("should call the original method send back original result but do not emit event if result type is wrong", async done => {
|
||||
it("should call the original method send back original result but do not emit event if result type is wrong", async () => {
|
||||
const emitSpy = jest.spyOn(websocketEventBus, "emit");
|
||||
|
||||
class TestMe {
|
||||
@@ -27,10 +27,10 @@ describe("The RealtimeDeleted decorator", () => {
|
||||
expect(emitSpy).toHaveBeenCalledTimes(0);
|
||||
|
||||
emitSpy.mockRestore();
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should call the original method send back original result and emit event", async done => {
|
||||
it("should call the original method send back original result and emit event", async () => {
|
||||
const emitSpy = jest.spyOn(websocketEventBus, "emit");
|
||||
|
||||
class TestMe {
|
||||
@@ -68,10 +68,10 @@ describe("The RealtimeDeleted decorator", () => {
|
||||
});
|
||||
|
||||
emitSpy.mockRestore();
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should emit event with path computed from function", async done => {
|
||||
it("should emit event with path computed from function", async () => {
|
||||
const emitSpy = jest.spyOn(websocketEventBus, "emit");
|
||||
|
||||
class TestMe {
|
||||
@@ -111,6 +111,6 @@ describe("The RealtimeDeleted decorator", () => {
|
||||
});
|
||||
|
||||
emitSpy.mockRestore();
|
||||
done();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
+6
-6
@@ -5,7 +5,7 @@ import { websocketEventBus } from "../../../../../../../src/core/platform/servic
|
||||
import { ResourcePath } from "../../../../../../../src/core/platform/services/realtime/types";
|
||||
|
||||
describe("The RealtimeUpdated decorator", () => {
|
||||
it("should call the original method send back original result but do not emit event if result type is wrong", async done => {
|
||||
it("should call the original method send back original result but do not emit event if result type is wrong", async () => {
|
||||
const emitSpy = jest.spyOn(websocketEventBus, "emit");
|
||||
|
||||
class TestMe {
|
||||
@@ -27,10 +27,10 @@ describe("The RealtimeUpdated decorator", () => {
|
||||
expect(emitSpy).toHaveBeenCalledTimes(0);
|
||||
|
||||
emitSpy.mockRestore();
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should call the original method send back original result and emit event", async done => {
|
||||
it("should call the original method send back original result and emit event", async () => {
|
||||
const emitSpy = jest.spyOn(websocketEventBus, "emit");
|
||||
|
||||
class TestMe {
|
||||
@@ -69,10 +69,10 @@ describe("The RealtimeUpdated decorator", () => {
|
||||
});
|
||||
|
||||
emitSpy.mockRestore();
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
it("should emit event with path computed from function", async done => {
|
||||
it("should emit event with path computed from function", async () => {
|
||||
const emitSpy = jest.spyOn(websocketEventBus, "emit");
|
||||
|
||||
class TestMe {
|
||||
@@ -113,6 +113,6 @@ describe("The RealtimeUpdated decorator", () => {
|
||||
});
|
||||
|
||||
emitSpy.mockRestore();
|
||||
done();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
+181
@@ -0,0 +1,181 @@
|
||||
import "reflect-metadata";
|
||||
import { describe } from "@jest/globals";
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import { DriveFileDTOBuilder } from "../../../../../../../src/services/documents/web/dto/drive-file-dto-builder";
|
||||
import { ListResult } from "../../../../../../../src/core/platform/framework/api/crud-service";
|
||||
import { DriveFile } from "../../../../../../../src/services/documents/entities/drive-file";
|
||||
import { CompanyExecutionContext } from "../../../../../../../src/services/applications/web/types";
|
||||
import { UserServiceImpl } from "../../../../../../../src/services/user/services/users/service";
|
||||
|
||||
describe("Drive File DTO Builder Test", () => {
|
||||
|
||||
const subj = new DriveFileDTOBuilder();
|
||||
|
||||
|
||||
it("The dto object will contain selected fields with the data ", async () => {
|
||||
//given
|
||||
const fields = ["id", "name"];
|
||||
const file = newFile("file_id", "file_name");
|
||||
|
||||
//when
|
||||
|
||||
let transformedFiles = await subj.build(
|
||||
new ListResult<DriveFile>("drive_files", [file]),
|
||||
context,
|
||||
fields
|
||||
);
|
||||
|
||||
//then
|
||||
expect(transformedFiles).toBeDefined();
|
||||
expect(transformedFiles.getEntities()?.length).toEqual(1);
|
||||
const actual = transformedFiles.getEntities()?.[0];
|
||||
expect(actual.id).toEqual("file_id");
|
||||
expect(actual.name).toEqual("file_name");
|
||||
});
|
||||
|
||||
it("The dto object will contain only selected fields with data", async () => {
|
||||
//given
|
||||
const fields = ["id", "name"];
|
||||
const file = newFile("file_id", "file_name", "file_parent_id");
|
||||
|
||||
//when
|
||||
|
||||
let transformedFiles = await subj.build(
|
||||
new ListResult<DriveFile>("drive_files", [file]),
|
||||
context,
|
||||
fields
|
||||
);
|
||||
|
||||
//then
|
||||
expect(transformedFiles).toBeDefined();
|
||||
expect(transformedFiles.getEntities()?.length).toEqual(1);
|
||||
const actual = transformedFiles.getEntities()?.[0];
|
||||
expect(Object.getOwnPropertyNames(actual).sort()).toEqual(fields.sort());
|
||||
});
|
||||
|
||||
it("When there is no fields set then whole object should be copied", async () => {
|
||||
//given
|
||||
const file = newFile("file_id", "file_name", "file_parent_id");
|
||||
|
||||
//when
|
||||
|
||||
let transformedFiles = await subj.build(
|
||||
new ListResult<DriveFile>("drive_files", [file]),
|
||||
context
|
||||
);
|
||||
|
||||
//then
|
||||
expect(transformedFiles).toBeDefined();
|
||||
expect(transformedFiles.getEntities()?.length).toEqual(1);
|
||||
const actual = transformedFiles.getEntities()?.[0];
|
||||
for (const prop in Object.getOwnPropertyNames(file)) {
|
||||
expect(actual[prop]).toEqual(file[prop]);
|
||||
}
|
||||
});
|
||||
|
||||
it("When field contains unknown property it should be skipped", async () => {
|
||||
//given
|
||||
const file = newFile("file_id", "file_name");
|
||||
let fields = ["id", "name", "unknown_property"];
|
||||
|
||||
//when
|
||||
let transformedFiles = await subj.build(
|
||||
new ListResult<DriveFile>("drive_files", [file]),
|
||||
context,
|
||||
fields
|
||||
);
|
||||
|
||||
//then
|
||||
expect(transformedFiles).toBeDefined();
|
||||
expect(transformedFiles.getEntities()?.length).toEqual(1);
|
||||
const actual = transformedFiles.getEntities()?.[0];
|
||||
expect(Object.getOwnPropertyNames(actual).sort()).toEqual(["id", "name"]);
|
||||
});
|
||||
|
||||
|
||||
it("When 'created_by' field is asked it should be initialized by corresponding user", async () => {
|
||||
//given
|
||||
let file_creator = newUser();
|
||||
const file = newFile("file_id", "file_name", "parent_id", file_creator.id);
|
||||
let fields = ["id", "name", "created_by"];
|
||||
subj.usersService = mock<UserServiceImpl>();
|
||||
subj.usersService.list = jest.fn().mockReturnValue(new ListResult("users", [file_creator]));
|
||||
|
||||
//when
|
||||
let transformedFiles = await subj.build(
|
||||
new ListResult<DriveFile>("drive_files", [file]),
|
||||
context,
|
||||
fields
|
||||
);
|
||||
|
||||
//then
|
||||
expect(transformedFiles).toBeDefined();
|
||||
expect(transformedFiles.getEntities()?.length).toEqual(1);
|
||||
const actual = transformedFiles.getEntities()?.[0];
|
||||
expect(actual.created_by.first_name).toEqual(file_creator.first_name);
|
||||
expect(actual.created_by.last_name).toEqual(file_creator.last_name);
|
||||
expect(actual.created_by.id).toEqual(file_creator.id);
|
||||
});
|
||||
|
||||
it("When 'shared_by' field is asked it should be initialized by corresponding user", async () => {
|
||||
//given
|
||||
let file_shared_by = newUser();
|
||||
const file = newFile("file_id", "file_name", "parent_id", null, file_shared_by.id);
|
||||
let fields = ["id", "name", "shared_by"];
|
||||
subj.usersService = mock<UserServiceImpl>();
|
||||
subj.usersService.list = jest.fn().mockReturnValue(new ListResult("users", [file_shared_by]));
|
||||
|
||||
//when
|
||||
let transformedFiles = await subj.build(
|
||||
new ListResult<DriveFile>("drive_files", [file]),
|
||||
context,
|
||||
fields
|
||||
);
|
||||
|
||||
//then
|
||||
expect(transformedFiles).toBeDefined();
|
||||
expect(transformedFiles.getEntities()?.length).toEqual(1);
|
||||
const actual = transformedFiles.getEntities()?.[0];
|
||||
expect(actual.shared_by.first_name).toEqual(file_shared_by.first_name);
|
||||
expect(actual.shared_by.last_name).toEqual(file_shared_by.last_name);
|
||||
expect(actual.shared_by.id).toEqual(file_shared_by.id);
|
||||
});
|
||||
|
||||
const context = {
|
||||
company: { id: "company_id" },
|
||||
user: {id : "current_user_id"}
|
||||
} as CompanyExecutionContext;
|
||||
|
||||
const newFile = (id, name, parent_id = "parent_id",
|
||||
creator = "file_creator", shared_by_id = "file_shared_by") => {
|
||||
return{
|
||||
name: name,
|
||||
id: id,
|
||||
parent_id: parent_id,
|
||||
last_version_cache: {
|
||||
file_size: 100,
|
||||
mode: "mode_me",
|
||||
},
|
||||
access_info: {
|
||||
entities: [
|
||||
{
|
||||
type: "user",
|
||||
id: context.user.id,
|
||||
level: "read",
|
||||
grantor: shared_by_id,
|
||||
}
|
||||
]
|
||||
},
|
||||
creator: creator,
|
||||
} as DriveFile;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
function newUser() {
|
||||
return {
|
||||
id: "user_id" + Math.random(),
|
||||
first_name: "user_name" + +Math.random(),
|
||||
last_name: "user_name" + +Math.random(),
|
||||
};
|
||||
}
|
||||
+924
-1762
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user