-
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 delete-unused-file
- Loading branch information
Showing
36 changed files
with
1,143 additions
and
60 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
140 changes: 140 additions & 0 deletions
140
apps/server/src/modules/group/controller/api-test/group.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,140 @@ | ||
import { EntityManager } from '@mikro-orm/mongodb'; | ||
import { HttpStatus, INestApplication } from '@nestjs/common'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { Role, RoleName, SchoolEntity, SortOrder, SystemEntity, User } from '@shared/domain'; | ||
import { | ||
groupEntityFactory, | ||
roleFactory, | ||
schoolFactory, | ||
systemFactory, | ||
TestApiClient, | ||
UserAndAccountTestFactory, | ||
userFactory, | ||
} from '@shared/testing'; | ||
import { ClassEntity } from '@src/modules/class/entity'; | ||
import { classEntityFactory } from '@src/modules/class/entity/testing/factory/class.entity.factory'; | ||
import { ServerTestModule } from '@src/modules/server'; | ||
import { GroupEntity, GroupEntityTypes } from '../../entity'; | ||
import { ClassInfoSearchListResponse, ClassSortBy } from '../dto'; | ||
|
||
const baseRouteName = '/groups'; | ||
|
||
describe('Group (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('findClassesForSchool', () => { | ||
describe('when an admin requests a list of classes', () => { | ||
const setup = async () => { | ||
const school: SchoolEntity = schoolFactory.buildWithId(); | ||
const { adminAccount, adminUser } = UserAndAccountTestFactory.buildAdmin({ school }); | ||
|
||
const teacherRole: Role = roleFactory.buildWithId({ name: RoleName.TEACHER }); | ||
const teacherUser: User = userFactory.buildWithId({ school, roles: [teacherRole] }); | ||
const system: SystemEntity = systemFactory.buildWithId(); | ||
const clazz: ClassEntity = classEntityFactory.buildWithId({ | ||
name: 'Group A', | ||
schoolId: school._id, | ||
teacherIds: [teacherUser._id], | ||
source: undefined, | ||
}); | ||
const group: GroupEntity = groupEntityFactory.buildWithId({ | ||
name: 'Group B', | ||
type: GroupEntityTypes.CLASS, | ||
externalSource: { | ||
externalId: 'externalId', | ||
system, | ||
}, | ||
organization: school, | ||
users: [ | ||
{ | ||
user: adminUser, | ||
role: teacherRole, | ||
}, | ||
], | ||
}); | ||
|
||
await em.persistAndFlush([school, adminAccount, adminUser, teacherRole, teacherUser, system, clazz, group]); | ||
em.clear(); | ||
|
||
const adminClient = await testApiClient.login(adminAccount); | ||
|
||
return { | ||
adminClient, | ||
group, | ||
clazz, | ||
system, | ||
adminUser, | ||
teacherUser, | ||
}; | ||
}; | ||
|
||
it('should return the classes of his school', async () => { | ||
const { adminClient, group, clazz, system, adminUser, teacherUser } = await setup(); | ||
|
||
const response = await adminClient.get(`/class`).query({ | ||
skip: 0, | ||
limit: 2, | ||
sortBy: ClassSortBy.NAME, | ||
sortOrder: SortOrder.desc, | ||
}); | ||
|
||
expect(response.body).toEqual<ClassInfoSearchListResponse>({ | ||
total: 2, | ||
data: [ | ||
{ | ||
name: group.name, | ||
externalSourceName: system.displayName, | ||
teachers: [adminUser.lastName], | ||
}, | ||
{ | ||
name: clazz.gradeLevel ? `${clazz.gradeLevel}${clazz.name}` : clazz.name, | ||
teachers: [teacherUser.lastName], | ||
}, | ||
], | ||
skip: 0, | ||
limit: 2, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when an invalid user requests a list of classes', () => { | ||
const setup = async () => { | ||
const { studentAccount, studentUser } = UserAndAccountTestFactory.buildStudent(); | ||
|
||
await em.persistAndFlush([studentAccount, studentUser]); | ||
em.clear(); | ||
|
||
const studentClient = await testApiClient.login(studentAccount); | ||
|
||
return { | ||
studentClient, | ||
}; | ||
}; | ||
|
||
it('should return forbidden', async () => { | ||
const { studentClient } = await setup(); | ||
|
||
const response = await studentClient.get(`/class`); | ||
|
||
expect(response.status).toEqual(HttpStatus.FORBIDDEN); | ||
}); | ||
}); | ||
}); | ||
}); |
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,2 @@ | ||
export * from './request'; | ||
export * from './response'; |
15 changes: 15 additions & 0 deletions
15
apps/server/src/modules/group/controller/dto/request/class-sort-params.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,15 @@ | ||
import { ApiPropertyOptional } from '@nestjs/swagger'; | ||
import { SortingParams } from '@shared/controller'; | ||
import { IsEnum, IsOptional } from 'class-validator'; | ||
|
||
export enum ClassSortBy { | ||
NAME = 'name', | ||
EXTERNAL_SOURCE_NAME = 'externalSourceName', | ||
} | ||
|
||
export class ClassSortParams extends SortingParams<ClassSortBy> { | ||
@IsOptional() | ||
@IsEnum(ClassSortBy) | ||
@ApiPropertyOptional({ enum: ClassSortBy }) | ||
sortBy?: ClassSortBy; | ||
} |
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 @@ | ||
export * from './class-sort-params'; |
13 changes: 13 additions & 0 deletions
13
apps/server/src/modules/group/controller/dto/response/class-info-search-list.response.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,13 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { PaginationResponse } from '@shared/controller'; | ||
import { ClassInfoResponse } from './class-info.response'; | ||
|
||
export class ClassInfoSearchListResponse extends PaginationResponse<ClassInfoResponse[]> { | ||
constructor(data: ClassInfoResponse[], total: number, skip?: number, limit?: number) { | ||
super(total, skip, limit); | ||
this.data = data; | ||
} | ||
|
||
@ApiProperty({ type: [ClassInfoResponse] }) | ||
data: ClassInfoResponse[]; | ||
} |
18 changes: 18 additions & 0 deletions
18
apps/server/src/modules/group/controller/dto/response/class-info.response.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,18 @@ | ||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; | ||
|
||
export class ClassInfoResponse { | ||
@ApiProperty() | ||
name: string; | ||
|
||
@ApiPropertyOptional() | ||
externalSourceName?: string; | ||
|
||
@ApiProperty({ type: [String] }) | ||
teachers: string[]; | ||
|
||
constructor(props: ClassInfoResponse) { | ||
this.name = props.name; | ||
this.externalSourceName = props.externalSourceName; | ||
this.teachers = props.teachers; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
apps/server/src/modules/group/controller/dto/response/index.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,2 @@ | ||
export * from './class-info.response'; | ||
export * from './class-info-search-list.response'; |
Oops, something went wrong.