fix(backend): Falende testen gerepareerd.
This commit is contained in:
		
							parent
							
								
									3c3a1d89c6
								
							
						
					
					
						commit
						fc675710b4
					
				
					 7 changed files with 34 additions and 14 deletions
				
			
		|  | @ -82,12 +82,19 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public async findAllSubmissionsForStudent(student: Student): Promise<Submission[]> { |     public async findAllSubmissionsForStudent(student: Student): Promise<Submission[]> { | ||||||
|         return this.find( |         const result = await this.find( | ||||||
|             { submitter: student }, |             { submitter: student }, | ||||||
|             { |             { | ||||||
|                 populate: ["onBehalfOf.members"] |                 populate: [ | ||||||
|  |                     "onBehalfOf.members" | ||||||
|  |                 ] | ||||||
|             } |             } | ||||||
|         ); |         ); | ||||||
|  | 
 | ||||||
|  |         // Workaround: For some reason, without this MikroORM generates an UPDATE query with a syntax error in some tests
 | ||||||
|  |         this.em.clear(); | ||||||
|  | 
 | ||||||
|  |         return result; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public async deleteSubmissionByLearningObjectAndSubmissionNumber(loId: LearningObjectIdentifier, submissionNumber: number): Promise<void> { |     public async deleteSubmissionByLearningObjectAndSubmissionNumber(loId: LearningObjectIdentifier, submissionNumber: number): Promise<void> { | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| import { Group } from '../entities/assignments/group.entity.js'; | import { Group } from '../entities/assignments/group.entity.js'; | ||||||
| import {mapToAssignment, mapToAssignmentDTO} from './assignment.js'; | import {mapToAssignment, mapToAssignmentDTO, mapToAssignmentDTOId} from './assignment.js'; | ||||||
| import {mapToStudent, mapToStudentDTO} from './student.js'; | import {mapToStudent, mapToStudentDTO} from './student.js'; | ||||||
| import {GroupDTO} from '@dwengo-1/common/interfaces/group'; | import {GroupDTO} from '@dwengo-1/common/interfaces/group'; | ||||||
| import {getGroupRepository} from "../data/repositories"; | import {getGroupRepository} from "../data/repositories"; | ||||||
|  | @ -13,7 +13,7 @@ export function mapToGroup(groupDto: GroupDTO, clazz: Class): Group { | ||||||
|     return getGroupRepository().create({ |     return getGroupRepository().create({ | ||||||
|         groupNumber: groupDto.groupNumber, |         groupNumber: groupDto.groupNumber, | ||||||
|         assignment: mapToAssignment(assignmentDto, clazz), |         assignment: mapToAssignment(assignmentDto, clazz), | ||||||
|         members: groupDto.members.map(studentDto => mapToStudent(studentDto as StudentDTO)) |         members: groupDto.members!.map(studentDto => mapToStudent(studentDto as StudentDTO)) | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -26,6 +26,16 @@ export function mapToGroupDTO(group: Group): GroupDTO { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export function mapToGroupDTOId(group: Group): GroupDTO { | export function mapToGroupDTOId(group: Group): GroupDTO { | ||||||
|  |     return { | ||||||
|  |         assignment: mapToAssignmentDTOId(group.assignment), | ||||||
|  |         groupNumber: group.groupNumber!, | ||||||
|  |     }; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Map to group DTO where other objects are only referenced by their id. | ||||||
|  |  */ | ||||||
|  | export function mapToShallowGroupDTO(group: Group): GroupDTO { | ||||||
|     return { |     return { | ||||||
|         assignment: group.assignment.id!, |         assignment: group.assignment.id!, | ||||||
|         groupNumber: group.groupNumber!, |         groupNumber: group.groupNumber!, | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ import { Question } from '../entities/questions/question.entity.js'; | ||||||
| import { mapToStudentDTO } from './student.js'; | import { mapToStudentDTO } from './student.js'; | ||||||
| import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | ||||||
| import { LearningObjectIdentifier } from '@dwengo-1/common/interfaces/learning-content'; | import { LearningObjectIdentifier } from '@dwengo-1/common/interfaces/learning-content'; | ||||||
| import {mapToGroupDTO} from "./group"; | import { mapToGroupDTOId } from "./group"; | ||||||
| 
 | 
 | ||||||
| function getLearningObjectIdentifier(question: Question): LearningObjectIdentifier { | function getLearningObjectIdentifier(question: Question): LearningObjectIdentifier { | ||||||
|     return { |     return { | ||||||
|  | @ -22,7 +22,7 @@ export function mapToQuestionDTO(question: Question): QuestionDTO { | ||||||
|         learningObjectIdentifier, |         learningObjectIdentifier, | ||||||
|         sequenceNumber: question.sequenceNumber!, |         sequenceNumber: question.sequenceNumber!, | ||||||
|         author: mapToStudentDTO(question.author), |         author: mapToStudentDTO(question.author), | ||||||
|         inGroup: mapToGroupDTO(question.inGroup), |         inGroup: mapToGroupDTOId(question.inGroup), | ||||||
|         timestamp: question.timestamp.toISOString(), |         timestamp: question.timestamp.toISOString(), | ||||||
|         content: question.content, |         content: question.content, | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|  | @ -6,7 +6,7 @@ import { | ||||||
|     getSubmissionRepository, |     getSubmissionRepository, | ||||||
| } from '../data/repositories.js'; | } from '../data/repositories.js'; | ||||||
| import { Group } from '../entities/assignments/group.entity.js'; | import { Group } from '../entities/assignments/group.entity.js'; | ||||||
| import { mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js'; | import { mapToGroupDTO, mapToShallowGroupDTO } from '../interfaces/group.js'; | ||||||
| import { mapToSubmissionDTO, mapToSubmissionDTOId } from '../interfaces/submission.js'; | import { mapToSubmissionDTO, mapToSubmissionDTOId } from '../interfaces/submission.js'; | ||||||
| import { GroupDTO } from '@dwengo-1/common/interfaces/group'; | import { GroupDTO } from '@dwengo-1/common/interfaces/group'; | ||||||
| import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/submission'; | import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/submission'; | ||||||
|  | @ -38,7 +38,7 @@ export async function getGroup(classId: string, assignmentNumber: number, groupN | ||||||
|         return mapToGroupDTO(group); |         return mapToGroupDTO(group); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return mapToGroupDTOId(group); |     return mapToShallowGroupDTO(group); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function createGroup(groupData: GroupDTO, classid: string, assignmentNumber: number): Promise<Group | null> { | export async function createGroup(groupData: GroupDTO, classid: string, assignmentNumber: number): Promise<Group | null> { | ||||||
|  | @ -103,7 +103,7 @@ export async function getAllGroups(classId: string, assignmentNumber: number, fu | ||||||
|         return groups.map(mapToGroupDTO); |         return groups.map(mapToGroupDTO); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return groups.map(mapToGroupDTOId); |     return groups.map(mapToShallowGroupDTO); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function getGroupSubmissions( | export async function getGroupSubmissions( | ||||||
|  |  | ||||||
|  | @ -7,7 +7,7 @@ import { | ||||||
|     getSubmissionRepository, |     getSubmissionRepository, | ||||||
| } from '../data/repositories.js'; | } from '../data/repositories.js'; | ||||||
| import { mapToClassDTO } from '../interfaces/class.js'; | import { mapToClassDTO } from '../interfaces/class.js'; | ||||||
| import { mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js'; | import { mapToGroupDTO, mapToShallowGroupDTO } from '../interfaces/group.js'; | ||||||
| import { mapToStudent, mapToStudentDTO } from '../interfaces/student.js'; | import { mapToStudent, mapToStudentDTO } from '../interfaces/student.js'; | ||||||
| import { mapToSubmissionDTO, mapToSubmissionDTOId } from '../interfaces/submission.js'; | import { mapToSubmissionDTO, mapToSubmissionDTOId } from '../interfaces/submission.js'; | ||||||
| import { getAllAssignments } from './assignments.js'; | import { getAllAssignments } from './assignments.js'; | ||||||
|  | @ -23,6 +23,7 @@ import { GroupDTO } from '@dwengo-1/common/interfaces/group'; | ||||||
| import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/submission'; | import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/submission'; | ||||||
| import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | ||||||
| import { ClassJoinRequestDTO } from '@dwengo-1/common/interfaces/class-join-request'; | import { ClassJoinRequestDTO } from '@dwengo-1/common/interfaces/class-join-request'; | ||||||
|  | import {Submission} from "../entities/assignments/submission.entity"; | ||||||
| 
 | 
 | ||||||
| export async function getAllStudents(full: boolean): Promise<StudentDTO[] | string[]> { | export async function getAllStudents(full: boolean): Promise<StudentDTO[] | string[]> { | ||||||
|     const studentRepository = getStudentRepository(); |     const studentRepository = getStudentRepository(); | ||||||
|  | @ -100,14 +101,15 @@ export async function getStudentGroups(username: string, full: boolean): Promise | ||||||
|         return groups.map(mapToGroupDTO); |         return groups.map(mapToGroupDTO); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return groups.map(mapToGroupDTOId); |     return groups.map(mapToShallowGroupDTO); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function getStudentSubmissions(username: string, full: boolean): Promise<SubmissionDTO[] | SubmissionDTOId[]> { | export async function getStudentSubmissions(username: string, full: boolean): Promise<SubmissionDTO[] | SubmissionDTOId[]> { | ||||||
|     const student = await fetchStudent(username); |     const student = await fetchStudent(username); | ||||||
| 
 | 
 | ||||||
|     const submissionRepository = getSubmissionRepository(); |     const submissionRepository = getSubmissionRepository(); | ||||||
|     const submissions = await submissionRepository.findAllSubmissionsForStudent(student); | 
 | ||||||
|  |     const submissions: Submission[] = await submissionRepository.findAllSubmissionsForStudent(student); | ||||||
| 
 | 
 | ||||||
|     if (full) { |     if (full) { | ||||||
|         return submissions.map(mapToSubmissionDTO); |         return submissions.map(mapToSubmissionDTO); | ||||||
|  |  | ||||||
|  | @ -147,6 +147,7 @@ describe('Student controllers', () => { | ||||||
| 
 | 
 | ||||||
|         const result = jsonMock.mock.lastCall?.[0]; |         const result = jsonMock.mock.lastCall?.[0]; | ||||||
|         expect(result.submissions).to.have.length.greaterThan(0); |         expect(result.submissions).to.have.length.greaterThan(0); | ||||||
|  | 
 | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     it('Student questions', async () => { |     it('Student questions', async () => { | ||||||
|  |  | ||||||
|  | @ -4,5 +4,5 @@ import { StudentDTO } from './student'; | ||||||
| export interface GroupDTO { | export interface GroupDTO { | ||||||
|     assignment: number | AssignmentDTO; |     assignment: number | AssignmentDTO; | ||||||
|     groupNumber: number; |     groupNumber: number; | ||||||
|     members: string[] | StudentDTO[]; |     members?: string[] | StudentDTO[]; | ||||||
| } | } | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Gerald Schmittinger
						Gerald Schmittinger