🚧 #46 Shared with me (#67)

* 🚧 #46 Shared with me
This commit is contained in:
Anton Shepilov
2023-06-07 10:48:44 +02:00
committed by GitHub
parent 49ec20d60e
commit f1bf507865
42 changed files with 1122 additions and 867 deletions
Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.
@@ -1,198 +0,0 @@
%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.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.
@@ -1,25 +1,24 @@
import "reflect-metadata";
import { afterAll, beforeAll, describe, expect, it } from "@jest/globals";
import { init, TestPlatform } from "../setup";
import { ResourceUpdateResponse } from "../../../src/utils/types";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import fs from "fs";
import { File } from "../../../src/services/files/entities/file";
import { deserialize } from "class-transformer";
import formAutoContent from "form-auto-content";
import LocalConnectorService from "../../../src/core/platform/services/storage/connectors/local/service";
import TestHelpers from "../common/common_test_helpers";
describe("The Files feature", () => {
const url = "/internal/services/files/v1";
let platform: TestPlatform;
let helpers: TestHelpers;
beforeAll(async () => {
platform = await init({
services: ["webserver", "database", "storage", "files", "previews"],
});
await platform.database.getConnector().init();
helpers = await TestHelpers.getInstance(platform)
});
afterAll(async done => {
@@ -28,37 +27,13 @@ describe("The Files feature", () => {
done();
});
async function uploadFile(file: string) {
const form = formAutoContent({file: fs.createReadStream(file)});
form.headers["authorization"] = `Bearer ${await platform.auth.getJWTToken()}`;
const filesUploadRaw = await platform.app.inject({
method: "POST",
url: `${url}/companies/${platform.workspace.company_id}/files?thumbnail_sync=1`,
...form,
});
const filesUpload: ResourceUpdateResponse<File> = deserialize(
ResourceUpdateResponse,
filesUploadRaw.body,
);
return filesUpload;
}
describe("On user send files", () => {
const files = [
"assets/sample.png",
"assets/sample.gif",
"assets/sample.pdf",
"assets/sample.doc",
"assets/sample.zip",
"assets/sample.mp4",
].map(p => `${__dirname}/${p}`);
const thumbnails = [1, 1, 2, 5, 0, 1];
it("Download file should return 500 if file doesn't exists", async () => {
//given file
const filesUpload = await uploadFile(files[0]);
expect(filesUpload.resource.id).toBeTruthy();
const filesUpload = await helpers.uploadRandomFile();
expect(filesUpload.id).toBeTruthy();
//clean files directory
expect(platform.storage.getConnector()).toBeInstanceOf(LocalConnectorService)
const path = (<LocalConnectorService>platform.storage.getConnector()).configuration.path;
@@ -66,7 +41,7 @@ describe("The Files feature", () => {
//when try to download the file
const fileDownloadResponse = await platform.app.inject({
method: "GET",
url: `${url}/companies/${platform.workspace.company_id}/files/${filesUpload.resource.id}/download`,
url: `${url}/companies/${platform.workspace.company_id}/files/${filesUpload.id}/download`,
});
//then file should be not found with 404 error and "File not found message"
expect(fileDownloadResponse).toBeTruthy();
@@ -76,15 +51,15 @@ describe("The Files feature", () => {
it("Download file should return 200 if file exists", async () => {
//given file
const filesUpload = await uploadFile(files[0]);
expect(filesUpload.resource.id).toBeTruthy();
const filesUpload = await helpers.uploadRandomFile()
expect(filesUpload.id).toBeTruthy();
//clean files directory
expect(platform.storage.getConnector()).toBeInstanceOf(LocalConnectorService)
//when try to download the file
const fileDownloadResponse = await platform.app.inject({
method: "GET",
url: `${url}/companies/${platform.workspace.company_id}/files/${filesUpload.resource.id}/download`,
url: `${url}/companies/${platform.workspace.company_id}/files/${filesUpload.id}/download`,
});
//then file should be not found with 404 error and "File not found message"
expect(fileDownloadResponse).toBeTruthy();
@@ -94,20 +69,20 @@ describe("The Files feature", () => {
it.skip("should save file and generate previews", async done => {
for (const i in files) {
const file = files[i];
for (const i in TestHelpers.ALL_FILES) {
const file = TestHelpers.ALL_FILES[i];
const filesUpload = await uploadFile(file);
const filesUpload = await helpers.uploadFile(file);
expect(filesUpload.resource.id).not.toBeFalsy();
expect(filesUpload.resource.encryption_key).toBeFalsy(); //This must not be disclosed
expect(filesUpload.resource.thumbnails.length).toBe(thumbnails[i]);
expect(filesUpload.id).not.toBeFalsy();
expect(filesUpload.encryption_key).toBeFalsy(); //This must not be disclosed
expect(filesUpload.thumbnails.length).toBe(thumbnails[i]);
for (const thumb of filesUpload.resource.thumbnails) {
for (const thumb of filesUpload.thumbnails) {
const thumbnails = await platform.app.inject({
headers: {"authorization": `Bearer ${await platform.auth.getJWTToken()}`},
method: "GET",
url: `${url}/companies/${platform.workspace.company_id}/files/${filesUpload.resource.id}/thumbnails/${thumb.index}`,
url: `${url}/companies/${platform.workspace.company_id}/files/${filesUpload.id}/thumbnails/${thumb.index}`,
});
expect(thumbnails.statusCode).toBe(200);
}