🔀 Merge branch 'postgres-support-fix' into 525-515-548-523-onlyoffice-rework

This commit is contained in:
Eric Doughty-Papassideris
2024-09-14 22:56:31 +02:00
19 changed files with 450 additions and 168 deletions
@@ -37,10 +37,15 @@ export class DriveFileMockClass {
}
export class DriveItemDetailsMockClass {
path: string[];
item: DriveFileMockClass;
children: DriveFileMockClass[];
versions: Record<string, unknown>[];
path: string[];
item: DriveFileMockClass;
children: DriveFileMockClass[];
versions: Record<string, unknown>[];
nextPage?: {
page_token: string;
limitStr: string;
reversed: boolean;
};
}
export class SearchResultMockClass {
@@ -36,27 +36,27 @@ describe("The Documents Browser Window and API", () => {
const myDriveId = "user_" + currentUser.user.id;
await currentUser.uploadAllFilesOneByOne(myDriveId);
let page = 1;
const limit = 2;
let page_token = "1";
const limitStr = "2";
let docs = await currentUser.browseDocuments(myDriveId, {
paginate: { page, limit },
paginate: { page_token, limitStr },
});
expect(docs).toBeDefined();
expect(docs.children).toHaveLength(limit);
expect(docs.children).toHaveLength(parseInt(limitStr));
page = 2;
page_token = "2";
docs = await currentUser.browseDocuments(myDriveId, {
paginate: { page, limit },
paginate: { page_token, limitStr },
});
expect(docs).toBeDefined();
expect(docs.children).toHaveLength(limit);
expect(docs.children).toHaveLength(parseInt(limitStr));
page = 3;
page_token = "3";
docs = await currentUser.browseDocuments(myDriveId, {
paginate: { page, limit },
paginate: { page_token, limitStr },
});
expect(docs).toBeDefined();
expect(docs.children.length).toBeLessThanOrEqual(limit);
expect(docs.children.length).toBeLessThanOrEqual(parseInt(limitStr));
});
it("Should sort documents by name in ascending order", async () => {
@@ -152,5 +152,158 @@ describe("The Documents Browser Window and API", () => {
const isSorted = docs.children.every((item, i, arr) => !i || arr[i - 1].size >= item.size);
expect(isSorted).toBe(true);
});
it("Should paginate shared with me ", async () => {
const sharedWIthMeFolder = "shared_with_me";
const oneUser = await UserApi.getInstance(platform, true, { companyRole: "admin" });
const anotherUser = await UserApi.getInstance(platform, true, { companyRole: "admin" });
let files = await oneUser.uploadAllFilesOneByOne();
for (const file of files) {
await oneUser.shareWithPermissions(file, anotherUser.user.id, "read");
}
// wait for files to be indexed
await new Promise(r => setTimeout(r, 5000));
let page_token: any = "1";
const limitStr = "2";
let docs = await anotherUser.browseDocuments(sharedWIthMeFolder, {
paginate: { page_token, limitStr },
});
expect(docs).toBeDefined();
expect(docs.children).toHaveLength(parseInt(limitStr));
page_token = docs.nextPage?.page_token || "2";
docs = await anotherUser.browseDocuments(sharedWIthMeFolder, {
paginate: { page_token, limitStr },
});
expect(docs).toBeDefined();
expect(docs.children).toHaveLength(parseInt(limitStr));
page_token = docs.nextPage?.page_token || "3";
docs = await anotherUser.browseDocuments(sharedWIthMeFolder, {
paginate: { page_token, limitStr },
});
expect(docs).toBeDefined();
expect(docs.children.length).toBeLessThanOrEqual(parseInt(limitStr));
});
it("Should sort shared with me by name in ascending order", async () => {
const sharedWIthMeFolder = "shared_with_me";
const oneUser = await UserApi.getInstance(platform, true, { companyRole: "admin" });
const anotherUser = await UserApi.getInstance(platform, true, { companyRole: "admin" });
let files = await oneUser.uploadAllFilesOneByOne();
for (const file of files) {
await oneUser.shareWithPermissions(file, anotherUser.user.id, "read");
}
const sortBy = "name";
const sortOrder = "asc";
const docs = await anotherUser.browseDocuments(sharedWIthMeFolder, {
sort: { by: sortBy, order: sortOrder },
});
expect(docs).toBeDefined();
const isSorted = docs.children.every((item, i, arr) => !i || arr[i - 1].name <= item.name);
expect(isSorted).toBe(true);
});
it("Should sort shared with me by name in descending order", async () => {
const sharedWIthMeFolder = "shared_with_me";
const oneUser = await UserApi.getInstance(platform, true, { companyRole: "admin" });
const anotherUser = await UserApi.getInstance(platform, true, { companyRole: "admin" });
let files = await oneUser.uploadAllFilesOneByOne();
for (const file of files) {
await oneUser.shareWithPermissions(file, anotherUser.user.id, "read");
}
const sortBy = "name";
const sortOrder = "desc";
const docs = await anotherUser.browseDocuments(sharedWIthMeFolder, {
sort: { by: sortBy, order: sortOrder },
});
expect(docs).toBeDefined();
const isSorted = docs.children.every((item, i, arr) => !i || arr[i - 1].name >= item.name);
expect(isSorted).toBe(true);
});
it("Should sort shared with me by size in ascending order", async () => {
const sharedWIthMeFolder = "shared_with_me";
const oneUser = await UserApi.getInstance(platform, true, { companyRole: "admin" });
const anotherUser = await UserApi.getInstance(platform, true, { companyRole: "admin" });
let files = await oneUser.uploadAllFilesOneByOne();
for (const file of files) {
await oneUser.shareWithPermissions(file, anotherUser.user.id, "read");
}
const sortBy = "size";
const sortOrder = "asc";
const docs = await anotherUser.browseDocuments(sharedWIthMeFolder, {
sort: { by: sortBy, order: sortOrder },
});
expect(docs).toBeDefined();
const isSorted = docs.children.every((item, i, arr) => !i || arr[i - 1].size <= item.size);
expect(isSorted).toBe(true);
});
it("Should sort shared with me by size in descending order", async () => {
const sharedWIthMeFolder = "shared_with_me";
const oneUser = await UserApi.getInstance(platform, true, { companyRole: "admin" });
const anotherUser = await UserApi.getInstance(platform, true, { companyRole: "admin" });
let files = await oneUser.uploadAllFilesOneByOne();
for (const file of files) {
await oneUser.shareWithPermissions(file, anotherUser.user.id, "read");
}
const sortBy = "size";
const sortOrder = "desc";
const docs = await anotherUser.browseDocuments(sharedWIthMeFolder, {
sort: { by: sortBy, order: sortOrder },
});
expect(docs).toBeDefined();
const isSorted = docs.children.every((item, i, arr) => !i || arr[i - 1].size >= item.size);
expect(isSorted).toBe(true);
});
it("Should sort shared with me by date in ascending order", async () => {
const sharedWIthMeFolder = "shared_with_me";
const oneUser = await UserApi.getInstance(platform, true, { companyRole: "admin" });
const anotherUser = await UserApi.getInstance(platform, true, { companyRole: "admin" });
let files = await oneUser.uploadAllFilesOneByOne();
for (const file of files) {
await oneUser.shareWithPermissions(file, anotherUser.user.id, "read");
}
const sortBy = "date";
const sortOrder = "asc";
const docs = await anotherUser.browseDocuments(sharedWIthMeFolder, {
sort: { by: sortBy, order: sortOrder },
});
expect(docs).toBeDefined();
const isSorted = docs.children.every(
(item, i, arr) => !i || new Date(arr[i - 1].added) <= new Date(item.added),
);
expect(isSorted).toBe(true);
});
it("Should sort shared with me by date in descending order", async () => {
const sharedWIthMeFolder = "shared_with_me";
const oneUser = await UserApi.getInstance(platform, true, { companyRole: "admin" });
const anotherUser = await UserApi.getInstance(platform, true, { companyRole: "admin" });
let files = await oneUser.uploadAllFilesOneByOne();
for (const file of files) {
await oneUser.shareWithPermissions(file, anotherUser.user.id, "read");
}
const sortBy = "date";
const sortOrder = "desc";
const docs = await anotherUser.browseDocuments(sharedWIthMeFolder, {
sort: { by: sortBy, order: sortOrder },
});
expect(docs).toBeDefined();
const isSorted = docs.children.every(
(item, i, arr) => !i || new Date(arr[i - 1].added) >= new Date(item.added),
);
expect(isSorted).toBe;
});
});
});
@@ -9,50 +9,46 @@ import WorkspaceUser, { getInstance } from "../../../../../../../src/services/wo
describe('EntityManager', () => {
const subj: EntityManager<TestDbEntity> = new EntityManager<TestDbEntity>({ } as Connector);
let connector = { upsert: () => void 0};
const subj: EntityManager<TestDbEntity> = new EntityManager<TestDbEntity>(connector as unknown as Connector);
let upsert;
beforeEach(async () => {
upsert = jest.spyOn((subj as any).connector, "upsert");
});
afterEach(() => {
jest.clearAllMocks();
subj.reset();
});
test ("persist should store entity to insert if all fields for pk is empty", () => {
//when
subj.persist(new TestDbEntity());
let entity = new TestDbEntity();
subj.persist(entity);
//then
expect((subj as any).toInsert.length).toEqual(1);
expect((subj as any).toUpdate.length).toEqual(0);
expect((subj as any).toRemove.length).toEqual(0);
expect((subj as any).toInsert[0].id).toBeDefined();
expect((subj as any).toInsert[0].company_id).toBeDefined();
expect(upsert).toBeCalledTimes(1);
expect(upsert).toBeCalledWith([entity], {"action": "INSERT"})
});
test ("persist should store entity to insert if id is set", () => {
//when
subj.persist(new TestDbEntity({id: randomUUID()}));
let entity = new TestDbEntity({id: randomUUID()});
subj.persist(entity);
//then
expect((subj as any).toInsert.length).toEqual(1);
expect((subj as any).toUpdate.length).toEqual(0);
expect((subj as any).toRemove.length).toEqual(0);
expect((subj as any).toInsert[0].id).toBeDefined();
expect((subj as any).toInsert[0].company_id).toBeDefined();
expect(upsert).toBeCalledTimes(1);
expect(upsert).toBeCalledWith([entity], {"action": "INSERT"})
});
test ("persist should store entity to insert if company_id is set", () => {
//when
subj.persist(new TestDbEntity({company_id: randomUUID()}));
let entity = new TestDbEntity({company_id: randomUUID()});
subj.persist(entity);
//then
expect((subj as any).toInsert.length).toEqual(1);
expect((subj as any).toUpdate.length).toEqual(0);
expect((subj as any).toRemove.length).toEqual(0);
expect((subj as any).toInsert[0].id).toBeDefined();
expect((subj as any).toInsert[0].company_id).toBeDefined();
expect(upsert).toBeCalledTimes(1);
expect(upsert).toBeCalledWith([entity], {"action": "INSERT"})
});
test ("persist should store entity to update if all pk fields are set", () => {
@@ -61,10 +57,8 @@ describe('EntityManager', () => {
subj.persist(entity);
//then
expect((subj as any).toUpdate.length).toEqual(1);
expect((subj as any).toInsert.length).toEqual(0);
expect((subj as any).toRemove.length).toEqual(0);
expect((subj as any).toUpdate[0]).toEqual(entity)
expect(upsert).toBeCalledTimes(1);
expect(upsert).toBeCalledWith([entity], {"action": "UPDATE"})
});
test ("persist should store entity to update if all pk fields are set and column name is different from field name", () => {
@@ -73,10 +67,8 @@ describe('EntityManager', () => {
subj.persist(entity);
//then
expect((subj as any).toUpdate.length).toEqual(1);
expect((subj as any).toInsert.length).toEqual(0);
expect((subj as any).toRemove.length).toEqual(0);
expect((subj as any).toUpdate[0]).toEqual(entity)
expect(upsert).toBeCalledTimes(1)
expect(upsert).toBeCalledWith([entity], {"action": "UPDATE"})
});
test ("persist should store entity to insert if not all pk fields are set and column name is different from field name", () => {
@@ -85,11 +77,7 @@ describe('EntityManager', () => {
subj.persist(entity);
//then
expect((subj as any).toUpdate.length).toEqual(0);
expect((subj as any).toInsert.length).toEqual(1);
expect((subj as any).toRemove.length).toEqual(0);
expect((subj as any).toInsert[0]).toEqual(entity);
expect(entity.userId).toBeDefined();
expect(upsert).toBeCalledWith([entity], {"action": "INSERT"})
});
});