-
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.
Merge branch 'main' into BC-5714-store-upload-state
- Loading branch information
Showing
177 changed files
with
4,273 additions
and
1,863 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
133 changes: 133 additions & 0 deletions
133
apps/server/src/modules/board/controller/api-test/drawing-item-check-permission.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,133 @@ | ||
import { EntityManager } from '@mikro-orm/mongodb'; | ||
import { ServerTestModule } from '@modules/server'; | ||
import { INestApplication } from '@nestjs/common'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { BoardExternalReferenceType } from '@shared/domain/domainobject'; | ||
import { | ||
TestApiClient, | ||
UserAndAccountTestFactory, | ||
cardNodeFactory, | ||
cleanupCollections, | ||
columnBoardNodeFactory, | ||
columnNodeFactory, | ||
courseFactory, | ||
} from '@shared/testing'; | ||
import { drawingElementNodeFactory } from '@shared/testing/factory/boardnode/drawing-element-node.factory'; | ||
|
||
const baseRouteName = '/elements'; | ||
describe('drawing permission check (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(); | ||
}); | ||
|
||
describe('when user is a valid teacher who is part of course', () => { | ||
const setup = async () => { | ||
await cleanupCollections(em); | ||
|
||
const { teacherAccount, teacherUser } = UserAndAccountTestFactory.buildTeacher(); | ||
const course = courseFactory.build({ teachers: [teacherUser] }); | ||
await em.persistAndFlush([teacherAccount, teacherUser, course]); | ||
|
||
const columnBoardNode = columnBoardNodeFactory.buildWithId({ | ||
context: { id: course.id, type: BoardExternalReferenceType.Course }, | ||
}); | ||
|
||
const columnNode = columnNodeFactory.buildWithId({ parent: columnBoardNode }); | ||
|
||
const cardNode = cardNodeFactory.buildWithId({ parent: columnNode }); | ||
|
||
const drawingItemNode = drawingElementNodeFactory.buildWithId({ parent: cardNode }); | ||
|
||
await em.persistAndFlush([columnBoardNode, columnNode, cardNode, drawingItemNode]); | ||
em.clear(); | ||
|
||
const loggedInClient = await testApiClient.login(teacherAccount); | ||
|
||
return { loggedInClient, teacherUser, columnBoardNode, columnNode, cardNode, drawingItemNode }; | ||
}; | ||
|
||
it('should return status 200', async () => { | ||
const { loggedInClient, drawingItemNode } = await setup(); | ||
|
||
const response = await loggedInClient.get(`${drawingItemNode.id}/permission`); | ||
|
||
expect(response.status).toEqual(200); | ||
}); | ||
}); | ||
|
||
describe('when only teacher is part of course', () => { | ||
const setup = async () => { | ||
await cleanupCollections(em); | ||
|
||
const { teacherAccount, teacherUser } = UserAndAccountTestFactory.buildTeacher(); | ||
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent(); | ||
|
||
const course = courseFactory.build({ students: [teacherUser] }); | ||
await em.persistAndFlush([teacherAccount, teacherUser, course, studentAccount, studentUser]); | ||
|
||
const columnBoardNode = columnBoardNodeFactory.buildWithId({ | ||
context: { id: course.id, type: BoardExternalReferenceType.Course }, | ||
}); | ||
|
||
const columnNode = columnNodeFactory.buildWithId({ parent: columnBoardNode }); | ||
|
||
const cardNode = cardNodeFactory.buildWithId({ parent: columnNode }); | ||
|
||
const drawingItemNode = drawingElementNodeFactory.buildWithId({ parent: cardNode }); | ||
|
||
await em.persistAndFlush([columnBoardNode, columnNode, cardNode, drawingItemNode]); | ||
em.clear(); | ||
|
||
const loggedInClient = await testApiClient.login(studentAccount); | ||
|
||
return { loggedInClient, studentUser, columnBoardNode, columnNode, cardNode, drawingItemNode }; | ||
}; | ||
|
||
it('should return status 403 for student not assigned to course', async () => { | ||
const { loggedInClient, drawingItemNode } = await setup(); | ||
|
||
const response = await loggedInClient.get(`${drawingItemNode.id}/permission`); | ||
|
||
expect(response.status).toEqual(403); | ||
}); | ||
}); | ||
|
||
describe('when asking for non-existing resource', () => { | ||
const setup = async () => { | ||
await cleanupCollections(em); | ||
|
||
const { teacherAccount, teacherUser } = UserAndAccountTestFactory.buildTeacher(); | ||
await em.persistAndFlush([teacherAccount, teacherUser]); | ||
|
||
em.clear(); | ||
|
||
const loggedInClient = await testApiClient.login(teacherAccount); | ||
|
||
return { loggedInClient }; | ||
}; | ||
|
||
it('should return status 404 for wrong id', async () => { | ||
const { loggedInClient } = await setup(); | ||
const wrongRandomId = '655b048616056135293d1e63'; | ||
|
||
const response = await loggedInClient.get(`${wrongRandomId}/permission`); | ||
|
||
expect(response.status).toEqual(404); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.