2020-01-08 05:17:54 +08:00
|
|
|
import {SharingDTO} from '../../../../src/common/entities/SharingDTO';
|
|
|
|
import {ObjectManagers} from '../../../../src/backend/model/ObjectManagers';
|
|
|
|
import {UserDTO, UserRoles} from '../../../../src/common/entities/UserDTO';
|
|
|
|
import {Utils} from '../../../../src/common/Utils';
|
|
|
|
|
|
|
|
export class RouteTestingHelper {
|
|
|
|
|
|
|
|
|
|
|
|
static async createSharing(testUser: UserDTO, password: string = null): Promise<SharingDTO> {
|
2021-04-18 21:48:35 +08:00
|
|
|
const sharing = {
|
2020-01-08 05:17:54 +08:00
|
|
|
sharingKey: 'sharing_test_key_' + Date.now(),
|
|
|
|
path: 'test',
|
|
|
|
expires: Date.now() + 1000,
|
|
|
|
timeStamp: Date.now(),
|
|
|
|
includeSubfolders: false,
|
|
|
|
creator: testUser
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SharingDTO;
|
2020-01-08 05:17:54 +08:00
|
|
|
if (password) {
|
|
|
|
sharing.password = password;
|
|
|
|
}
|
|
|
|
await ObjectManagers.getInstance().SharingManager.createSharing(Utils.clone(sharing)); // do not rewrite password
|
|
|
|
return sharing;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static getExpectedSharingUser(sharing: SharingDTO): UserDTO {
|
2021-04-18 21:48:35 +08:00
|
|
|
return {
|
2020-01-08 05:17:54 +08:00
|
|
|
name: 'Guest',
|
|
|
|
role: UserRoles.LimitedGuest,
|
|
|
|
permissions: [sharing.path],
|
|
|
|
usedSharingKey: sharing.sharingKey
|
2021-04-18 21:48:35 +08:00
|
|
|
} as UserDTO;
|
2020-01-08 05:17:54 +08:00
|
|
|
}
|
|
|
|
}
|