hedgedoc/frontend/src/test-utils/note-ownership.ts
Philip Molares c2f41118b6 feat: check permissions in realtime code and frontend
Signed-off-by: Philip Molares <philip.molares@udo.edu>
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2023-04-06 22:54:50 +02:00

30 lines
846 B
TypeScript

/*
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import * as useApplicationStateModule from '../hooks/common/use-application-state'
import type { ApplicationState } from '../redux/application-state'
jest.mock('../hooks/common/use-application-state')
export const mockNoteOwnership = (
ownUsername: string,
noteOwner: string,
additionalState?: Partial<ApplicationState>
) => {
jest.spyOn(useApplicationStateModule, 'useApplicationState').mockImplementation((fn) => {
return fn({
...additionalState,
noteDetails: {
...additionalState?.noteDetails,
permissions: {
owner: noteOwner
}
},
user: {
...additionalState?.user,
username: ownUsername
}
} as ApplicationState)
})
}