diff --git a/src/groups/groups.service.spec.ts b/src/groups/groups.service.spec.ts index 334c8a835..da59c6ea5 100644 --- a/src/groups/groups.service.spec.ts +++ b/src/groups/groups.service.spec.ts @@ -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); diff --git a/src/groups/groups.service.ts b/src/groups/groups.service.ts index 4c85564cd..5b15dea9b 100644 --- a/src/groups/groups.service.ts +++ b/src/groups/groups.service.ts @@ -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 { + return this.getGroupByName(SpecialGroup.EVERYONE); + } + + /** + * Get the group object for the logged-in special group. + * @return {Group} the LOGGED_IN group + */ + getLoggedInGroup(): Promise { + return this.getGroupByName(SpecialGroup.LOGGED_IN); + } + /** * Build GroupInfoDto from a group. * @param {Group} group - the group to use