mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-03-11 21:51:53 +00:00
feat(group): add helper functions for special groups
This is syntactic sugar. Co-Authored-By: Tilman Vatteroth <git@tilmanvatteroth.de> Signed-off-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
f11f3b0931
commit
5cdc0edfb9
2 changed files with 31 additions and 2 deletions
src/groups
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
@ -13,6 +13,7 @@ import { AlreadyInDBError, NotInDBError } from '../errors/errors';
|
|||
import { LoggerModule } from '../logger/logger.module';
|
||||
import { Group } from './group.entity';
|
||||
import { GroupsService } from './groups.service';
|
||||
import { SpecialGroup } from './groups.special';
|
||||
|
||||
describe('GroupsService', () => {
|
||||
let service: GroupsService;
|
||||
|
@ -89,6 +90,17 @@ describe('GroupsService', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('getEveryoneGroup return EVERYONE group', async () => {
|
||||
const spy = jest.spyOn(service, 'getGroupByName').mockImplementation();
|
||||
await service.getEveryoneGroup();
|
||||
expect(spy).toHaveBeenCalledWith(SpecialGroup.EVERYONE);
|
||||
});
|
||||
it('getLoggedInGroup return LOGGED_IN group', async () => {
|
||||
const spy = jest.spyOn(service, 'getGroupByName').mockImplementation();
|
||||
await service.getLoggedInGroup();
|
||||
expect(spy).toHaveBeenCalledWith(SpecialGroup.LOGGED_IN);
|
||||
});
|
||||
|
||||
describe('toGroupDto', () => {
|
||||
it('works', () => {
|
||||
const groupDto = service.toGroupDto(group);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
@ -11,6 +11,7 @@ import { AlreadyInDBError, NotInDBError } from '../errors/errors';
|
|||
import { ConsoleLoggerService } from '../logger/console-logger.service';
|
||||
import { GroupInfoDto } from './group-info.dto';
|
||||
import { Group } from './group.entity';
|
||||
import { SpecialGroup } from './groups.special';
|
||||
|
||||
@Injectable()
|
||||
export class GroupsService {
|
||||
|
@ -66,6 +67,22 @@ export class GroupsService {
|
|||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the group object for the everyone special group.
|
||||
* @return {Group} the EVERYONE group
|
||||
*/
|
||||
getEveryoneGroup(): Promise<Group> {
|
||||
return this.getGroupByName(SpecialGroup.EVERYONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the group object for the logged-in special group.
|
||||
* @return {Group} the LOGGED_IN group
|
||||
*/
|
||||
getLoggedInGroup(): Promise<Group> {
|
||||
return this.getGroupByName(SpecialGroup.LOGGED_IN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build GroupInfoDto from a group.
|
||||
* @param {Group} group - the group to use
|
||||
|
|
Loading…
Reference in a new issue