1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/test/backend/integration/routers/RouteTestingHelper.ts

34 lines
1.1 KiB
TypeScript
Raw Normal View History

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> {
const sharing = <SharingDTO>{
sharingKey: 'sharing_test_key_' + Date.now(),
path: 'test',
expires: Date.now() + 1000,
timeStamp: Date.now(),
includeSubfolders: false,
creator: testUser
};
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 {
return <UserDTO>{
name: 'Guest',
role: UserRoles.LimitedGuest,
permissions: [sharing.path],
usedSharingKey: sharing.sharingKey
};
}
}