test; classjoinrequests
This commit is contained in:
		
							parent
							
								
									44051e6343
								
							
						
					
					
						commit
						cc1a281d52
					
				
					 1 changed files with 18 additions and 13 deletions
				
			
		|  | @ -2,43 +2,48 @@ import { beforeAll, describe, expect, it } from 'vitest'; | |||
| import { setupTestApp } from '../../setup-tests'; | ||||
| import { ClassJoinRequestRepository } from '../../../src/data/classes/class-join-request-repository'; | ||||
| import { getClassJoinRequestRepository, getClassRepository, getStudentRepository } from '../../../src/data/repositories'; | ||||
| import { StudentRepository } from '../../../src/data/users/student-repository'; | ||||
| import { ClassRepository } from '../../../src/data/classes/class-repository'; | ||||
| import { getPinkFloyd, getSmashingPumpkins } from '../../test_assets/users/students.testdata'; | ||||
| import { getClass02, getClass03 } from '../../test_assets/classes/classes.testdata'; | ||||
| import { getClassJoinRequest01, getClassJoinRequest02, getClassJoinRequest03 } from '../../test_assets/classes/class-join-requests.testdata'; | ||||
| 
 | ||||
| describe('ClassJoinRequestRepository', () => { | ||||
|     let classJoinRequestRepository: ClassJoinRequestRepository; | ||||
|     let studentRepository: StudentRepository; | ||||
|     let cassRepository: ClassRepository; | ||||
| 
 | ||||
|     beforeAll(async () => { | ||||
|         await setupTestApp(); | ||||
|         classJoinRequestRepository = getClassJoinRequestRepository(); | ||||
|         studentRepository = getStudentRepository(); | ||||
|         cassRepository = getClassRepository(); | ||||
|     }); | ||||
| 
 | ||||
|     it('should list all requests from student to join classes', async () => { | ||||
|         const student = await studentRepository.findByUsername('PinkFloyd'); | ||||
|         const requests = await classJoinRequestRepository.findAllRequestsBy(student!); | ||||
|         const studentUsed = getPinkFloyd(); | ||||
|         const jr1 = getClassJoinRequest01(); | ||||
|         const jr2 = getClassJoinRequest03(); | ||||
|         const requests = await classJoinRequestRepository.findAllRequestsBy(studentUsed); | ||||
| 
 | ||||
|         expect(requests).toBeTruthy(); | ||||
|         expect(requests).toHaveLength(2); | ||||
|         expect(requests[0].class.classId!).toBeOneOf([jr1.class.classId!, jr2.class.classId!]); | ||||
|         expect(requests[1].class.classId!).toBeOneOf([jr1.class.classId!, jr2.class.classId!]); | ||||
|     }); | ||||
| 
 | ||||
|     it('should list all requests to a single class', async () => { | ||||
|         const class_ = await cassRepository.findById('34d484a1-295f-4e9f-bfdc-3e7a23d86a89'); | ||||
|         const class_ = getClass02(); | ||||
|         const jr1 = getClassJoinRequest01(); | ||||
|         const jr2 = getClassJoinRequest02(); | ||||
|         const requests = await classJoinRequestRepository.findAllOpenRequestsTo(class_!); | ||||
| 
 | ||||
|         expect(requests).toBeTruthy(); | ||||
|         expect(requests).toHaveLength(2); | ||||
|         expect(requests[0].class.classId).toBeOneOf([jr1.class.classId, jr2.class.classId]); | ||||
|         expect(requests[1].class.classId).toBeOneOf([jr1.class.classId, jr2.class.classId]); | ||||
|     }); | ||||
| 
 | ||||
|     it('should not find a removed request', async () => { | ||||
|         const student = await studentRepository.findByUsername('SmashingPumpkins'); | ||||
|         const class_ = await cassRepository.findById('80dcc3e0-1811-4091-9361-42c0eee91cfa'); | ||||
|         await classJoinRequestRepository.deleteBy(student!, class_!); | ||||
|         const studentUsed = getSmashingPumpkins(); | ||||
|         const class_ = getClass03(); | ||||
|         await classJoinRequestRepository.deleteBy(studentUsed!, class_!); | ||||
| 
 | ||||
|         const request = await classJoinRequestRepository.findAllRequestsBy(student!); | ||||
|         const request = await classJoinRequestRepository.findAllRequestsBy(studentUsed!); | ||||
| 
 | ||||
|         expect(request).toHaveLength(0); | ||||
|     }); | ||||
|  |  | |||
		Reference in a new issue
	
	 laurejablonski
						laurejablonski