🐛 backend: adding editing session key (#525)
This commit is contained in:
committed by
ericlinagora
parent
3de9829bf0
commit
16dbf8077b
@@ -28,6 +28,7 @@ export class DriveFileMockClass {
|
||||
tags: string[];
|
||||
last_modified: number;
|
||||
access_info: MockAccessInformation;
|
||||
editing_session_key: string;
|
||||
creator: string;
|
||||
is_directory: boolean;
|
||||
scope: "personal" | "shared";
|
||||
|
||||
@@ -396,6 +396,29 @@ export default class UserApi {
|
||||
});
|
||||
};
|
||||
|
||||
async beginEditingDocument(
|
||||
driveFileId: string,
|
||||
editorApplicationId: string,
|
||||
): Promise<Response> {
|
||||
return await this.api.post(
|
||||
`${UserApi.DOC_URL}/companies/${this.platform.workspace.company_id}/item/${driveFileId}/editing_session`,
|
||||
{ editorApplicationId },
|
||||
{
|
||||
authorization: `Bearer ${this.jwt}`
|
||||
});
|
||||
}
|
||||
|
||||
async beginEditingDocumentExpectOk(
|
||||
driveFileId: string,
|
||||
editorApplicationId: string,
|
||||
): Promise<string> {
|
||||
const result = await this.beginEditingDocument(driveFileId, editorApplicationId);
|
||||
expect(result.statusCode).toBe(200);
|
||||
const {editingSessionKey} = result.json();
|
||||
expect(editingSessionKey).toBeTruthy();
|
||||
return editingSessionKey;
|
||||
}
|
||||
|
||||
async searchDocument(
|
||||
payload: Record<string, any>
|
||||
) {
|
||||
@@ -459,6 +482,16 @@ export default class UserApi {
|
||||
return doc;
|
||||
};
|
||||
|
||||
async getDocumentByEditingKey(editing_session_key: string) {
|
||||
return await this.platform.app.inject({
|
||||
method: "GET",
|
||||
url: `${UserApi.DOC_URL}/companies/${this.platform.workspace.company_id}/item/editing_session/${encodeURIComponent(editing_session_key)}`,
|
||||
headers: {
|
||||
authorization: `Bearer ${this.jwt}`
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
async sharedWithMeDocuments(
|
||||
payload: Record<string, any>
|
||||
) {
|
||||
|
||||
@@ -75,4 +75,43 @@ describe("the Drive's documents' editing session kind-of-lock", () => {
|
||||
expect(driveFileRepository?.atomicCompareAndSet(temporaryDocument, "editing_session_key", "124", null)).
|
||||
rejects.toThrow("no row matched PK");
|
||||
});
|
||||
|
||||
it('rejects invalid editorApplicationId', async () => {
|
||||
let result = await currentUser.beginEditingDocument(temporaryDocument.id, '');
|
||||
expect(result.statusCode).toBe(400);
|
||||
result = await currentUser.beginEditingDocument(temporaryDocument.id, 'e2e-testing');
|
||||
expect(result.statusCode).toBe(400);
|
||||
result = await currentUser.beginEditingDocument(temporaryDocument.id, 'e2e_testing_but_this_one_is_likely_too_long_the_max_is_128_with_added_guid_and_ts_added_after_and_counting_towards_128');
|
||||
expect(result.statusCode).toBe(400);
|
||||
});
|
||||
|
||||
it('can begin an editing session on a document only once', async () => {
|
||||
const editingSessionKey = await currentUser.beginEditingDocumentExpectOk(temporaryDocument.id, 'e2e_testing');
|
||||
const secondKey = await currentUser.beginEditingDocumentExpectOk(temporaryDocument.id, 'e2e_testing');
|
||||
expect(editingSessionKey).toBe(secondKey);
|
||||
const document = await currentUser.getDocumentOKCheck(temporaryDocument.id)
|
||||
expect(document.item.editing_session_key).toBe(editingSessionKey);
|
||||
});
|
||||
|
||||
it('cannot begin an editing session on a document without write permissions', async () => {
|
||||
const secondUser = await UserApi.getInstance(platform!, true);
|
||||
const editingResult = await secondUser.beginEditingDocument(temporaryDocument.id, 'e2e_testing');
|
||||
expect(editingResult.statusCode).toBe(401);
|
||||
});
|
||||
|
||||
it('can retreive the document from the editing session key', async () => {
|
||||
const editingSessionKey = await currentUser.beginEditingDocumentExpectOk(temporaryDocument.id, 'e2e_testing');
|
||||
let foundDocumentResult = await currentUser.getDocumentByEditingKey(editingSessionKey + "-made-wrong");
|
||||
expect(foundDocumentResult.statusCode).toBe(404);
|
||||
foundDocumentResult = await currentUser.getDocumentByEditingKey("");
|
||||
expect(foundDocumentResult.statusCode).toBe(400);
|
||||
foundDocumentResult = await currentUser.getDocumentByEditingKey(editingSessionKey);
|
||||
expect(foundDocumentResult.statusCode).toBe(200);
|
||||
expect(temporaryDocument.id).toBe(foundDocumentResult.json().id);
|
||||
});
|
||||
|
||||
it('can end an editing session on a document only once with the right key', async () => {
|
||||
const editingSessionKey = await currentUser.beginEditingDocumentExpectOk(temporaryDocument.id, 'e2e_testing');
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user