Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 34 KiB |
Binary file not shown.
@@ -0,0 +1,198 @@
|
||||
%PDF-1.3
|
||||
%âãÏÓ
|
||||
|
||||
1 0 obj
|
||||
<<
|
||||
/Type /Catalog
|
||||
/Outlines 2 0 R
|
||||
/Pages 3 0 R
|
||||
>>
|
||||
endobj
|
||||
|
||||
2 0 obj
|
||||
<<
|
||||
/Type /Outlines
|
||||
/Count 0
|
||||
>>
|
||||
endobj
|
||||
|
||||
3 0 obj
|
||||
<<
|
||||
/Type /Pages
|
||||
/Count 2
|
||||
/Kids [ 4 0 R 6 0 R ]
|
||||
>>
|
||||
endobj
|
||||
|
||||
4 0 obj
|
||||
<<
|
||||
/Type /Page
|
||||
/Parent 3 0 R
|
||||
/Resources <<
|
||||
/Font <<
|
||||
/F1 9 0 R
|
||||
>>
|
||||
/ProcSet 8 0 R
|
||||
>>
|
||||
/MediaBox [0 0 612.0000 792.0000]
|
||||
/Contents 5 0 R
|
||||
>>
|
||||
endobj
|
||||
|
||||
5 0 obj
|
||||
<< /Length 1074 >>
|
||||
stream
|
||||
2 J
|
||||
BT
|
||||
0 0 0 rg
|
||||
/F1 0027 Tf
|
||||
57.3750 722.2800 Td
|
||||
( A Simple PDF File ) Tj
|
||||
ET
|
||||
BT
|
||||
/F1 0010 Tf
|
||||
69.2500 688.6080 Td
|
||||
( This is a small demonstration .pdf file - ) Tj
|
||||
ET
|
||||
BT
|
||||
/F1 0010 Tf
|
||||
69.2500 664.7040 Td
|
||||
( just for use in the Virtual Mechanics tutorials. More text. And more ) Tj
|
||||
ET
|
||||
BT
|
||||
/F1 0010 Tf
|
||||
69.2500 652.7520 Td
|
||||
( text. And more text. And more text. And more text. ) Tj
|
||||
ET
|
||||
BT
|
||||
/F1 0010 Tf
|
||||
69.2500 628.8480 Td
|
||||
( And more text. And more text. And more text. And more text. And more ) Tj
|
||||
ET
|
||||
BT
|
||||
/F1 0010 Tf
|
||||
69.2500 616.8960 Td
|
||||
( text. And more text. Boring, zzzzz. And more text. And more text. And ) Tj
|
||||
ET
|
||||
BT
|
||||
/F1 0010 Tf
|
||||
69.2500 604.9440 Td
|
||||
( more text. And more text. And more text. And more text. And more text. ) Tj
|
||||
ET
|
||||
BT
|
||||
/F1 0010 Tf
|
||||
69.2500 592.9920 Td
|
||||
( And more text. And more text. ) Tj
|
||||
ET
|
||||
BT
|
||||
/F1 0010 Tf
|
||||
69.2500 569.0880 Td
|
||||
( And more text. And more text. And more text. And more text. And more ) Tj
|
||||
ET
|
||||
BT
|
||||
/F1 0010 Tf
|
||||
69.2500 557.1360 Td
|
||||
( text. And more text. And more text. Even more. Continued on page 2 ...) Tj
|
||||
ET
|
||||
endstream
|
||||
endobj
|
||||
|
||||
6 0 obj
|
||||
<<
|
||||
/Type /Page
|
||||
/Parent 3 0 R
|
||||
/Resources <<
|
||||
/Font <<
|
||||
/F1 9 0 R
|
||||
>>
|
||||
/ProcSet 8 0 R
|
||||
>>
|
||||
/MediaBox [0 0 612.0000 792.0000]
|
||||
/Contents 7 0 R
|
||||
>>
|
||||
endobj
|
||||
|
||||
7 0 obj
|
||||
<< /Length 676 >>
|
||||
stream
|
||||
2 J
|
||||
BT
|
||||
0 0 0 rg
|
||||
/F1 0027 Tf
|
||||
57.3750 722.2800 Td
|
||||
( Simple PDF File 2 ) Tj
|
||||
ET
|
||||
BT
|
||||
/F1 0010 Tf
|
||||
69.2500 688.6080 Td
|
||||
( ...continued from page 1. Yet more text. And more text. And more text. ) Tj
|
||||
ET
|
||||
BT
|
||||
/F1 0010 Tf
|
||||
69.2500 676.6560 Td
|
||||
( And more text. And more text. And more text. And more text. And more ) Tj
|
||||
ET
|
||||
BT
|
||||
/F1 0010 Tf
|
||||
69.2500 664.7040 Td
|
||||
( text. Oh, how boring typing this stuff. But not as boring as watching ) Tj
|
||||
ET
|
||||
BT
|
||||
/F1 0010 Tf
|
||||
69.2500 652.7520 Td
|
||||
( paint dry. And more text. And more text. And more text. And more text. ) Tj
|
||||
ET
|
||||
BT
|
||||
/F1 0010 Tf
|
||||
69.2500 640.8000 Td
|
||||
( Boring. More, a little more text. The end, and just as well. ) Tj
|
||||
ET
|
||||
endstream
|
||||
endobj
|
||||
|
||||
8 0 obj
|
||||
[/PDF /Text]
|
||||
endobj
|
||||
|
||||
9 0 obj
|
||||
<<
|
||||
/Type /Font
|
||||
/Subtype /Type1
|
||||
/Name /F1
|
||||
/BaseFont /Helvetica
|
||||
/Encoding /WinAnsiEncoding
|
||||
>>
|
||||
endobj
|
||||
|
||||
10 0 obj
|
||||
<<
|
||||
/Creator (Rave \(http://www.nevrona.com/rave\))
|
||||
/Producer (Nevrona Designs)
|
||||
/CreationDate (D:20060301072826)
|
||||
>>
|
||||
endobj
|
||||
|
||||
xref
|
||||
0 11
|
||||
0000000000 65535 f
|
||||
0000000019 00000 n
|
||||
0000000093 00000 n
|
||||
0000000147 00000 n
|
||||
0000000222 00000 n
|
||||
0000000390 00000 n
|
||||
0000001522 00000 n
|
||||
0000001690 00000 n
|
||||
0000002423 00000 n
|
||||
0000002456 00000 n
|
||||
0000002574 00000 n
|
||||
|
||||
trailer
|
||||
<<
|
||||
/Size 11
|
||||
/Root 1 0 R
|
||||
/Info 10 0 R
|
||||
>>
|
||||
|
||||
startxref
|
||||
2714
|
||||
%%EOF
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
Binary file not shown.
@@ -0,0 +1,192 @@
|
||||
// @ts-ignore
|
||||
import fs from "fs";
|
||||
import {ResourceUpdateResponse, Workspace} from "../../../src/utils/types";
|
||||
import {File} from "../../../src/services/files/entities/file";
|
||||
import {deserialize} from "class-transformer";
|
||||
import formAutoContent from "form-auto-content";
|
||||
import {TestPlatform, User} from "../setup";
|
||||
import {v1 as uuidv1} from "uuid";
|
||||
import {TestDbService} from "../utils.prepare.db";
|
||||
import {DriveFile} from "../../../src/services/documents/entities/drive-file";
|
||||
import {FileVersion} from "../../../src/services/documents/entities/file-version";
|
||||
import {SearchResultMockClass} from "./entities/mock_entities";
|
||||
import {logger} from "../../../src/core/platform/framework";
|
||||
|
||||
export default class TestHelpers {
|
||||
|
||||
private static readonly DOC_URL = "/internal/services/documents/v1";
|
||||
|
||||
static readonly ALL_FILES = [
|
||||
"sample.png",
|
||||
"sample.gif",
|
||||
"sample.pdf",
|
||||
"sample.doc",
|
||||
"sample.zip",
|
||||
"sample.mp4",
|
||||
]
|
||||
|
||||
platform: TestPlatform;
|
||||
dbService: TestDbService;
|
||||
user: User;
|
||||
workspace: Workspace;
|
||||
jwt: string;
|
||||
|
||||
private constructor(
|
||||
platform: TestPlatform,
|
||||
) {
|
||||
this.platform = platform
|
||||
}
|
||||
|
||||
private async init(newUser: boolean) {
|
||||
this.dbService = await TestDbService.getInstance(this.platform, true);
|
||||
if (newUser) {
|
||||
this.workspace = this.platform.workspace;
|
||||
const workspacePK = {id: this.workspace.workspace_id, company_id: this.workspace.company_id};
|
||||
this.user = await this.dbService.createUser([workspacePK], {}, uuidv1());
|
||||
} else {
|
||||
this.user = this.platform.currentUser;
|
||||
this.workspace = this.platform.workspace;
|
||||
}
|
||||
this.jwt = this.getJWTTokenForUser(this.user.id);
|
||||
}
|
||||
|
||||
public static async getInstance(platform: TestPlatform, newUser = false): Promise<TestHelpers> {
|
||||
const helpers = new TestHelpers(platform);
|
||||
await helpers.init(newUser)
|
||||
return helpers;
|
||||
}
|
||||
|
||||
async uploadFiles() {
|
||||
return Promise.all(TestHelpers.ALL_FILES.map(f => this.uploadFile(f)));
|
||||
}
|
||||
|
||||
async uploadRandomFile() {
|
||||
return await this.uploadFile(TestHelpers.ALL_FILES[Math.floor((Math.random()*TestHelpers.ALL_FILES.length))])
|
||||
}
|
||||
|
||||
async uploadFile(filename: string) {
|
||||
logger.info(`Upload ${filename} for the user: ${this.user.id}`);
|
||||
const fullPath = `${__dirname}/assets/${filename}`
|
||||
const url = "/internal/services/files/v1";
|
||||
const form = formAutoContent({file: fs.createReadStream(fullPath)});
|
||||
form.headers["authorization"] = `Bearer ${this.jwt}`;
|
||||
|
||||
const filesUploadRaw = await this.platform.app.inject({
|
||||
method: "POST",
|
||||
url: `${url}/companies/${this.platform.workspace.company_id}/files?thumbnail_sync=1`,
|
||||
...form,
|
||||
});
|
||||
|
||||
const filesUpload: ResourceUpdateResponse<File> = deserialize(
|
||||
ResourceUpdateResponse,
|
||||
filesUploadRaw.body,
|
||||
);
|
||||
return filesUpload.resource;
|
||||
}
|
||||
|
||||
private getJWTTokenForUser(userId: string): string {
|
||||
const payload = {
|
||||
sub: userId,
|
||||
role: "",
|
||||
}
|
||||
return this.platform.authService.sign(payload);
|
||||
}
|
||||
|
||||
async uploadFileAndCreateDocument(
|
||||
filename: string
|
||||
) {
|
||||
return this.uploadFile(filename).then(f => this.createDocumentFromFile(f));
|
||||
};
|
||||
|
||||
async uploadRandomFileAndCreateDocument() {
|
||||
return this.uploadRandomFile().then(f => this.createDocumentFromFile(f));
|
||||
};
|
||||
|
||||
async uploadAllFilesAndCreateDocuments() {
|
||||
return await Promise.all(TestHelpers.ALL_FILES.map(f => this.uploadFileAndCreateDocument(f)))
|
||||
};
|
||||
|
||||
async uploadAllFilesOneByOne() {
|
||||
const files: Array<DriveFile> = [];
|
||||
for (const idx in TestHelpers.ALL_FILES) {
|
||||
const f = await this.uploadFile(TestHelpers.ALL_FILES[idx]);
|
||||
const doc = await this.createDocumentFromFile(f);
|
||||
files.push(doc);
|
||||
}
|
||||
return files;
|
||||
};
|
||||
|
||||
async createDocument(
|
||||
platform: TestPlatform,
|
||||
item: Partial<DriveFile>,
|
||||
version: Partial<FileVersion>
|
||||
) {
|
||||
|
||||
return await platform.app.inject({
|
||||
method: "POST",
|
||||
url: `${TestHelpers.DOC_URL}/companies/${platform.workspace.company_id}/item`,
|
||||
headers: {
|
||||
authorization: `Bearer ${this.jwt}`,
|
||||
},
|
||||
payload: {
|
||||
item,
|
||||
version,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
async createDocumentFromFile(
|
||||
file: File
|
||||
) {
|
||||
const item = {
|
||||
name: file.metadata.name,
|
||||
parent_id: "root",
|
||||
company_id: file.company_id,
|
||||
};
|
||||
|
||||
const version = {
|
||||
file_metadata: {
|
||||
name: file.metadata.name,
|
||||
size: file.upload_data?.size,
|
||||
thumbnails: [],
|
||||
external_id: file.id
|
||||
}
|
||||
}
|
||||
|
||||
const response = await this.createDocument(this.platform, item, version);
|
||||
return deserialize<DriveFile>(DriveFile, response.body);
|
||||
};
|
||||
|
||||
async updateDocument(
|
||||
id: string | "root" | "trash",
|
||||
item: Partial<DriveFile>
|
||||
) {
|
||||
return await this.platform.app.inject({
|
||||
method: "POST",
|
||||
url: `${TestHelpers.DOC_URL}/companies/${this.platform.workspace.company_id}/item/${id}`,
|
||||
headers: {
|
||||
authorization: `Bearer ${this.jwt}`,
|
||||
},
|
||||
payload: item,
|
||||
});
|
||||
};
|
||||
|
||||
async searchDocument (
|
||||
payload: Record<string, any>
|
||||
){
|
||||
const response = await this.platform.app.inject({
|
||||
method: "POST",
|
||||
url: `${TestHelpers.DOC_URL}/companies/${this.platform.workspace.company_id}/search`,
|
||||
headers: {
|
||||
authorization: `Bearer ${this.jwt}`,
|
||||
},
|
||||
payload,
|
||||
});
|
||||
|
||||
return deserialize<SearchResultMockClass>(
|
||||
SearchResultMockClass,
|
||||
response.body)
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import {DriveFileAccessLevel, publicAccessLevel} from "../../../../src/services/documents/types";
|
||||
|
||||
export type MockAccessInformation = {
|
||||
public?: {
|
||||
token: string;
|
||||
password: string;
|
||||
expiration: number;
|
||||
level: publicAccessLevel;
|
||||
};
|
||||
entities: MockAuthEntity[];
|
||||
};
|
||||
|
||||
export type MockAuthEntity = {
|
||||
type: "user" | "channel" | "company" | "folder";
|
||||
id: string | "parent";
|
||||
level: publicAccessLevel | DriveFileAccessLevel;
|
||||
};
|
||||
|
||||
export class DriveFileMockClass {
|
||||
id: string;
|
||||
name: string;
|
||||
size: number;
|
||||
added: string;
|
||||
parent_id: string;
|
||||
extension: string;
|
||||
description: string;
|
||||
tags: string[];
|
||||
last_modified: string;
|
||||
access_info: MockAccessInformation;
|
||||
creator: string;
|
||||
}
|
||||
|
||||
export class DriveItemDetailsMockClass {
|
||||
path: string[];
|
||||
item: DriveFileMockClass;
|
||||
children: DriveFileMockClass[];
|
||||
versions: Record<string, unknown>[];
|
||||
}
|
||||
|
||||
export class SearchResultMockClass {
|
||||
entities: DriveFileMockClass[];
|
||||
}
|
||||
Reference in New Issue
Block a user