-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* implement board creation in room * add api endpoint for getting room boards * add room context to board context service * add tests --------- Co-authored-by: MartinSchuhmacher <[email protected]>
- Loading branch information
1 parent
14600ef
commit ac0f0dc
Showing
32 changed files
with
1,665 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
apps/server/src/modules/board/controller/api-test/board-context-in-rooms.api.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import { EntityManager } from '@mikro-orm/mongodb'; | ||
import { ServerTestModule } from '@modules/server'; | ||
import { INestApplication } from '@nestjs/common'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { TestApiClient, cleanupCollections, groupEntityFactory, roleFactory, userFactory } from '@shared/testing'; | ||
import { Permission, RoleName } from '@shared/domain/interface'; | ||
import { accountFactory } from '@src/modules/account/testing'; | ||
import { GroupEntityTypes } from '@src/modules/group/entity'; | ||
import { roomMemberEntityFactory } from '@src/modules/room-member/testing'; | ||
import { roomEntityFactory } from '@src/modules/room/testing'; | ||
import { columnBoardEntityFactory } from '../../testing'; | ||
import { BoardExternalReferenceType } from '../../domain'; | ||
|
||
const baseRouteName = '/boards'; | ||
|
||
describe('board get context in room (api)', () => { | ||
let app: INestApplication; | ||
let em: EntityManager; | ||
let testApiClient: TestApiClient; | ||
|
||
beforeAll(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
imports: [ServerTestModule], | ||
}).compile(); | ||
|
||
app = module.createNestApplication(); | ||
await app.init(); | ||
em = module.get(EntityManager); | ||
testApiClient = new TestApiClient(app, baseRouteName); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.close(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await cleanupCollections(em); | ||
}); | ||
|
||
const setup = async () => { | ||
const userWithEditRole = userFactory.buildWithId(); | ||
const accountWithEditRole = accountFactory.withUser(userWithEditRole).build(); | ||
|
||
const userWithViewRole = userFactory.buildWithId(); | ||
const accountWithViewRole = accountFactory.withUser(userWithViewRole).build(); | ||
|
||
const noAccessUser = userFactory.buildWithId(); | ||
const noAccessAccount = accountFactory.withUser(noAccessUser).build(); | ||
|
||
const roleRoomEdit = roleFactory.buildWithId({ | ||
name: RoleName.ROOM_EDITOR, | ||
permissions: [Permission.ROOM_EDIT], | ||
}); | ||
const roleRoomView = roleFactory.buildWithId({ | ||
name: RoleName.ROOM_VIEWER, | ||
permissions: [Permission.ROOM_VIEW], | ||
}); | ||
|
||
const userGroup = groupEntityFactory.buildWithId({ | ||
type: GroupEntityTypes.ROOM, | ||
users: [ | ||
{ user: userWithEditRole, role: roleRoomEdit }, | ||
{ user: userWithViewRole, role: roleRoomView }, | ||
], | ||
}); | ||
|
||
const room = roomEntityFactory.buildWithId(); | ||
|
||
const roomMember = roomMemberEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id }); | ||
|
||
await em.persistAndFlush([ | ||
accountWithEditRole, | ||
accountWithViewRole, | ||
noAccessAccount, | ||
userWithEditRole, | ||
userWithViewRole, | ||
noAccessUser, | ||
roleRoomEdit, | ||
roleRoomView, | ||
userGroup, | ||
room, | ||
roomMember, | ||
]); | ||
|
||
const columnBoardNode = columnBoardEntityFactory.build({ | ||
isVisible: false, | ||
context: { id: room.id, type: BoardExternalReferenceType.Room }, | ||
}); | ||
|
||
await em.persistAndFlush([columnBoardNode]); | ||
em.clear(); | ||
|
||
return { accountWithEditRole, accountWithViewRole, noAccessAccount, columnBoardNode }; | ||
}; | ||
|
||
describe('with user who has edit role in room', () => { | ||
it('should return status 200', async () => { | ||
const { accountWithEditRole, columnBoardNode } = await setup(); | ||
|
||
const loggedInClient = await testApiClient.login(accountWithEditRole); | ||
|
||
const response = await loggedInClient.get(`${columnBoardNode.id}/context`); | ||
|
||
expect(response.status).toEqual(200); | ||
}); | ||
|
||
it('should return the context', async () => { | ||
const { accountWithEditRole, columnBoardNode } = await setup(); | ||
|
||
const loggedInClient = await testApiClient.login(accountWithEditRole); | ||
|
||
const response = await loggedInClient.get(`${columnBoardNode.id}/context`); | ||
|
||
expect(response.body).toEqual({ id: columnBoardNode.context?.id, type: columnBoardNode.context?.type }); | ||
}); | ||
}); | ||
|
||
describe('with user who has only view role in room', () => { | ||
it('should return status 403', async () => { | ||
const { accountWithViewRole, columnBoardNode } = await setup(); | ||
|
||
const loggedInClient = await testApiClient.login(accountWithViewRole); | ||
|
||
const response = await loggedInClient.get(`${columnBoardNode.id}/context`); | ||
|
||
expect(response.status).toEqual(403); | ||
}); | ||
}); | ||
|
||
describe('with user who is not part of the room', () => { | ||
it('should return status 403', async () => { | ||
const { noAccessAccount, columnBoardNode } = await setup(); | ||
|
||
const loggedInClient = await testApiClient.login(noAccessAccount); | ||
|
||
const response = await loggedInClient.get(`${columnBoardNode.id}/context`); | ||
|
||
expect(response.status).toEqual(403); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.